From 3fe047f1bbcf289b6fa037a2b26ea8ef37a1f549 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Sat, 14 Oct 2017 23:31:31 +0200 Subject: [PATCH] Not a working state, implementing winning conditions Signed-off-by: Malte Tammena --- src/game/Game.java | 42 ++++++++++++++++++++++++++++++++++++----- src/player/Player1.java | 14 +++++++++----- src/player/Player2.java | 14 +++++++++----- 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/game/Game.java b/src/game/Game.java index 4f4db36..7412fd5 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -36,11 +36,6 @@ public class Game { */ private int[][] board; - /** - * Unplayed pieces in the game. - */ - private int piecesLeft; - /** * Is the game still running? */ @@ -81,6 +76,7 @@ public class Game { if(gameOn) { turn = !turn; logGame(); + checkState(); } else { System.out.println("*******************"); System.out.println("Thanks for Playing!"); @@ -114,6 +110,42 @@ public class Game { } } + private int crawl(int i, int j) { + int symbol = this.board[i][j]; + if (i > 0) { + if (j > 0) { + + } + } + } + + /** + * + */ + private void checkState() { + outer:for (int i = 0; i < this.board.length; i++) { + for (int j = 0; j < this.board[i].length; j++) { + if (crawl(i, j) >= 4) { + log("We have a winner!"); + break outer; + } + } + } + // --- CHECK DRAW --- + boolean draw = true; + outer:for (int i = 0; i < this.board.length; i++) { + for (int j = 0; j < this.board[i].length; j++) { + if (this.board[i][j] == 0) { + draw = false; + break outer; + } + } + } + if (draw) { + this.gameOn = false; + } + } + /** * Deep copies the board. * diff --git a/src/player/Player1.java b/src/player/Player1.java index 9a3d00b..f7ae56f 100644 --- a/src/player/Player1.java +++ b/src/player/Player1.java @@ -1,19 +1,23 @@ package player; +import java.util.Random; + public class Player1 implements Player{ + private String name; + private Random ran; public Player1(String name){ this.name = name; + this.ran = new Random(); } public int move(int[][] board){ - for(int i=0;i