From be0540a879db436970adad02785e978198b5de76 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Sun, 15 Oct 2017 13:20:16 +0200 Subject: [PATCH] Added a player wrapper PlayerObject Signed-off-by: Malte Tammena --- Makefile | 1 + src/game/Game.java | 10 +++++----- src/game/PlayerObject.java | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/game/PlayerObject.java diff --git a/Makefile b/Makefile index 8523c36..2b202b4 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ LIBARIES= CLASSES=\ src/game/Main.java \ src/game/Game.java \ +src/game/PlayerObject.java \ src/player/Player.java \ src/player/Player1.java \ src/player/Player2.java diff --git a/src/game/Game.java b/src/game/Game.java index c4f80f3..85d2973 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -22,17 +22,17 @@ public class Game { /** * Player One */ - private final Player p1; + private final PlayerObject p1; /** * Player Two */ - private final Player p2; + private final PlayerObject p2; /** * Player who made the last move. */ - private Player lastPlayer; + private PlayerObject lastPlayer; /** * The game's board. @@ -56,8 +56,8 @@ public class Game { * @param p2 Player Two */ public Game(Player p1, Player p2) { - this.p1 = p1; - this.p2 = p2; + this.p1 = new PlayerObject(p1); + this.p2 = new PlayerObject(p2); this.board = new int [GAME_COLUMNS][GAME_ROWS]; this.gameOn = false; } diff --git a/src/game/PlayerObject.java b/src/game/PlayerObject.java new file mode 100644 index 0000000..fdd280a --- /dev/null +++ b/src/game/PlayerObject.java @@ -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; + } +}