Commit b6925aa9 authored by Anna Maria Eilertsen's avatar Anna Maria Eilertsen
Browse files

renamed methods for consistency

parent 91005af4
...@@ -77,7 +77,7 @@ s * Initializes a JFrame in which we place the game ...@@ -77,7 +77,7 @@ s * Initializes a JFrame in which we place the game
} }
private void reset(MNKGame newGame) { private void reset(MNKGame newGame) {
this.game = game.getNewGame(newGame); this.game = game.newGame(newGame);
updateMessage(); updateMessage();
removeAll(); removeAll();
initialize(); initialize();
...@@ -101,9 +101,9 @@ s * Initializes a JFrame in which we place the game ...@@ -101,9 +101,9 @@ s * Initializes a JFrame in which we place the game
*/ */
private void updateMessage() { private void updateMessage() {
if (game.hasWinner()) if (game.hasWinner())
statusMessage.setText("The game is over! The winner is " + game.getWinner()); statusMessage.setText("The game is over! The winner is " + game.winner());
else if(game.hasPossibleMoves()) { else if(game.hasPossibleMoves()) {
statusMessage.setText("Next move from " + game.getCurrentPlayer()); statusMessage.setText("Next move from " + game.currentPlayer());
}else{ }else{
statusMessage.setText("The game is over! No one won."); statusMessage.setText("The game is over! No one won.");
} }
...@@ -192,7 +192,7 @@ s * Initializes a JFrame in which we place the game ...@@ -192,7 +192,7 @@ s * Initializes a JFrame in which we place the game
@Override @Override
public Color getBackground() { public Color getBackground() {
return pieceToColor(game.getPieceAt(x, y)); return pieceToColor(game.pieceAt(x, y));
} }
} }
......
...@@ -80,11 +80,11 @@ public class TwoPlayerGame<T extends MNKGame> { ...@@ -80,11 +80,11 @@ public class TwoPlayerGame<T extends MNKGame> {
return p1.name(); return p1.name();
} }
public String getPlayer2() { public String player2() {
return p2.name(); return p2.name();
} }
public String getCurrentPlayer() { public String currentPlayer() {
return currentPlayer.name(); return currentPlayer.name();
} }
...@@ -92,19 +92,23 @@ public class TwoPlayerGame<T extends MNKGame> { ...@@ -92,19 +92,23 @@ public class TwoPlayerGame<T extends MNKGame> {
return game.hasWinner(); return game.hasWinner();
} }
public String getWinner() { public String winner() {
return getPlayerFromPiece(game.getWinner()); return playerFromPiece(game.getWinner());
} }
public boolean hasPossibleMoves() { public boolean hasPossibleMoves() {
return !game.hasWinner() && game.hasPossibleMoves(); return !game.hasWinner() && game.hasPossibleMoves();
} }
public Piece getPieceAt(int x, int y) { public Piece pieceAt(int x, int y) {
return game.getPieceAt(x, y); return game.getPieceAt(x, y);
} }
public String getPlayerFromPiece(Piece piece) { public boolean hasPieceAt(int x, int y) {
return game.getPieceAt(x, y) != Piece.NONE;
}
public String playerFromPiece(Piece piece) {
if(piece.equals(Piece.NONE)) if(piece.equals(Piece.NONE))
return "No Player"; return "No Player";
if(p1.getColor()==piece) if(p1.getColor()==piece)
...@@ -148,11 +152,8 @@ public class TwoPlayerGame<T extends MNKGame> { ...@@ -148,11 +152,8 @@ public class TwoPlayerGame<T extends MNKGame> {
currentPlayer = next(); currentPlayer = next();
} }
public TwoPlayerGame<T> getNewGame(T game) { public TwoPlayerGame<T> newGame(T game) {
return new TwoPlayerGame<T>(game, p1, p2); return new TwoPlayerGame<T>(game, p1, p2);
} }
public boolean hasPieceAt(int x, int y) {
return game.getPieceAt(x, y) != Piece.NONE;
}
} }
Supports Markdown
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