Added a player wrapper PlayerObject
Signed-off-by: Malte Tammena <malte.tammena@gmx.de>
This commit is contained in:
parent
049171749d
commit
be0540a879
1
Makefile
1
Makefile
|
@ -13,6 +13,7 @@ LIBARIES=
|
||||||
CLASSES=\
|
CLASSES=\
|
||||||
src/game/Main.java \
|
src/game/Main.java \
|
||||||
src/game/Game.java \
|
src/game/Game.java \
|
||||||
|
src/game/PlayerObject.java \
|
||||||
src/player/Player.java \
|
src/player/Player.java \
|
||||||
src/player/Player1.java \
|
src/player/Player1.java \
|
||||||
src/player/Player2.java
|
src/player/Player2.java
|
||||||
|
|
|
@ -22,17 +22,17 @@ public class Game {
|
||||||
/**
|
/**
|
||||||
* Player One
|
* Player One
|
||||||
*/
|
*/
|
||||||
private final Player p1;
|
private final PlayerObject p1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player Two
|
* Player Two
|
||||||
*/
|
*/
|
||||||
private final Player p2;
|
private final PlayerObject p2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player who made the last move.
|
* Player who made the last move.
|
||||||
*/
|
*/
|
||||||
private Player lastPlayer;
|
private PlayerObject lastPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The game's board.
|
* The game's board.
|
||||||
|
@ -56,8 +56,8 @@ public class Game {
|
||||||
* @param p2 Player Two
|
* @param p2 Player Two
|
||||||
*/
|
*/
|
||||||
public Game(Player p1, Player p2) {
|
public Game(Player p1, Player p2) {
|
||||||
this.p1 = p1;
|
this.p1 = new PlayerObject(p1);
|
||||||
this.p2 = p2;
|
this.p2 = new PlayerObject(p2);
|
||||||
this.board = new int [GAME_COLUMNS][GAME_ROWS];
|
this.board = new int [GAME_COLUMNS][GAME_ROWS];
|
||||||
this.gameOn = false;
|
this.gameOn = false;
|
||||||
}
|
}
|
||||||
|
|
40
src/game/PlayerObject.java
Normal file
40
src/game/PlayerObject.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for the player.
|
||||||
|
* This is a wrapper for a player. This guarantees, that no
|
||||||
|
* player will change his Symbol, nor his id.
|
||||||
|
*/
|
||||||
|
public class PlayerObject {
|
||||||
|
|
||||||
|
private final Player p;
|
||||||
|
private final int id;
|
||||||
|
private String sym;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a player.
|
||||||
|
*
|
||||||
|
* @param id The players id.
|
||||||
|
* @param p The player himself.
|
||||||
|
*/
|
||||||
|
public PlayerObject(int id, Player p) {
|
||||||
|
this.p = p;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSymbol(String sym) {
|
||||||
|
this.sym = sym;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSymbol() {
|
||||||
|
return this.sym;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getP() {
|
||||||
|
return this.p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getID() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue