organisation
This commit is contained in:
parent
6e02917e17
commit
245e895256
32
Case.java
Normal file
32
Case.java
Normal file
@ -0,0 +1,32 @@
|
||||
/*public class Case {
|
||||
// Réalisation du damier et ajout d'éléments graphiques
|
||||
for (int currentLine=0; currentLine<lignes; currentLine++){
|
||||
for(int currentCase = 0; currentCase < colonnes; currentCase++){
|
||||
if (currentLine%2==0){
|
||||
if (currentCase%2==0){
|
||||
JPanel dark = new JPanel();
|
||||
dark.setSize(caseSize);
|
||||
dark.setBackground(gray2);
|
||||
grille.add(dark);
|
||||
} else {
|
||||
JPanel light = new JPanel();
|
||||
light.setSize(caseSize);
|
||||
light.setBackground(gray1);
|
||||
grille.add(light);
|
||||
}
|
||||
} else {
|
||||
if (currentCase%2==0){
|
||||
JPanel light = new JPanel();
|
||||
light.setSize(caseSize);
|
||||
light.setBackground(gray1);
|
||||
grille.add(light);
|
||||
} else {
|
||||
JPanel dark = new JPanel();
|
||||
dark.setSize(caseSize);
|
||||
dark.setBackground(gray2);
|
||||
grille.add(dark);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
12
Etoile.java
12
Etoile.java
@ -1,13 +1,17 @@
|
||||
import javax.swing.JComponent;
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
// Création d'un Jcomponent Etoile, qui sert pour le marquage des mines
|
||||
public class Etoile extends JComponent {
|
||||
private Image etoileImage;
|
||||
public Etoile() {
|
||||
super();
|
||||
this.etoileImage = Toolkit.getDefaultToolkit().getImage("etoile.png");
|
||||
}
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
Graphics etoile = pinceau.create();
|
||||
int[] x={0,35,50,65,100,70,90,50,20,35};
|
||||
int[] y={40,40,0,40,40,60,100,80,100,80};
|
||||
etoile.setColor(Color.MAGENTA);
|
||||
etoile.fillPolygon(x,y,10);
|
||||
etoile.drawImage(this.etoileImage,5,10,90,80,this);
|
||||
}
|
||||
}
|
@ -3,65 +3,22 @@ import java.awt.*;
|
||||
|
||||
// Cette classe à pour but d'afficher un menu et de réagir aux directives de l'utilisateur (lancer le jeu, le quitter...)
|
||||
public class FrameJeu{
|
||||
public FrameJeu(int lignes, int colonnes) {
|
||||
public FrameJeu(JPanel grille, int mines) {
|
||||
|
||||
// On récupère les dimensions de l'écran pour adapter la taille par défaut de notre fenêtre
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int frameWidth = screenSize.width * 2/3;
|
||||
int frameHeight = screenSize.height * 2/3;
|
||||
|
||||
// On crée ensuite notre fenêtre avec des valeurs par défaut
|
||||
JFrame fenetre = new JFrame("Démineur - En Jeu");
|
||||
fenetre.setSize(frameWidth,frameHeight);
|
||||
fenetre.setSize( screenSize.width * 2/3,screenSize.height * 2/3);
|
||||
fenetre.setLocation(screenSize.width * 1/6, screenSize.height * 1/6);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
/*Banniere banniere = new Banniere(mines);
|
||||
fenetre.add(banniere, BorderLayout.NORTH)*/
|
||||
fenetre.add(grille, BorderLayout.SOUTH);
|
||||
|
||||
// On créer La grille de jeu
|
||||
|
||||
// Découpage de la fenêtre en fonction des paramètres pour la mise en place du damier
|
||||
Dimension damierSize = fenetre.getSize();
|
||||
Dimension caseSize = new Dimension(frameWidth/colonnes,frameWidth/colonnes);
|
||||
GridLayout damier = new GridLayout(lignes,colonnes);
|
||||
fenetre.setLayout(damier);
|
||||
|
||||
// Création des couleurs
|
||||
Color gray1 = new Color(80,80,80);
|
||||
Color gray2 = new Color(70,70,70);
|
||||
|
||||
// Réalisation du damier et ajout d'éléments graphiques
|
||||
for (int currentLine=0; currentLine<lignes; currentLine++){
|
||||
for(int currentCase = 0; currentCase < colonnes; currentCase++){
|
||||
if (currentLine%2==0){
|
||||
if (currentCase%2==0){
|
||||
JPanel dark = new JPanel();
|
||||
dark.setSize(caseSize);
|
||||
dark.setBackground(gray2);
|
||||
fenetre.add(dark);
|
||||
} else {
|
||||
JPanel light = new JPanel();
|
||||
light.setSize(caseSize);
|
||||
light.setBackground(gray1);
|
||||
fenetre.add(light);
|
||||
}
|
||||
} else {
|
||||
if (currentCase%2==0){
|
||||
JPanel light = new JPanel();
|
||||
light.setSize(caseSize);
|
||||
light.setBackground(gray1);
|
||||
fenetre.add(light);
|
||||
} else {
|
||||
JPanel dark = new JPanel();
|
||||
dark.setSize(caseSize);
|
||||
dark.setBackground(gray2);
|
||||
fenetre.add(dark);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fenetre.pack();
|
||||
fenetre.setLocation(damierSize.width * 1/6,(screenSize.height/2)- frameHeight/2);
|
||||
fenetre.setVisible(true);
|
||||
System.out.println(" Jeu " + damierSize.width * 1/6 +" "+ ((screenSize.height/2)- frameHeight/2) + " "+caseSize.width +" "+ caseSize.height );
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ public class FrameMenu{
|
||||
new Fond(fenetre);
|
||||
|
||||
|
||||
|
||||
// A faire : choix de la taille de la grille, bouton jouer, charger et quitter, déscription/règles du jeu
|
||||
|
||||
fenetre.setVisible(true);
|
||||
|
61
Grille.java
Normal file
61
Grille.java
Normal file
@ -0,0 +1,61 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Grille extends JComponent {
|
||||
private Dimension grilleSize=new Dimension(0,0);
|
||||
private JPanel grille= new JPanel();
|
||||
|
||||
// On créer La grille de jeu
|
||||
public Grille(int lignes, int colonnes, int mines){
|
||||
|
||||
// Découpage de l'espace en fonction des paramètres pour la mise en place de la grille
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
this.grilleSize = new Dimension(screenSize.width*2/3, screenSize.height*5/9);
|
||||
Dimension caseSize = new Dimension(this.grilleSize.width/colonnes,this.grilleSize.width/colonnes);
|
||||
GridLayout damier = new GridLayout(lignes,colonnes);
|
||||
this.grille.setLayout(damier);
|
||||
this.grille.setSize(grilleSize);
|
||||
|
||||
// Création des couleurs
|
||||
Color gray1 = new Color(80,80,80);
|
||||
Color gray2 = new Color(70,70,70);
|
||||
|
||||
// Réalisation du damier et ajout d'éléments graphiques
|
||||
for (int currentLine=0; currentLine<lignes; currentLine++){
|
||||
for(int currentCase = 0; currentCase < colonnes; currentCase++){
|
||||
if (currentLine%2==0){
|
||||
if (currentCase%2==0){
|
||||
JPanel dark = new JPanel();
|
||||
dark.setSize(caseSize);
|
||||
dark.setBackground(gray2);
|
||||
this.grille.add(dark);
|
||||
} else {
|
||||
JPanel light = new JPanel();
|
||||
light.setSize(caseSize);
|
||||
light.setBackground(gray1);
|
||||
this.grille.add(light);
|
||||
}
|
||||
} else {
|
||||
if (currentCase%2==0){
|
||||
JPanel light = new JPanel();
|
||||
light.setSize(caseSize);
|
||||
light.setBackground(gray1);
|
||||
this.grille.add(light);
|
||||
} else {
|
||||
JPanel dark = new JPanel();
|
||||
dark.setSize(caseSize);
|
||||
dark.setBackground(gray2);
|
||||
this.grille.add(dark);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getGrilleSize() {
|
||||
return grilleSize;
|
||||
}
|
||||
public JPanel getGrille() {
|
||||
return grille;
|
||||
}
|
||||
}
|
17
Test.java
17
Test.java
@ -1,19 +1,6 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
// On récupère les dimensions de l'écran pour adapter la taille de notre fenêtre
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int frameWidth = screenSize.width * 2/3;
|
||||
int frameHeight = screenSize.height * 2/3;
|
||||
int frameLocation[]={screenSize.width * 1/6, screenSize.height * 1/6};
|
||||
|
||||
// On crée ensuite notre fenêtre
|
||||
JFrame fenetre = new JFrame("Démineur - Menu");
|
||||
fenetre.setSize(frameWidth,frameHeight);
|
||||
fenetre.setLocation(frameLocation[0],frameLocation[1]);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.setVisible(true);
|
||||
Grille grille=new Grille(10,15,15);
|
||||
new FrameJeu(grille.getGrille(), 15);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user