Fixed check win

This commit is contained in:
Dorian Zedler 2020-02-22 11:02:10 +01:00
parent ac9e6fb34b
commit ef225e828b

View file

@ -97,7 +97,7 @@ public class GameBoard extends JPanel {
// if the container is empty -> add the plate // if the container is empty -> add the plate
this.BoardContainers[column][i].insertPlate(plate); this.BoardContainers[column][i].insertPlate(plate);
PlateType winCheckResult = this.checkContainerForWin(column, i); PlateType winCheckResult = this.checkForWin();
if (winCheckResult == null) if (winCheckResult == null)
return "ok"; return "ok";
@ -162,6 +162,25 @@ public class GameBoard extends JPanel {
return containerSize; return containerSize;
} }
/**
* Function to check if there is a chain of at least four plates of the same
* color anywhere on the board
*
* @return <code>null</code> if there was no matching chain; otherwise the
* PlateType of the chain that was found
*/
public PlateType checkForWin() {
for (int c = 0; c < this.boardColumns; c++) {
for (int r = 0; r < this.boardRows; r++) {
PlateType res = this.checkContainerForWin(c, r);
if (res != null)
return res;
}
}
return null;
}
/** /**
* Function to check if a certain container is the beginning of a four plate log * Function to check if a certain container is the beginning of a four plate log
* chain of plates of the same type what would indicate the end of the game. If * chain of plates of the same type what would indicate the end of the game. If
@ -169,8 +188,8 @@ public class GameBoard extends JPanel {
* *
* @param c column of the container to check * @param c column of the container to check
* @param r row of the container to check * @param r row of the container to check
* @return <code>null</code> if there was no matching chain or the PlateType of * @return <code>null</code> if there was no matching chain; otherwise the
* the chain * PlateType of the chain that was found
*/ */
public PlateType checkContainerForWin(int c, int r) { public PlateType checkContainerForWin(int c, int r) {