From 6672ba61ffe46d741fe720ba5b8fcb7bf137dc5a Mon Sep 17 00:00:00 2001 From: Justine Yannis Date: Fri, 11 Nov 2022 20:06:41 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20bug=20:=20mauvais=20comptage=20des=20poin?= =?UTF-8?q?ts=20(ajout=20de=20point=20dans=20la=20fonction=20verifyWin=20s?= =?UTF-8?q?upprim=C3=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Puissance4/Model/GrilleModel.java | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/projetAgile/src/fr/iutfbleau/projetAgile/Puissance4/Model/GrilleModel.java b/projetAgile/src/fr/iutfbleau/projetAgile/Puissance4/Model/GrilleModel.java index e873792..6c4e492 100644 --- a/projetAgile/src/fr/iutfbleau/projetAgile/Puissance4/Model/GrilleModel.java +++ b/projetAgile/src/fr/iutfbleau/projetAgile/Puissance4/Model/GrilleModel.java @@ -81,9 +81,15 @@ public class GrilleModel extends AbstractGridInitiater{ for (int row = this.row - 1; row >= 0; row--) { if (grille[column][row] == Constants.EMPTY_PLAYER) { this.addPiece(column, row); - if(!this.verifyWin(column, row, this.playerTurn)){ - this.switchPlayer(); + if(this.verifyWin(column, row, this.playerTurn)){ + if(this.playersList.size() > 2){ + this.removePlayer(); + } else{ + this.setPartyStatus(GameStatus.WIN); + } + return; } + this.switchPlayer(); this.verifyDraw(); return; } @@ -101,14 +107,14 @@ public class GrilleModel extends AbstractGridInitiater{ private void verifyNewWin() { int firstLastPlayer = this.playersList.get(0); - int seconfLastPlayer = this.playersList.get(1); + int secondLastPlayer = this.playersList.get(1); boolean verifyFirstWin = this.verifyWinAll(firstLastPlayer); - boolean verifySecondWin = this.verifyWinAll(seconfLastPlayer); + boolean verifySecondWin = this.verifyWinAll(secondLastPlayer); if(verifyFirstWin && verifySecondWin) { this.setPartyStatus(GameStatus.DRAW); } else if(verifyFirstWin || verifySecondWin) { - this.playerTurn = verifyFirstWin ? firstLastPlayer : seconfLastPlayer; + this.playerTurn = verifyFirstWin ? firstLastPlayer : secondLastPlayer; this.setPartyStatus(GameStatus.WIN); } } @@ -135,11 +141,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)) { - if(this.playersList.size()==3){ - this.removePlayer(); - }else{ - this.setPartyStatus(GameStatus.WIN); - } + return true; } @@ -149,11 +151,7 @@ public class GrilleModel extends AbstractGridInitiater{ } //Vérification diagonale haut à gauche -> bas à droite if(verifyAlignedPiece(diagonalColumn, diagonalRow, 1, 1, playerColor)) { - if(this.playersList.size() > 2){ - this.removePlayer(); - }else{ - this.setPartyStatus(GameStatus.WIN); - } + return true; } @@ -166,11 +164,7 @@ public class GrilleModel extends AbstractGridInitiater{ //Vérification diagonale haut à droite -> bas à gauche if(verifyAlignedPiece(diagonalColumn, diagonalRow, -1, 1, playerColor)) { - if(this.playersList.size() > 2){ - this.removePlayer(); - }else{ - this.setPartyStatus(GameStatus.WIN); - } + return true; } return false;