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
private JLabel statusMessage;
private Grid<GamePanel> clickablePanels;
private GameSupplier gameSupplier;
private TwoPlayerGame game;
private TwoPlayerGame<MNKGame> game;
public MNKGameGUI(GameSupplier gameSupplier) {
this.gameSupplier = gameSupplier;
//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;
* @author Anna Eilertsen - anna.eilertsen@uib.no
*
*/
public class TwoPlayerGame {
public class TwoPlayerGame<T extends MNKGame> {
private Player p1, p2;
private MNKGame game;
private T game;
private Player currentPlayer;
public TwoPlayerGame() {
}
public TwoPlayerGame(MNKGame game) {
public TwoPlayerGame(T game) {
this.game = game;
}
public TwoPlayerGame(MNKGame game, Player player1, Player player2) {
public TwoPlayerGame(T game, Player player1, Player player2) {
this.p1 = player1;
this.p2 = player2;
this.game = game;
initializeCurrentPlayer();
}
public void setGame(MNKGame game) {
public void setGame(T game) {
if(game!=null) {
throw new IllegalStateException("Game is already initialized");
}
......@@ -45,21 +45,21 @@ public class TwoPlayerGame {
if(p1!=null) {
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) {
if(p2!=null) {
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() {
if(p2!=null) {
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() {
......@@ -148,8 +148,8 @@ public class TwoPlayerGame {
currentPlayer = next();
}
public TwoPlayerGame getNewGame(MNKGame game) {
return new TwoPlayerGame(game, p1, p2);
public TwoPlayerGame<T> getNewGame(T game) {
return new TwoPlayerGame<T>(game, p1, p2);
}
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