choix et jouer fonctionnels
This commit is contained in:
parent
30286851a1
commit
1b19ba171b
@ -1,4 +1,5 @@
|
||||
import javax.swing.*;
|
||||
|
||||
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...)
|
||||
@ -6,6 +7,9 @@ public class FrameMenu{
|
||||
private int lignes;
|
||||
private int colonnes;
|
||||
private int mines;
|
||||
private JSlider sliderLignes;
|
||||
private JSlider sliderColonnes;
|
||||
private JSlider sliderMines;
|
||||
public FrameMenu() {
|
||||
|
||||
// On récupère les dimensions de l'écran pour adapter la taille de notre fenêtre
|
||||
@ -22,36 +26,50 @@ public class FrameMenu{
|
||||
|
||||
|
||||
// On créer les zones de textes de saisie
|
||||
JSlider sliderLignes = new JSlider(4,30);
|
||||
JSlider sliderColonnes = new JSlider(4,30);
|
||||
JSlider sliderMines = new JSlider(16,900);
|
||||
this.sliderLignes = new JSlider(4,30);
|
||||
this.sliderColonnes = new JSlider(4,30);
|
||||
this.sliderMines = new JSlider(0,900, 16);
|
||||
|
||||
miseEnPage.gridx = 0;
|
||||
miseEnPage.gridy = 0;
|
||||
miseEnPage.weightx =0;
|
||||
miseEnPage.weighty = 0.3;
|
||||
miseEnPage.fill = GridBagConstraints.BOTH;
|
||||
fenetre.add(sliderLignes);
|
||||
|
||||
miseEnPage.gridx = 0;
|
||||
miseEnPage.gridy = 1;
|
||||
miseEnPage.weightx =0;
|
||||
miseEnPage.weighty = 0.3;
|
||||
miseEnPage.fill = GridBagConstraints.BOTH;
|
||||
fenetre.add(sliderColonnes);
|
||||
|
||||
miseEnPage.gridx = 0;
|
||||
miseEnPage.gridy = 2;
|
||||
miseEnPage.weightx =0;
|
||||
miseEnPage.weighty = 0.3;
|
||||
miseEnPage.fill = GridBagConstraints.BOTH;
|
||||
fenetre.add(sliderMines);
|
||||
sliderLignes.addChangeListener(new SettingsListener(0,this));
|
||||
sliderColonnes.addChangeListener(new SettingsListener(1,this));
|
||||
sliderMines.addChangeListener(new SettingsListener(2,this));
|
||||
|
||||
this.lignes=sliderLignes.getValue();
|
||||
this.colonnes=sliderColonnes.getValue();
|
||||
this.mines=sliderMines.getValue();
|
||||
System.out.println("Lignes : "+this.lignes+" Colonnes : "+this.colonnes+" Mines : "+this.mines);
|
||||
// A faire : choix de la taille de la grille, bouton jouer, charger et quitter
|
||||
|
||||
fenetre.add(sliderLignes);
|
||||
fenetre.add(sliderColonnes);
|
||||
fenetre.add(sliderMines);
|
||||
|
||||
JButton newGame = new JButton("New Game");
|
||||
newGame.addActionListener(new NewGameListener(this));
|
||||
|
||||
fenetre.add(newGame);
|
||||
|
||||
// A faire : bouton jouer, charger et quitter
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
|
||||
// Méthode pour récupérer les valeurs des paramètres
|
||||
public void setSettings(int settingToSet, int settingValue){
|
||||
if (settingToSet==0){
|
||||
this.lignes=settingValue;
|
||||
} else if (settingToSet==1){
|
||||
this.colonnes=settingValue;
|
||||
} else if (settingToSet==2){
|
||||
this.mines=settingValue;
|
||||
}
|
||||
this.sliderMines.setMaximum(this.colonnes*this.lignes);
|
||||
System.out.println("Lignes : "+this.lignes+" Colonnes : "+this.colonnes+" Mines : "+this.mines);
|
||||
}
|
||||
|
||||
// Methode pour connaître les paramètres de la partie
|
||||
public int[] getSettings(){
|
||||
int[] settings = new int[3];
|
||||
settings[0]=this.lignes;
|
||||
settings[1]=this.colonnes;
|
||||
settings[2]=this.mines;
|
||||
return settings;
|
||||
}
|
||||
}
|
11
NewGameListener.java
Normal file
11
NewGameListener.java
Normal file
@ -0,0 +1,11 @@
|
||||
import java.awt.event.*;
|
||||
public class NewGameListener implements ActionListener{
|
||||
private FrameMenu menu;
|
||||
public NewGameListener(FrameMenu menu){
|
||||
this.menu=menu;
|
||||
}
|
||||
public void actionPerformed(ActionEvent event){
|
||||
int[] settings =this.menu.getSettings();
|
||||
new FrameJeu(settings[0], settings[1], settings[2]);
|
||||
}
|
||||
}
|
20
SettingsListener.java
Normal file
20
SettingsListener.java
Normal file
@ -0,0 +1,20 @@
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
public class SettingsListener implements ChangeListener{
|
||||
private int settingToSet;
|
||||
private int settingValue;
|
||||
private FrameMenu menu;
|
||||
public SettingsListener(int settingToSet, FrameMenu menu){
|
||||
this.settingToSet=settingToSet;
|
||||
this.menu=menu;
|
||||
}
|
||||
public void stateChanged(ChangeEvent evenement) {
|
||||
JSlider slider = (JSlider) evenement.getSource();
|
||||
settingValue=slider.getValue();
|
||||
this.menu.setSettings(this.settingToSet, settingValue);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user