Redoing players in the game.

Signed-off-by: Malte Tammena <malte.tammena@gmx.de>
This commit is contained in:
Malte Tammena 2017-10-15 13:12:31 +02:00
parent d7074f2a18
commit 049171749d
3 changed files with 17 additions and 12 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
doc/

View File

@ -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();
}
/**

View File

@ -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;