Antialiasing, changement de nom avec vérifications
This commit is contained in:
parent
8407bc43a2
commit
db896573ac
@ -43,7 +43,8 @@ public class BoutonsMenu extends JComponent{
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
Graphics2D secondPinceau = (Graphics2D) pinceau.create();
|
||||
secondPinceau.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
// obligatoire : si le composant n'est pas censé être transparent
|
||||
if (this.isOpaque()) {
|
||||
// obligatoire : on repeint toute la surface avec la couleur de fond
|
||||
|
@ -11,6 +11,8 @@ import fr.iutfbleau.projetAgile.Puissance4.Model.GrilleModel;
|
||||
import fr.iutfbleau.projetAgile.Puissance4.View.Grille;
|
||||
|
||||
import java.awt.event.WindowListener;
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public abstract class Menu{
|
||||
@ -140,11 +142,16 @@ public abstract class Menu{
|
||||
if((g==Menu.MENU || g==Menu.PUISSANCE_4)){
|
||||
if(g!=Menu.MENU){
|
||||
if(g==Menu.PUISSANCE_4){
|
||||
LancementPartie lm=new LancementPartie(Menu.frame);
|
||||
lm.addActionListener(new ObservateurAccueil(lm.getPanel()));
|
||||
Menu.frame.add(lm.getPanel(), Menu.PUISSANCE_4);
|
||||
try {
|
||||
LancementPartie lm=new LancementPartie(Menu.frame);
|
||||
lm.accueilButton(new ObservateurAccueil(lm.getPanel()));
|
||||
Menu.frame.add(lm.getPanel(), Menu.PUISSANCE_4);
|
||||
Menu.cd.show(Menu.frame.getContentPane(), g);
|
||||
} catch (CancellationException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
Menu.cd.show(Menu.frame.getContentPane(), g);
|
||||
}
|
||||
else{
|
||||
Menu.cd.removeLayoutComponent(composent);
|
||||
|
@ -18,7 +18,7 @@ public class Puissance4Controller {
|
||||
* @param grille La grille
|
||||
* @param modele Le modèle
|
||||
*/
|
||||
public Puissance4Controller(Grille grille, GrilleModel modele, String J1, String J2) {
|
||||
public Puissance4Controller(Grille grille, GrilleModel modele) {
|
||||
this.modele = modele;
|
||||
this.grille = grille;
|
||||
|
||||
@ -30,25 +30,21 @@ public class Puissance4Controller {
|
||||
this.grille.addMouseListener(mouseListener);
|
||||
this.grille.addMouseMotionListener(mouseListener);
|
||||
|
||||
//Initialisation des noms des joueurs
|
||||
this.modele.setPlayerOneName(J1);
|
||||
this.modele.setPlayerTwoName(J2);
|
||||
|
||||
//Initialisation du panneau avec la grille, les boutons, etc
|
||||
this.panel = new Puissance4Panel(this.grille);
|
||||
this.panel.init();
|
||||
this.panel.resetButton(resetListener);
|
||||
ModelEventListener modelListener = new ModelEventListener(panel);
|
||||
this.panel.setPlayerOneName(this.modele.getPlayerOneName());
|
||||
this.panel.setPlayerTwoName(this.modele.getPlayerTwoName());
|
||||
this.panel.changeLabel(this.modele.getPlayerTurn());
|
||||
//Ajout listener au modèle
|
||||
this.modele.addGridListener(modelListener);
|
||||
}
|
||||
|
||||
public void initPanel() {
|
||||
this.panel.init();
|
||||
this.panel.changeLabel(this.modele.getPlayerTurn());
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
if(this.modele.getGameStatus() == GameStatus.PLAYING) {
|
||||
|
||||
int confirmation = JOptionPane.showConfirmDialog(this.panel, "Une partie est en cours ! Etes-vous sûr de vouloir recommencer ?", "Recommencer", JOptionPane.YES_NO_OPTION);
|
||||
if(confirmation == 1) return;
|
||||
}
|
||||
@ -79,12 +75,14 @@ public class Puissance4Controller {
|
||||
return this.panel;
|
||||
}
|
||||
|
||||
public void AddActionListener(ActionListener l){
|
||||
this.panel.acceuilButton(l);
|
||||
public void accueilButton(ActionListener l){
|
||||
this.panel.accueilButton(l);
|
||||
}
|
||||
|
||||
public void ChangeName(String J1, String J2)throws IllegalArgumentException{
|
||||
public void changeName(String J1, String J2) {
|
||||
this.modele.setPlayerOneName(J1);
|
||||
this.modele.setPlayerTwoName(J2);
|
||||
this.panel.setPlayerOneName(this.modele.getPlayerOneName());
|
||||
this.panel.setPlayerTwoName(this.modele.getPlayerTwoName());
|
||||
}
|
||||
}
|
||||
|
@ -5,52 +5,48 @@ import fr.iutfbleau.projetAgile.Puissance4.Controller.Puissance4Controller;
|
||||
import fr.iutfbleau.projetAgile.Puissance4.View.Grille;
|
||||
import fr.iutfbleau.projetAgile.Puissance4.Model.GrilleModel;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
public class LancementPartie {
|
||||
private Puissance4Controller P4;
|
||||
public LancementPartie(JFrame fenetre){
|
||||
public LancementPartie(JFrame fenetre) throws CancellationException{
|
||||
boolean nameCorrect = false;
|
||||
JTextField field1 = new JTextField("Joueur 1");
|
||||
JTextField field2 = new JTextField("Joueur 2");
|
||||
Object[] message = {
|
||||
"Entrez le nom du joueur 1", field1,
|
||||
"Entrez le nom du joueur 2:", field2,
|
||||
};
|
||||
int choix = JOptionPane.showConfirmDialog(fenetre, message, "Entrez les noms des joueurs", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
||||
if (choix == JOptionPane.OK_OPTION)
|
||||
{
|
||||
try {
|
||||
String J1 = field1.getText();
|
||||
String J2 = field2.getText();
|
||||
Grille g=new Grille();
|
||||
GrilleModel m=new GrilleModel();
|
||||
this.P4= new Puissance4Controller(g, m, J1, J2);
|
||||
} catch (Exception e) {
|
||||
|
||||
String J1 = null;
|
||||
String J2 = null;
|
||||
while(!nameCorrect) {
|
||||
int choix = JOptionPane.showConfirmDialog(fenetre, message, "Entrez les noms des joueurs", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
||||
if (choix == JOptionPane.OK_OPTION) {
|
||||
J1 = field1.getText();
|
||||
J2 = field2.getText();
|
||||
nameCorrect = true;
|
||||
if(J1.isEmpty() || J2.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(fenetre,"Un des noms est vides","Erreur ", JOptionPane.ERROR_MESSAGE);
|
||||
nameCorrect = false;
|
||||
}
|
||||
if(J1.compareTo(J2) == 0) {
|
||||
JOptionPane.showMessageDialog(fenetre,"Les deux noms sont identiques","Erreur ", JOptionPane.ERROR_MESSAGE);
|
||||
nameCorrect = false;
|
||||
}
|
||||
} else {
|
||||
throw new CancellationException("User cancelled");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void addActionListener(ActionListener l){
|
||||
this.P4.AddActionListener(l);
|
||||
Grille g=new Grille();
|
||||
GrilleModel m=new GrilleModel();
|
||||
this.P4 = new Puissance4Controller(g, m);
|
||||
this.P4.changeName(J1, J2);
|
||||
this.P4.initPanel();
|
||||
|
||||
}
|
||||
|
||||
public void ChangeName(JFrame fenetre){
|
||||
JTextField field1 = new JTextField("Joueur 1");
|
||||
JTextField field2 = new JTextField("Joueur 2");
|
||||
Object[] message = {
|
||||
"Entrez le nom du joueur 1", field1,
|
||||
"Entrez le nom du joueur 2:", field2,
|
||||
};
|
||||
int choix = JOptionPane.showConfirmDialog(fenetre, message, "Entrez les noms des joueurs", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
||||
if (choix == JOptionPane.OK_OPTION)
|
||||
{
|
||||
try {
|
||||
String J1 = field1.getText();
|
||||
String J2 = field2.getText();
|
||||
this.P4.ChangeName(J1, J2);
|
||||
}catch(Exception e){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
public void accueilButton(ActionListener l){
|
||||
this.P4.accueilButton(l);
|
||||
}
|
||||
|
||||
public JPanel getPanel(){
|
||||
|
@ -115,7 +115,7 @@ public class Puissance4Panel extends JPanel{
|
||||
public void resetButton(ActionListener l) {
|
||||
this.reset.addActionListener(l);
|
||||
}
|
||||
public void acceuilButton(ActionListener l){
|
||||
public void accueilButton(ActionListener l){
|
||||
this.menu.addActionListener(l);
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ public class Puissance4Panel extends JPanel{
|
||||
switch(status){
|
||||
case WIN:
|
||||
this.label.setText("Victoire de : " + (playerTurn == Constants.PLAYER_ONE ? this.playerOneName : this.playerTwoName));
|
||||
System.out.println("Score : Joueur 1 = " + playerOneScore + " Joueur 2 = " + playerTwoScore);
|
||||
System.out.println("Score : " + playerOneName + " = " + playerOneScore + " " + playerTwoName + " = " + playerTwoScore);
|
||||
break;
|
||||
|
||||
case DRAW:
|
||||
|
Loading…
Reference in New Issue
Block a user