diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a2e6bd4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +doc/ diff --git a/src/game/Game.java b/src/game/Game.java index 6f22892..c4f80f3 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -29,6 +29,11 @@ public class Game { */ private final Player p2; + /** + * Player who made the last move. + */ + private Player lastPlayer; + /** * The game's board. * It's size is GAME_COLUMNS * GAME_ROWS. @@ -46,6 +51,9 @@ public class Game { /** * Constructor. * Initialize board and save players. + * + * @param p1 Player One + * @param p2 Player Two */ public Game(Player p1, Player p2) { this.p1 = p1; @@ -68,16 +76,16 @@ public class Game { first = this.p2; second = this.p1; } - boolean turn = true; this.gameOn = true; while(gameOn) { - if(turn){ - makeMove(first,turn); + if(lastPlayer == second){ + lastPlayer = first; + makeMove(first); } else { - makeMove(second,turn); + lastPlayer = second; + makeMove(second); } if(gameOn) { - turn = !turn; logGame(); checkState(); } else { @@ -91,7 +99,7 @@ public class Game { /** * Calls a players functions to make a move. */ - private void makeMove(Player p, boolean turn) { + private void makeMove(Player p) { log(p.getName() + " makes a move!"); // Get a choice from the player, while only giving him a copy of the game. int choice = p.move(copyBoard()); @@ -108,11 +116,7 @@ public class Game { pos++; } // Change the board accordingly. - if(turn){ - this.board[choice][pos] = 1; - } else { - this.board[choice][pos] = 2; - } + this.board[choice][pos] = p.getNr(); } /** diff --git a/src/player/Player1.java b/src/player/Player1.java index f7ae56f..2c5f9c0 100644 --- a/src/player/Player1.java +++ b/src/player/Player1.java @@ -2,7 +2,7 @@ package player; import java.util.Random; -public class Player1 implements Player{ +public class Player1 implements Player { private String name; private Random ran;