Commit 91005af4 authored by Anna Maria Eilertsen's avatar Anna Maria Eilertsen
Browse files

made generic

parent ca4cf17d
...@@ -51,12 +51,12 @@ s * Initializes a JFrame in which we place the game ...@@ -51,12 +51,12 @@ s * Initializes a JFrame in which we place the game
private JLabel statusMessage; private JLabel statusMessage;
private Grid<GamePanel> clickablePanels; private Grid<GamePanel> clickablePanels;
private GameSupplier gameSupplier; private GameSupplier gameSupplier;
private TwoPlayerGame game; private TwoPlayerGame<MNKGame> game;
public MNKGameGUI(GameSupplier gameSupplier) { public MNKGameGUI(GameSupplier gameSupplier) {
this.gameSupplier = gameSupplier; this.gameSupplier = gameSupplier;
//initialize to default values //initialize to default values
game = new TwoPlayerGame(gameSupplier.getTicTacToeGame()); game = new TwoPlayerGame<>(gameSupplier.getTicTacToeGame());
} }
/* /*
......
...@@ -15,26 +15,26 @@ import inf101.v20.sem2.mnkgames.player.AI.SimpleAIPlayer; ...@@ -15,26 +15,26 @@ import inf101.v20.sem2.mnkgames.player.AI.SimpleAIPlayer;
* @author Anna Eilertsen - anna.eilertsen@uib.no * @author Anna Eilertsen - anna.eilertsen@uib.no
* *
*/ */
public class TwoPlayerGame { public class TwoPlayerGame<T extends MNKGame> {
private Player p1, p2; private Player p1, p2;
private MNKGame game; private T game;
private Player currentPlayer; private Player currentPlayer;
public TwoPlayerGame() { public TwoPlayerGame() {
} }
public TwoPlayerGame(MNKGame game) { public TwoPlayerGame(T game) {
this.game = game; this.game = game;
} }
public TwoPlayerGame(MNKGame game, Player player1, Player player2) { public TwoPlayerGame(T game, Player player1, Player player2) {
this.p1 = player1; this.p1 = player1;
this.p2 = player2; this.p2 = player2;
this.game = game; this.game = game;
initializeCurrentPlayer(); initializeCurrentPlayer();
} }
public void setGame(MNKGame game) { public void setGame(T game) {
if(game!=null) { if(game!=null) {
throw new IllegalStateException("Game is already initialized"); throw new IllegalStateException("Game is already initialized");
} }
...@@ -45,21 +45,21 @@ public class TwoPlayerGame { ...@@ -45,21 +45,21 @@ public class TwoPlayerGame {
if(p1!=null) { if(p1!=null) {
throw new IllegalStateException("Player 1 is already initialized"); throw new IllegalStateException("Player 1 is already initialized");
} }
this.p1 = new HumanPlayer(name, MNKGame.getStartColor()); this.p1 = new HumanPlayer(name, T.getStartColor());
} }
public void setHumanPlayer2(String name) { public void setHumanPlayer2(String name) {
if(p2!=null) { if(p2!=null) {
throw new IllegalStateException("Player 2 is already initialized"); throw new IllegalStateException("Player 2 is already initialized");
} }
this.p2 = new HumanPlayer(name, MNKGame.getStartColor().next()); this.p2 = new HumanPlayer(name, T.getStartColor().next());
} }
public void setAIPlayer2() { public void setAIPlayer2() {
if(p2!=null) { if(p2!=null) {
throw new IllegalStateException("Player 2 is already initialized"); throw new IllegalStateException("Player 2 is already initialized");
} }
this.p2 = new SimpleAIPlayer(MNKGame.getStartColor().next()); this.p2 = new SimpleAIPlayer(T.getStartColor().next());
} }
private void initializeCurrentPlayer() { private void initializeCurrentPlayer() {
...@@ -148,8 +148,8 @@ public class TwoPlayerGame { ...@@ -148,8 +148,8 @@ public class TwoPlayerGame {
currentPlayer = next(); currentPlayer = next();
} }
public TwoPlayerGame getNewGame(MNKGame game) { public TwoPlayerGame<T> getNewGame(T game) {
return new TwoPlayerGame(game, p1, p2); return new TwoPlayerGame<T>(game, p1, p2);
} }
public boolean hasPieceAt(int x, int y) { public boolean hasPieceAt(int x, int y) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment