Ajout nom joueur + score
This commit is contained in:
parent
64ed666bdb
commit
74074633ef
@ -23,6 +23,6 @@ public class ModelEventListener implements GridChangedListener {
|
||||
|
||||
@Override
|
||||
public void statusChanged(StatusEvent e) {
|
||||
this.panel.setGameStatus(e.getStatus(), e.getPlayerTurn());
|
||||
this.panel.setGameStatus(e.getStatus(), e.getPlayerTurn(), e.getPlayerOneScore(), e.getPlayerTwoScore());
|
||||
}
|
||||
}
|
||||
|
@ -24,16 +24,25 @@ public class Puissance4Controller {
|
||||
ResetGame resetListener = new ResetGame(this);
|
||||
GrilleMouseListener mouseListener = new GrilleMouseListener(this);
|
||||
|
||||
|
||||
//Initialisation de la grille
|
||||
this.grille.init(modele.getTab());
|
||||
this.panel = new Puissance4Panel(this.grille);
|
||||
this.panel.addResetListener(resetListener);
|
||||
ModelEventListener modelListener = new ModelEventListener(panel);
|
||||
this.modele.addGridListener(modelListener);
|
||||
this.grille.addMouseListener(mouseListener);
|
||||
this.grille.addMouseMotionListener(mouseListener);
|
||||
|
||||
//Initialisation des noms des joueurs
|
||||
this.modele.setPlayerOneName("Joueur 1"); //A changer
|
||||
this.modele.setPlayerTwoName("Joueur 2");
|
||||
|
||||
//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.changeLabel(this.modele.getPlayerTurn());
|
||||
this.panel.setPlayerOneName(this.modele.getPlayerOneName());
|
||||
this.panel.setPlayerTwoName(this.modele.getPlayerTwoName());
|
||||
//Ajout listener au modèle
|
||||
this.modele.addGridListener(modelListener);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
|
@ -51,11 +51,11 @@ public abstract class AbstractGridInitiater {
|
||||
* @param status
|
||||
* @param playerTurn
|
||||
*/
|
||||
protected void firePlayerChanged(GameStatus status, int playerTurn) {
|
||||
protected void firePlayerChanged(GameStatus status, int playerTurn, int playerOneScore, int playerTwoScore) {
|
||||
StatusEvent event = null;
|
||||
for(GridChangedListener listener : getGridListeners()) {
|
||||
if(event == null)
|
||||
event = new StatusEvent(status, playerTurn);
|
||||
event = new StatusEvent(status, playerTurn, playerOneScore, playerTwoScore);
|
||||
listener.playerChanged(event);
|
||||
}
|
||||
}
|
||||
@ -64,11 +64,11 @@ public abstract class AbstractGridInitiater {
|
||||
* Notifie tous les listeners lorsque le status du jeu change
|
||||
* @param status Le nouveau status
|
||||
*/
|
||||
protected void fireStatusChanged(GameStatus status, int playerTurn) {
|
||||
protected void fireStatusChanged(GameStatus status, int playerTurn, int playerOneScore, int playerTwoScore) {
|
||||
StatusEvent event = null;
|
||||
for(GridChangedListener listener : getGridListeners()) {
|
||||
if(event == null)
|
||||
event = new StatusEvent(status, playerTurn);
|
||||
event = new StatusEvent(status, playerTurn, playerOneScore, playerTwoScore);
|
||||
listener.statusChanged(event);
|
||||
}
|
||||
}
|
||||
|
@ -5,12 +5,16 @@ import fr.iutfbleau.projetAgile.Puissance4.Utils.GameStatus;
|
||||
public class StatusEvent {
|
||||
private GameStatus status;
|
||||
private int playerTurn;
|
||||
private int playerOneScore;
|
||||
private int playerTwoScore;
|
||||
/**
|
||||
* Evenement représentant le changement de status du jeu
|
||||
*/
|
||||
public StatusEvent(GameStatus status, int playerTurn) {
|
||||
public StatusEvent(GameStatus status, int playerTurn, int playerOneScore, int playerTwoScore) {
|
||||
this.status = status;
|
||||
this.playerTurn = playerTurn;
|
||||
this.playerOneScore = playerOneScore;
|
||||
this.playerTwoScore = playerTwoScore;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -24,4 +28,12 @@ public class StatusEvent {
|
||||
public int getPlayerTurn() {
|
||||
return this.playerTurn;
|
||||
}
|
||||
|
||||
public int getPlayerOneScore() {
|
||||
return playerOneScore;
|
||||
}
|
||||
|
||||
public int getPlayerTwoScore() {
|
||||
return playerTwoScore;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,10 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
private int piecePlayed = 0;
|
||||
private int playerTurn;
|
||||
private int column, row;
|
||||
private String playerOneName;
|
||||
private String playerTwoName;
|
||||
private int playerOneScore = 0;
|
||||
private int playerTwoScore = 0;
|
||||
|
||||
public GrilleModel() {
|
||||
super();
|
||||
@ -22,6 +26,7 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
this.grille = new int[this.column][this.row];
|
||||
this.reset();
|
||||
}
|
||||
|
||||
//Fonction de test (pourra être modifié)
|
||||
public void reset() {
|
||||
for(int i = 0; i < this.column; i++) {
|
||||
@ -65,7 +70,7 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
int diagonalRow = row;
|
||||
//Vérification horizontal et vertical
|
||||
if(verifyAlignedPiece(column, 0, 0, 1, playerColor) || verifyAlignedPiece(0, row, 1, 0, playerColor)) {
|
||||
this.setPartyStatus(GameStatus.STOP);
|
||||
this.setPartyStatus(GameStatus.WIN);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -75,7 +80,7 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
}
|
||||
//Vérification diagonale haut à gauche -> bas à droite
|
||||
if(verifyAlignedPiece(diagonalColumn, diagonalRow, 1, 1, playerColor)) {
|
||||
this.setPartyStatus(GameStatus.STOP);
|
||||
this.setPartyStatus(GameStatus.WIN);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -88,7 +93,7 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
|
||||
//Vérification diagonale haut à droite -> bas à gauche
|
||||
if(verifyAlignedPiece(diagonalColumn, diagonalRow, -1, 1, playerColor)) {
|
||||
this.setPartyStatus(GameStatus.STOP);
|
||||
this.setPartyStatus(GameStatus.WIN);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -127,7 +132,7 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
|
||||
public void switchPlayer() {
|
||||
this.playerTurn = this.playerTurn == Constants.PLAYER_ONE ? Constants.PLAYER_TWO : Constants.PLAYER_ONE;
|
||||
firePlayerChanged(this.gameStatus, this.playerTurn);
|
||||
firePlayerChanged(this.gameStatus, this.playerTurn, this.playerOneScore, this.playerTwoScore);
|
||||
}
|
||||
|
||||
public int getPlayerTurn() {
|
||||
@ -146,13 +151,35 @@ public class GrilleModel extends AbstractGridInitiater{
|
||||
return this.row;
|
||||
}
|
||||
|
||||
public void setPartyStatus(GameStatus gameStatus) {
|
||||
this.gameStatus = gameStatus;
|
||||
fireStatusChanged(this.gameStatus, this.playerTurn);
|
||||
public String getPlayerOneName() {
|
||||
return this.playerOneName;
|
||||
}
|
||||
|
||||
public String getPlayerTwoName() {
|
||||
return this.playerTwoName;
|
||||
}
|
||||
|
||||
public GameStatus getGameStatus() {
|
||||
return this.gameStatus;
|
||||
}
|
||||
|
||||
public void setPartyStatus(GameStatus gameStatus) {
|
||||
this.gameStatus = gameStatus;
|
||||
if(gameStatus == GameStatus.WIN) {
|
||||
if(this.playerTurn == Constants.PLAYER_ONE)
|
||||
playerOneScore++;
|
||||
else
|
||||
playerTwoScore++;
|
||||
}
|
||||
fireStatusChanged(this.gameStatus, this.playerTurn, this.playerOneScore, this.playerTwoScore);
|
||||
}
|
||||
|
||||
public void setPlayerOneName(String playerOneName) {
|
||||
this.playerOneName = playerOneName;
|
||||
}
|
||||
|
||||
public void setPlayerTwoName(String playerTwoName) {
|
||||
this.playerTwoName = playerTwoName;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package fr.iutfbleau.projetAgile.Puissance4.Utils;
|
||||
|
||||
public enum GameStatus {
|
||||
PLAYING, STOP, DRAW;
|
||||
PLAYING, WIN, DRAW;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,8 @@ public class Puissance4Panel extends JPanel{
|
||||
private JButton menu;
|
||||
private JLabel label;
|
||||
private Grille grille;
|
||||
private String playerOneName;
|
||||
private String playerTwoName;
|
||||
|
||||
public Puissance4Panel(Grille grille) {
|
||||
super();
|
||||
@ -99,26 +101,34 @@ public class Puissance4Panel extends JPanel{
|
||||
menu.setBorder(new EmptyBorder(5,10,5,10));
|
||||
}
|
||||
|
||||
public void setPlayerOneName(String playerOneName) {
|
||||
this.playerOneName = playerOneName;
|
||||
}
|
||||
|
||||
public void setPlayerTwoName(String playerTwoName) {
|
||||
this.playerTwoName = playerTwoName;
|
||||
}
|
||||
|
||||
public Grille getGrille() {
|
||||
return grille;
|
||||
}
|
||||
|
||||
public void addResetListener(ActionListener l) {
|
||||
public void resetButton(ActionListener l) {
|
||||
this.reset.addActionListener(l);
|
||||
}
|
||||
|
||||
public void changeLabel(int joueur) {
|
||||
switch(joueur){
|
||||
case Constants.PLAYER_ONE:
|
||||
this.label.setText("Tour Joueur 1");
|
||||
this.label.setText("Tour de : " + this.playerOneName);
|
||||
break;
|
||||
|
||||
case Constants.PLAYER_TWO:
|
||||
this.label.setText("Tour Joueur 2");
|
||||
this.label.setText("Tour de : " + this.playerTwoName);
|
||||
break;
|
||||
|
||||
default:
|
||||
this.label.setText("TOUR JOUEUR INCONNU");
|
||||
this.label.setText("JOUEUR INCONNU");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -127,11 +137,12 @@ public class Puissance4Panel extends JPanel{
|
||||
this.grille.addPlayerPiece(column, row, player);
|
||||
}
|
||||
|
||||
public void setGameStatus(GameStatus status, int playerTurn) {
|
||||
public void setGameStatus(GameStatus status, int playerTurn, int playerOneScore, int playerTwoScore) {
|
||||
this.grille.hover(-1, playerTurn);
|
||||
switch(status){
|
||||
case STOP:
|
||||
this.label.setText("Victoire du joueur " + playerTurn);
|
||||
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);
|
||||
break;
|
||||
|
||||
case DRAW:
|
||||
|
Loading…
Reference in New Issue
Block a user