Vérification des couleurs choisies (fonction pas push jeudi et écrasée)

This commit is contained in:
Justine Yannis 2022-11-11 20:23:40 +01:00
parent 6672ba61ff
commit 400e2e8f58
5 changed files with 34 additions and 16 deletions

View File

@ -1,5 +1,6 @@
package fr.iutfbleau.projetAgile.Puissance4.Controller;
import fr.iutfbleau.projetAgile.Puissance4.Utils.Constants;
import fr.iutfbleau.projetAgile.Puissance4.View.ColorChooserDialog;
import java.awt.event.ActionEvent;
@ -26,9 +27,15 @@ public class ColorActionListener implements ActionListener{
*/
@Override
public void actionPerformed(ActionEvent e) {
if(this.dialog.isColorValid() && this.dialog.isNameValid()) {
this.dialog.setConfirm(true);
this.dialog.setVisible(false);
if(this.dialog.isColorValid()) {
if(this.dialog.isNameValid()) {
this.dialog.setConfirm(true);
this.dialog.setVisible(false);
}
}
else {
Constants.resetColor();
this.dialog.repaint();
}
}
}

View File

@ -7,9 +7,6 @@ import javax.swing.event.ChangeListener;
import fr.iutfbleau.projetAgile.Puissance4.Utils.Constants;
/**
* Classe inutile, peut être remplacée par l'appuie sur le bouton confirmé (A changer Jeudi)
*/
public class ColorChooserListener implements ChangeListener {
private JComponent composant;

View File

@ -106,15 +106,15 @@ public class GrilleModel extends AbstractGridInitiater{
}
private void verifyNewWin() {
int firstLastPlayer = this.playersList.get(0);
int secondLastPlayer = this.playersList.get(1);
boolean verifyFirstWin = this.verifyWinAll(firstLastPlayer);
boolean verifySecondWin = this.verifyWinAll(secondLastPlayer);
boolean verifyFirstWin = this.verifyWinAll(this.playerTurn);
this.switchPlayer();
boolean verifySecondWin = this.verifyWinAll(this.playerTurn);
if(verifyFirstWin && verifySecondWin) {
this.setPartyStatus(GameStatus.DRAW);
}
else if(verifyFirstWin || verifySecondWin) {
this.playerTurn = verifyFirstWin ? firstLastPlayer : secondLastPlayer;
if(verifyFirstWin)
switchPlayer();
this.setPartyStatus(GameStatus.WIN);
}
}
@ -262,6 +262,8 @@ public class GrilleModel extends AbstractGridInitiater{
}
}
// ----------------------- Getter et Setter --------------------------
/**
* ReplayersListne le playersList du joueur
* @return Le playersList du joueur
@ -378,8 +380,4 @@ public class GrilleModel extends AbstractGridInitiater{
public void setPlayerThreeName(String playerThreeName) {
this.playerThreeName = playerThreeName;
}
public void setPlayerNumber(int i) {
this.playerNumber = i;
}
}

View File

@ -75,5 +75,6 @@ public class Constants {
public static void resetColor() {
Constants.PLAYER_ONE_COLOR = new Color(252,21,21);
Constants.PLAYER_TWO_COLOR = new Color(241,205,15);
Constants.PLAYER_THREE_COLOR = new Color(15,20,241);
}
}

View File

@ -187,10 +187,21 @@ public class ColorChooserDialog extends JDialog{
*/
public boolean isColorValid() {
double distanceBetweenP1AndP2 = Math.sqrt(Math.pow(Constants.PLAYER_TWO_COLOR.getRed() - Constants.PLAYER_ONE_COLOR.getRed(), 2) + Math.pow(Constants.PLAYER_TWO_COLOR.getGreen() - Constants.PLAYER_ONE_COLOR.getGreen(), 2) + Math.pow(Constants.PLAYER_TWO_COLOR.getBlue() - Constants.PLAYER_ONE_COLOR.getBlue(), 2));
double distanceBetweenP1AndP3 = Math.sqrt(Math.pow(Constants.PLAYER_TWO_COLOR.getRed() - Constants.PLAYER_THREE_COLOR.getRed(), 2) + Math.pow(Constants.PLAYER_TWO_COLOR.getGreen() - Constants.PLAYER_THREE_COLOR.getGreen(), 2) + Math.pow(Constants.PLAYER_TWO_COLOR.getBlue() - Constants.PLAYER_THREE_COLOR.getBlue(), 2));
double distanceBetweenP2AndP3 = Math.sqrt(Math.pow(Constants.PLAYER_TWO_COLOR.getRed() - Constants.PLAYER_THREE_COLOR.getRed(), 2) + Math.pow(Constants.PLAYER_TWO_COLOR.getGreen() - Constants.PLAYER_THREE_COLOR.getGreen(), 2) + Math.pow(Constants.PLAYER_TWO_COLOR.getBlue() - Constants.PLAYER_THREE_COLOR.getBlue(), 2));
double distanceBetweenP1AndEmpty = Math.sqrt(Math.pow(Constants.EMPTY_COLOR.getRed() - Constants.PLAYER_ONE_COLOR.getRed(), 2) + Math.pow(Constants.EMPTY_COLOR.getGreen() - Constants.PLAYER_ONE_COLOR.getGreen(), 2) + Math.pow(Constants.EMPTY_COLOR.getBlue() - Constants.PLAYER_ONE_COLOR.getBlue(), 2));
double distanceBetweenP2AndEmpty = Math.sqrt(Math.pow(Constants.EMPTY_COLOR.getRed() - Constants.PLAYER_TWO_COLOR.getRed(), 2) + Math.pow(Constants.EMPTY_COLOR.getGreen() - Constants.PLAYER_TWO_COLOR.getGreen(), 2) + Math.pow(Constants.EMPTY_COLOR.getBlue() - Constants.PLAYER_TWO_COLOR.getBlue(), 2));
double distanceBetweenP3AndEmpty = Math.sqrt(Math.pow(Constants.EMPTY_COLOR.getRed() - Constants.PLAYER_THREE_COLOR.getRed(), 2) + Math.pow(Constants.EMPTY_COLOR.getGreen() - Constants.PLAYER_THREE_COLOR.getGreen(), 2) + Math.pow(Constants.EMPTY_COLOR.getBlue() - Constants.PLAYER_THREE_COLOR.getBlue(), 2));
if(distanceBetweenP1AndP2 < 150f) {
JOptionPane.showMessageDialog(this,"Les deux couleurs sont trop proches","Erreur ", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(this,"Les deux couleurs sont trop proches (1,2)","Erreur ", JOptionPane.ERROR_MESSAGE);
return false;
}
if(distanceBetweenP1AndP3 < 150f) {
JOptionPane.showMessageDialog(this,"Les deux couleurs sont trop proches (1,3)","Erreur ", JOptionPane.ERROR_MESSAGE);
return false;
}
if(distanceBetweenP2AndP3 < 150f) {
JOptionPane.showMessageDialog(this,"Les deux couleurs sont trop proches (2,3)","Erreur ", JOptionPane.ERROR_MESSAGE);
return false;
}
else if(distanceBetweenP1AndEmpty < 150f) {
@ -201,6 +212,10 @@ public class ColorChooserDialog extends JDialog{
JOptionPane.showMessageDialog(this,"La couleur du joueur 2 est trop sombre","Erreur ", JOptionPane.ERROR_MESSAGE);
return false;
}
else if(distanceBetweenP3AndEmpty < 150f) {
JOptionPane.showMessageDialog(this,"La couleur du joueur 3 est trop sombre","Erreur ", JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
}