Ajout demande du nombre de joueur
This commit is contained in:
parent
41ec67a568
commit
23dc15b5ab
@ -1,5 +1,5 @@
|
||||
@JAVAC_OPT = -implicit:none \
|
||||
-d build -classpath build -sourcepath src
|
||||
-d build -classpath "build" -sourcepath src
|
||||
PACKAGE = fr.iutfbleau.projetAgile
|
||||
PACKAGE_PATH = fr/iutfbleau/projetAgile
|
||||
|
||||
@ -25,7 +25,7 @@ Controller = build/$(PACKAGE_PATH)/Puissance4/Controller/GrilleMouseListener.cla
|
||||
#BUT PAR DEFAUT
|
||||
ArgileGames.jar : build/$(PACKAGE_PATH)/Main.class
|
||||
@echo "Creating jar..."
|
||||
@jar cfe ArgileGames.jar $(PACKAGE_PATH).Main -C build fr -C res images
|
||||
@jar cfme ArgileGames.jar Manifest.txt $(PACKAGE_PATH).Main res/ -C build fr
|
||||
@echo "Finished"
|
||||
|
||||
#------- Events ------
|
||||
@ -144,7 +144,7 @@ build/$(PACKAGE_PATH)/Puissance4/LancementPuissance4.class : src/$(PACKAGE_PATH)
|
||||
build/$(PACKAGE_PATH)/Puissance4/View/ColorChooserDialog.class \
|
||||
build/$(PACKAGE_PATH)/Puissance4/View/Grille.class \
|
||||
build/$(PACKAGE_PATH)/Puissance4/Model/GrilleModel.class
|
||||
@javac $(@JAVAC_OPT) $<
|
||||
@javac -implicit:none -d build -classpath "build:res/mariadb-client.jar" -sourcepath src $<
|
||||
|
||||
build/$(PACKAGE_PATH)/Jeu.class : src/$(PACKAGE_PATH)/Jeu.java
|
||||
@javac $(@JAVAC_OPT) $<
|
||||
|
3
projetAgile/Manifest.txt
Normal file
3
projetAgile/Manifest.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path: res/mariadb-client.jar
|
||||
Created-By: 1.7.0_06 (Oracle Corporation)
|
@ -20,7 +20,7 @@ public class BoutonsMenu extends JComponent{
|
||||
super();
|
||||
this.path=path0;
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
this.img = Toolkit.getDefaultToolkit().getImage(cl.getResource("images/"+this.path+".png"));
|
||||
this.img = Toolkit.getDefaultToolkit().getImage(cl.getResource("res/images/"+this.path+".png"));
|
||||
this.survol=false;
|
||||
this.disponibiliter=disponibiliter0;
|
||||
}
|
||||
|
@ -26,8 +26,10 @@ public class ColorChooserListener implements ChangeListener {
|
||||
ColorSelectionModel chooser = (ColorSelectionModel) e.getSource();
|
||||
if(this.player == Constants.PLAYER_ONE)
|
||||
Constants.PLAYER_ONE_COLOR = chooser.getSelectedColor();
|
||||
else
|
||||
else if(this.player == Constants.PLAYER_THREE)
|
||||
Constants.PLAYER_TWO_COLOR = chooser.getSelectedColor();
|
||||
else
|
||||
Constants.PLAYER_THREE_COLOR = chooser.getSelectedColor();
|
||||
composant.repaint();
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,17 @@ public class ModelEventListener implements GridChangedListener {
|
||||
|
||||
private Puissance4Panel panel;
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
* @param p
|
||||
*/
|
||||
public ModelEventListener(Puissance4Panel p) {
|
||||
this.panel = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute un pion à l'emplacement modifié dans la grille
|
||||
*/
|
||||
@Override
|
||||
public void gridChanged(GridEvent e) {
|
||||
this.panel.addPlayerPiece(e.getColumn(), e.getRow(), e.getPlayer());
|
||||
@ -20,6 +27,6 @@ public class ModelEventListener implements GridChangedListener {
|
||||
public void statusChanged(StatusEvent e) {
|
||||
this.panel.changeLabel(e.getPlayerTurn());
|
||||
this.panel.changeHoverColor(e.getPlayerTurn());
|
||||
this.panel.setGameStatus(e.getStatus(), e.getPlayerTurn(), e.getPlayerOneScore(), e.getPlayerTwoScore());
|
||||
this.panel.setGameStatus(e.getStatus(), e.getPlayerTurn(), e.getPlayerOneScore(), e.getPlayerTwoScore(), e.getPlayerThreeScore());
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,10 @@ public class Puissance4Controller {
|
||||
*/
|
||||
public void initPanel() {
|
||||
this.panel.init();
|
||||
this.panel.setPlayerNumber(this.modele.getPlayerNumber());
|
||||
this.panel.changeHoverColor(this.modele.getPlayerTurn());
|
||||
this.panel.changeLabel(this.modele.getPlayerTurn());
|
||||
this.panel.changeScore(this.modele.getPlayerOneScore(), this.modele.getPlayerTwoScore());
|
||||
this.panel.changeScore(this.modele.getPlayerOneScore(), this.modele.getPlayerTwoScore(), this.modele.getPlayerThreeScore());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,4 +123,18 @@ public class Puissance4Controller {
|
||||
this.panel.setPlayerOneName(this.modele.getPlayerOneName());
|
||||
this.panel.setPlayerTwoName(this.modele.getPlayerTwoName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Change le nom des joueurs dans le modèle et la vue
|
||||
* @param J1 le nom du joueur 1
|
||||
* @param J2 le nom du joueur 2
|
||||
*/
|
||||
public void changeName(String J1, String J2, String J3) {
|
||||
this.modele.setPlayerOneName(J1);
|
||||
this.modele.setPlayerTwoName(J2);
|
||||
this.modele.setPlayerThreeName(J3);
|
||||
this.panel.setPlayerOneName(this.modele.getPlayerOneName());
|
||||
this.panel.setPlayerTwoName(this.modele.getPlayerTwoName());
|
||||
this.panel.setPlayerThreeName(this.modele.getPlayerThreeName());
|
||||
}
|
||||
}
|
||||
|
@ -56,11 +56,11 @@ public abstract class AbstractGridInitiater {
|
||||
* @param playerOneScore Le score du joueur 1
|
||||
* @param playerTwoScore Le score du joueur 2
|
||||
*/
|
||||
protected void fireStatusChanged(GameStatus status, int playerTurn, int playerOneScore, int playerTwoScore) {
|
||||
protected void fireStatusChanged(GameStatus status, int playerTurn, int playerOneScore, int playerTwoScore, int playerThreeScore) {
|
||||
StatusEvent event = null;
|
||||
for(GridChangedListener listener : getGridListeners()) {
|
||||
if(event == null)
|
||||
event = new StatusEvent(status, playerTurn, playerOneScore, playerTwoScore);
|
||||
event = new StatusEvent(status, playerTurn, playerOneScore, playerTwoScore, playerThreeScore);
|
||||
listener.statusChanged(event);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ public class StatusEvent {
|
||||
private int playerTurn;
|
||||
private int playerOneScore;
|
||||
private int playerTwoScore;
|
||||
private int playerThreeScore;
|
||||
|
||||
/**
|
||||
* Crée un évènement
|
||||
@ -17,12 +18,14 @@ public class StatusEvent {
|
||||
* @param playerTurn le tour du joueur
|
||||
* @param playerOneScore le score du joueur 1
|
||||
* @param playerTwoScore le score du joueur 2
|
||||
* @param playerThreeScore le score du joueur 2
|
||||
*/
|
||||
public StatusEvent(GameStatus status, int playerTurn, int playerOneScore, int playerTwoScore) {
|
||||
public StatusEvent(GameStatus status, int playerTurn, int playerOneScore, int playerTwoScore, int playerThreeScore) {
|
||||
this.status = status;
|
||||
this.playerTurn = playerTurn;
|
||||
this.playerOneScore = playerOneScore;
|
||||
this.playerTwoScore = playerTwoScore;
|
||||
this.playerThreeScore = playerThreeScore;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,4 +59,12 @@ public class StatusEvent {
|
||||
public int getPlayerTwoScore() {
|
||||
return playerTwoScore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le score du joueur 3
|
||||
* @return Le score du joueur 3
|
||||
*/
|
||||
public int getPlayerThreeScore() {
|
||||
return playerThreeScore;
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,17 @@ import fr.iutfbleau.projetAgile.Puissance4.View.Grille;
|
||||
import fr.iutfbleau.projetAgile.Puissance4.View.ColorChooserDialog;
|
||||
import fr.iutfbleau.projetAgile.Puissance4.Model.GrilleModel;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import org.mariadb.jdbc.*;
|
||||
import java.sql.Statement;
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
|
||||
/**
|
||||
* Classe qui initialise une partie de Puissance 4
|
||||
@ -24,17 +32,44 @@ public class LancementPuissance4 implements Jeu{
|
||||
public LancementPuissance4(JFrame fenetre) throws CancellationException{
|
||||
String J1 = null;
|
||||
String J2 = null;
|
||||
ColorChooserDialog chooser = new ColorChooserDialog(fenetre, true);
|
||||
String J3 = null;
|
||||
int playerNumber;
|
||||
JRadioButton twoPlayer = new JRadioButton("Deux joueurs");
|
||||
JRadioButton threePlayer = new JRadioButton("Trois joueurs");
|
||||
ButtonGroup buttons = new ButtonGroup();
|
||||
buttons.add(twoPlayer);
|
||||
buttons.add(threePlayer);
|
||||
Object[] message = {
|
||||
"Combien de joueurs ?", twoPlayer, threePlayer
|
||||
};
|
||||
int choix = JOptionPane.showConfirmDialog(fenetre, message, "Entrez le nombre de joueur", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
||||
if(choix != JOptionPane.OK_OPTION) {
|
||||
throw new CancellationException("User cancelled");
|
||||
}
|
||||
|
||||
if(buttons.getSelection() == twoPlayer.getModel())
|
||||
playerNumber = 2;
|
||||
else
|
||||
playerNumber = 3;
|
||||
|
||||
ColorChooserDialog chooser = new ColorChooserDialog(fenetre, true, playerNumber);
|
||||
if (chooser.getChoice()) {
|
||||
J1 = chooser.getPlayerOneName();
|
||||
J2 = chooser.getPlayerTwoName();
|
||||
if(playerNumber == 3)
|
||||
J3 = chooser.getPlayerThreeName();
|
||||
} else {
|
||||
throw new CancellationException("User cancelled");
|
||||
}
|
||||
|
||||
this.sendToDatabase(playerNumber);
|
||||
Grille g=new Grille();
|
||||
GrilleModel m=new GrilleModel();
|
||||
GrilleModel m=new GrilleModel(playerNumber);
|
||||
this.P4 = new Puissance4Controller(g, m);
|
||||
this.P4.changeName(J1, J2);
|
||||
if(playerNumber == 2)
|
||||
this.P4.changeName(J1, J2);
|
||||
else
|
||||
this.P4.changeName(J1, J2, J3);
|
||||
this.P4.initPanel();
|
||||
}
|
||||
|
||||
@ -55,4 +90,32 @@ public class LancementPuissance4 implements Jeu{
|
||||
public JPanel getPanel(){
|
||||
return this.P4.getPanel();
|
||||
}
|
||||
|
||||
public void sendToDatabase(int playerNumber) {
|
||||
try {
|
||||
|
||||
Class.forName("org.mariadb.jdbc.Driver"); //Verification du pilote
|
||||
Connection conn = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/justiney", "justiney", "motdepasseJustiney");
|
||||
|
||||
try {
|
||||
Statement req = conn.createStatement();
|
||||
//------ Requete preparee --------
|
||||
if(playerNumber == 2)
|
||||
req.executeUpdate("UPDATE SondageMarchePuissance4 SET twoPlayer = twoPlayer + 1");
|
||||
else
|
||||
req.executeUpdate("UPDATE SondageMarchePuissance4 SET threePlayer = threePlayer + 1");
|
||||
|
||||
req.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Probleme requete");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
conn.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,19 +15,40 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
private int column, row;
|
||||
private String playerOneName;
|
||||
private String playerTwoName;
|
||||
private String playerThreeName;
|
||||
private int playerOneScore;
|
||||
private int playerTwoScore;
|
||||
private int playerThreeScore;
|
||||
private int playerNumber;
|
||||
|
||||
/**
|
||||
* Crée le modèle et l'initialise avec des cases vides
|
||||
*/
|
||||
public GrilleModel() {
|
||||
public GrilleModel(int playerNumber) {
|
||||
super();
|
||||
this.column = Constants.COLUMN_COUNT;
|
||||
this.row = Constants.ROW_COUNT;
|
||||
this.grille = new int[this.column][this.row];
|
||||
this.playerOneScore = 0;
|
||||
this.playerTwoScore = 0;
|
||||
this.playerThreeScore = 0;
|
||||
this.playerNumber = playerNumber;
|
||||
this.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée le modèle et l'initialise avec des les cases du tableau donné en arguments
|
||||
*/
|
||||
public GrilleModel(int[][] tab, int playerNumber) {
|
||||
//Faire un test pour le nombre de colonnes/lignes
|
||||
super();
|
||||
this.column = Constants.COLUMN_COUNT;
|
||||
this.row = Constants.ROW_COUNT;
|
||||
this.grille = tab;
|
||||
this.playerOneScore = 0;
|
||||
this.playerTwoScore = 0;
|
||||
this.playerThreeScore = 0;
|
||||
this.playerNumber = playerNumber;
|
||||
this.reset();
|
||||
}
|
||||
|
||||
@ -121,13 +142,20 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
*/
|
||||
private boolean verifyAlignedPiece(int numColumn, int numRow, int columnOffset, int rowOffset, int playerColor) {
|
||||
int couleur = playerColor;
|
||||
int max = 0;
|
||||
int compteur = 0;
|
||||
|
||||
if(this.playerNumber == 2)
|
||||
max = Constants.ALIGNED_NUMBER_TWO;
|
||||
else
|
||||
max = Constants.ALIGNED_NUMBER_THREE;
|
||||
|
||||
while ((numColumn >= 0) && (numColumn < this.column) && (numRow >= 0) && (numRow < this.row)) {
|
||||
if (grille[numColumn][numRow] != couleur)
|
||||
compteur = 0;
|
||||
else
|
||||
compteur++;
|
||||
if (compteur >= 4)
|
||||
if (compteur >= max)
|
||||
return true;
|
||||
numColumn += columnOffset;
|
||||
numRow += rowOffset;
|
||||
@ -143,8 +171,20 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
* Change le tour du joueur et notifie tous les listeners
|
||||
*/
|
||||
public void switchPlayer() {
|
||||
this.playerTurn = this.playerTurn == Constants.PLAYER_ONE ? Constants.PLAYER_TWO : Constants.PLAYER_ONE;
|
||||
fireStatusChanged(this.gameStatus, this.playerTurn, this.playerOneScore, this.playerTwoScore);
|
||||
switch(this.playerNumber) {
|
||||
case 3 :
|
||||
if(this.playerTurn == Constants.PLAYER_ONE)
|
||||
this.playerTurn = Constants.PLAYER_TWO;
|
||||
else if(this.playerTurn == Constants.PLAYER_TWO)
|
||||
this.playerTurn = Constants.PLAYER_THREE;
|
||||
else
|
||||
this.playerTurn = Constants.PLAYER_ONE;
|
||||
break;
|
||||
default :
|
||||
this.playerTurn = this.playerTurn == Constants.PLAYER_ONE ? Constants.PLAYER_TWO : Constants.PLAYER_ONE;
|
||||
}
|
||||
|
||||
fireStatusChanged(this.gameStatus, this.playerTurn, this.playerOneScore, this.playerTwoScore, this.playerThreeScore);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,10 +196,12 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
if(gameStatus == GameStatus.WIN) {
|
||||
if(this.playerTurn == Constants.PLAYER_ONE)
|
||||
playerOneScore++;
|
||||
else
|
||||
else if(this.playerTurn == Constants.PLAYER_TWO)
|
||||
playerTwoScore++;
|
||||
else
|
||||
playerThreeScore++;
|
||||
}
|
||||
fireStatusChanged(this.gameStatus, this.playerTurn, this.playerOneScore, this.playerTwoScore);
|
||||
fireStatusChanged(this.gameStatus, this.playerTurn, this.playerOneScore, this.playerTwoScore, this.playerThreeScore);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,6 +252,15 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
return this.playerTwoName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le nom du joueur 3
|
||||
* @return Un string du nom du joueur 2
|
||||
*/
|
||||
public String getPlayerThreeName() {
|
||||
return this.playerThreeName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne le score du joueur 1
|
||||
* @return Le score du joueur 1
|
||||
@ -226,6 +277,14 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
return playerTwoScore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le score du joueur 3
|
||||
* @return Le score du joueur 3
|
||||
*/
|
||||
public int getPlayerThreeScore() {
|
||||
return playerTwoScore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le {@link fr.iutfbleau.projetAgile.Puissance4.Utils.GameStatus status} de la partie
|
||||
* @return Le status de la partie
|
||||
@ -234,6 +293,10 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
return this.gameStatus;
|
||||
}
|
||||
|
||||
public int getPlayerNumber() {
|
||||
return this.playerNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Définit le nom du joueur 1
|
||||
* @param playerOneName Le nom du joueur 1
|
||||
@ -249,4 +312,12 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
public void setPlayerTwoName(String playerTwoName) {
|
||||
this.playerTwoName = playerTwoName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Définit le nom du joueur 2
|
||||
* @param playerThreeName Le nom du joueur 2
|
||||
*/
|
||||
public void setPlayerThreeName(String playerThreeName) {
|
||||
this.playerThreeName = playerThreeName;
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,13 @@ public class Constants {
|
||||
*/
|
||||
public static Color PLAYER_ONE_COLOR = new Color(252,21,21);
|
||||
/**
|
||||
* La couleur du joueur 1
|
||||
* La couleur du joueur 2
|
||||
*/
|
||||
public static Color PLAYER_TWO_COLOR = new Color(241,205,15);
|
||||
/**
|
||||
* La couleur du joueur 3
|
||||
*/
|
||||
public static Color PLAYER_THREE_COLOR = new Color(15,20,241);
|
||||
/**
|
||||
* La couleur d'un pion "vide"
|
||||
*/
|
||||
@ -34,6 +38,10 @@ public class Constants {
|
||||
* L'entier qui représente un pion du joueur 2
|
||||
*/
|
||||
public final static int PLAYER_TWO = 2;
|
||||
/**
|
||||
* L'entier qui représente un pion du joueur 3
|
||||
*/
|
||||
public final static int PLAYER_THREE = 3;
|
||||
/**
|
||||
* Le survol du pion est activé ?
|
||||
*/
|
||||
@ -50,6 +58,15 @@ public class Constants {
|
||||
* Le nombre de ligne de la grille
|
||||
*/
|
||||
public final static int ROW_COUNT = 6;
|
||||
/**
|
||||
* Nombre de pion aligné avec 2 joueurs
|
||||
*/
|
||||
public final static int ALIGNED_NUMBER_TWO = 4;
|
||||
/**
|
||||
* Nombre de pion aligné avec 3 joueurs
|
||||
*/
|
||||
public final static int ALIGNED_NUMBER_THREE = 3;
|
||||
|
||||
|
||||
private Constants() {
|
||||
|
||||
|
@ -27,6 +27,7 @@ public class ColorChooserDialog extends JDialog{
|
||||
|
||||
private JTextField field1;
|
||||
private JTextField field2;
|
||||
private JTextField field3;
|
||||
private boolean confirm = false;
|
||||
|
||||
/**
|
||||
@ -35,7 +36,7 @@ public class ColorChooserDialog extends JDialog{
|
||||
* @param modal specifie si la fenêtre modale bloque les interactions avec les fenêtres mères
|
||||
* @see javax.swing.JDialog#JDialog(Frame, boolean)
|
||||
*/
|
||||
public ColorChooserDialog(Frame owner, boolean modal) {
|
||||
public ColorChooserDialog(Frame owner, boolean modal, int playerNumber) {
|
||||
super(owner, "Choisissez vos noms et couleurs",modal);
|
||||
this.setLayout(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
@ -43,8 +44,10 @@ public class ColorChooserDialog extends JDialog{
|
||||
int length = 12;
|
||||
JColorChooser playerOneChooser = new JColorChooser(Constants.PLAYER_ONE_COLOR);
|
||||
JColorChooser playerTwoChooser = new JColorChooser(Constants.PLAYER_TWO_COLOR);
|
||||
JColorChooser playerThreeChooser = new JColorChooser(Constants.PLAYER_THREE_COLOR);
|
||||
AbstractColorChooserPanel[] panelsP1 = playerOneChooser.getChooserPanels();
|
||||
AbstractColorChooserPanel[] panelsP2 = playerTwoChooser.getChooserPanels();
|
||||
AbstractColorChooserPanel[] panelsP3 = playerThreeChooser.getChooserPanels();
|
||||
|
||||
UIManager.put("ColorChooser.swatchesSwatchSize", new Dimension(length, length));
|
||||
UIManager.put("ColorChooser.swatchesRecentSwatchSize", new Dimension(length, length));
|
||||
@ -53,37 +56,49 @@ public class ColorChooserDialog extends JDialog{
|
||||
for(int i = 1; i < panelsP1.length; i++) {
|
||||
playerOneChooser.removeChooserPanel(panelsP1[i]);
|
||||
playerTwoChooser.removeChooserPanel(panelsP2[i]);
|
||||
playerThreeChooser.removeChooserPanel(panelsP3[i]);
|
||||
}
|
||||
|
||||
JButton bouton = new JButton("Confirmer");
|
||||
Pion pionP1 = new Pion(Constants.PLAYER_ONE);
|
||||
Pion pionP2 = new Pion(Constants.PLAYER_TWO);
|
||||
Pion pionP3 = new Pion(Constants.PLAYER_THREE);
|
||||
bouton.addActionListener(new ColorActionListener(this));
|
||||
pionP1.setPreferredSize(new Dimension(50,50));
|
||||
pionP2.setPreferredSize(new Dimension(50,50));
|
||||
pionP3.setPreferredSize(new Dimension(50,50));
|
||||
|
||||
JPanel panelPionP1 = new JPanel();
|
||||
JPanel panelPionP2 = new JPanel();
|
||||
JPanel panelPionP3 = new JPanel();
|
||||
|
||||
panelPionP1.add(pionP1);
|
||||
panelPionP1.setBackground(Constants.BACKGROUND_COLOR);
|
||||
panelPionP2.add(pionP2);
|
||||
panelPionP2.setBackground(Constants.BACKGROUND_COLOR);
|
||||
panelPionP3.add(pionP3);
|
||||
panelPionP3.setBackground(Constants.BACKGROUND_COLOR);
|
||||
|
||||
playerOneChooser.setPreviewPanel(panelPionP1);
|
||||
playerTwoChooser.setPreviewPanel(panelPionP2);
|
||||
playerThreeChooser.setPreviewPanel(panelPionP3);
|
||||
|
||||
playerOneChooser.getSelectionModel().addChangeListener(new ColorChooserListener(pionP1, Constants.PLAYER_ONE));
|
||||
|
||||
playerTwoChooser.getSelectionModel().addChangeListener(new ColorChooserListener(pionP2, Constants.PLAYER_TWO));
|
||||
|
||||
playerThreeChooser.getSelectionModel().addChangeListener(new ColorChooserListener(pionP2, Constants.PLAYER_THREE));
|
||||
|
||||
|
||||
JPanel panelP1 = new JPanel(new GridBagLayout());
|
||||
JPanel panelP2 = new JPanel(new GridBagLayout());
|
||||
JPanel panelP3 = new JPanel(new GridBagLayout());
|
||||
JLabel labelP1 = new JLabel("Nom et couleur du joueur 1");
|
||||
JLabel labelP2 = new JLabel("Nom et couleur du joueur 2");
|
||||
JLabel labelP3 = new JLabel("Nom et couleur du joueur 2");
|
||||
this.field1 = new JTextField("Joueur 1");
|
||||
this.field2 = new JTextField("Joueur 2");
|
||||
this.field3 = new JTextField("Joueur 3");
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
@ -127,8 +142,33 @@ public class ColorChooserDialog extends JDialog{
|
||||
gbc.gridy = 0;
|
||||
this.add(panelP2,gbc);
|
||||
|
||||
if(playerNumber == 3) {
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.weighty = 0;
|
||||
panelP3.add(labelP3, gbc);
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
panelP3.add(field3, gbc);
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 2;
|
||||
gbc.weighty = 0.5;
|
||||
panelP3.add(playerThreeChooser, gbc);
|
||||
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
gbc.gridwidth = 2;
|
||||
gbc.insets = new Insets(5, 5, 5, 5);
|
||||
this.add(panelP3,gbc);
|
||||
}
|
||||
|
||||
gbc.gridx = 1;
|
||||
gbc.gridy = 1;
|
||||
if(playerNumber == 3)
|
||||
gbc.gridy = 2;
|
||||
else
|
||||
gbc.gridy = 1;
|
||||
gbc.weighty = 0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.EAST;
|
||||
@ -209,6 +249,14 @@ public class ColorChooserDialog extends JDialog{
|
||||
return this.field2.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de récupérer le nom inscrit pour le joueur 3
|
||||
* @return un {@code String} correspondant au nom du joueur 3
|
||||
*/
|
||||
public String getPlayerThreeName() {
|
||||
return this.field3.getText();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Permet de confirmer la choix de l'utilisateur
|
||||
|
@ -94,8 +94,11 @@ public class Grille extends JPanel{
|
||||
case Constants.PLAYER_TWO :
|
||||
c = new Color(Constants.PLAYER_TWO_COLOR.getRed(), Constants.PLAYER_TWO_COLOR.getGreen(), Constants.PLAYER_TWO_COLOR.getBlue(), 100);
|
||||
break;
|
||||
case Constants.PLAYER_THREE :
|
||||
c = new Color(Constants.PLAYER_THREE_COLOR.getRed(), Constants.PLAYER_THREE_COLOR.getGreen(), Constants.PLAYER_THREE_COLOR.getBlue(), 100);
|
||||
break;
|
||||
default :
|
||||
c = Color.BLACK;
|
||||
c = Color.BLACK;
|
||||
}
|
||||
Pion.setHighlightColor(c);
|
||||
}
|
||||
|
@ -88,6 +88,9 @@ public class Pion extends JComponent{
|
||||
case Constants.PLAYER_TWO :
|
||||
c = Constants.PLAYER_TWO_COLOR;
|
||||
break;
|
||||
case Constants.PLAYER_THREE :
|
||||
c = Constants.PLAYER_THREE_COLOR;
|
||||
break;
|
||||
default :
|
||||
c = Constants.EMPTY_COLOR;
|
||||
break;
|
||||
|
@ -20,6 +20,8 @@ public class Puissance4Panel extends JPanel{
|
||||
private Grille grille;
|
||||
private String playerOneName;
|
||||
private String playerTwoName;
|
||||
private String playerThreeName;
|
||||
private int playerNumber;
|
||||
|
||||
/**
|
||||
* Crée un panneau avec la grille
|
||||
@ -156,7 +158,9 @@ public class Puissance4Panel extends JPanel{
|
||||
case Constants.PLAYER_TWO:
|
||||
this.playerTurn.setText("Tour de : " + this.playerTwoName);
|
||||
break;
|
||||
|
||||
case Constants.PLAYER_THREE:
|
||||
this.playerTurn.setText("Tour de : " + this.playerThreeName);
|
||||
break;
|
||||
default:
|
||||
this.playerTurn.setText("JOUEUR INCONNU");
|
||||
break;
|
||||
@ -169,7 +173,17 @@ public class Puissance4Panel extends JPanel{
|
||||
* @param playerTwoScore le score du joueur 2
|
||||
*/
|
||||
public void changeScore(int playerOneScore, int playerTwoScore) {
|
||||
this.score.setText(this.playerOneName + " : " + playerOneScore + " - " + playerTwoScore + " : " + this.playerTwoName);
|
||||
this.score.setText(this.playerOneName + " : " + playerOneScore + " | " + this.playerTwoName + " : " + playerTwoScore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change le texte affichant le score des joueurs
|
||||
* @param playerOneScore le score du joueur 1
|
||||
* @param playerTwoScore le score du joueur 2
|
||||
* @param playerThreeScore le score du joueur 3
|
||||
*/
|
||||
public void changeScore(int playerOneScore, int playerTwoScore, int playerThreeScore) {
|
||||
this.score.setText(this.playerOneName + " : " + playerOneScore + " | " + this.playerTwoName + " : " + playerTwoScore + " | " + this.playerThreeName + " : " + playerThreeScore);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,11 +203,18 @@ public class Puissance4Panel extends JPanel{
|
||||
* @param playerOneScore le score du joueur 1
|
||||
* @param playerTwoScore le score du joueur 2
|
||||
*/
|
||||
public void setGameStatus(GameStatus status, int playerTurn, int playerOneScore, int playerTwoScore) {
|
||||
public void setGameStatus(GameStatus status, int playerTurn, int playerOneScore, int playerTwoScore, int playerThreeScore) {
|
||||
this.grille.hover(-1);
|
||||
switch(status){
|
||||
case WIN:
|
||||
this.playerTurn.setText("Victoire de : " + (playerTurn == Constants.PLAYER_ONE ? this.playerOneName : this.playerTwoName));
|
||||
case WIN:
|
||||
String gagnant = null;
|
||||
if(playerTurn == Constants.PLAYER_ONE)
|
||||
gagnant = this.playerOneName;
|
||||
else if(playerTurn == Constants.PLAYER_TWO)
|
||||
gagnant = this.playerTwoName;
|
||||
else
|
||||
gagnant = this.playerThreeName;
|
||||
this.playerTurn.setText("Victoire de : " + gagnant);
|
||||
break;
|
||||
|
||||
case DRAW:
|
||||
@ -204,7 +225,10 @@ public class Puissance4Panel extends JPanel{
|
||||
this.changeLabel(playerTurn);
|
||||
break;
|
||||
}
|
||||
this.changeScore(playerOneScore, playerTwoScore);
|
||||
if(this.playerNumber == 2)
|
||||
this.changeScore(playerOneScore, playerTwoScore);
|
||||
else
|
||||
this.changeScore(playerOneScore, playerTwoScore, playerThreeScore);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,6 +247,18 @@ public class Puissance4Panel extends JPanel{
|
||||
this.playerTwoName = playerTwoName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de définir le nom du joueur 3
|
||||
* @param playerTwoName le nom du joueur
|
||||
*/
|
||||
public void setPlayerThreeName(String playerThreeName) {
|
||||
this.playerThreeName = playerThreeName;
|
||||
}
|
||||
|
||||
public void setPlayerNumber(int playerNumber) {
|
||||
this.playerNumber = playerNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne la grille du Puissance 4
|
||||
* @return La grille du Puissance 4
|
||||
|
Loading…
Reference in New Issue
Block a user