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