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

refactoring: rename

parent c9d700d4
......@@ -55,12 +55,12 @@ s * Initializes a JFrame in which we place the game
private Grid<GamePanel> clickablePanels;
private GameSupplier gameSupplier;
private boolean multiplayer;
private TwoPlayerGame helperGame;
private TwoPlayerGame game;
public MNKGameGUI(GameSupplier gameSupplier) {
this.gameSupplier = gameSupplier;
//initialize to default values
helperGame = new TwoPlayerGame(gameSupplier.getTicTacToeGame());
game = new TwoPlayerGame(gameSupplier.getTicTacToeGame());
}
/*
......@@ -80,8 +80,8 @@ s * Initializes a JFrame in which we place the game
}
}
private void reset(MNKGame game) {
this.helperGame = helperGame.getNewGame(game);
private void reset(MNKGame newGame) {
this.game = game.getNewGame(newGame);
updateMessage();
removeAll();
initialize();
......@@ -95,7 +95,7 @@ s * Initializes a JFrame in which we place the game
clickablePanels.forEach(item -> item.updateToGame());
updateMessage();
MNKGameGUI.super.updateUI();
if(!helperGame.hasPossibleMoves()) {
if(!game.hasPossibleMoves()) {
stop();
}
}
......@@ -104,10 +104,10 @@ s * Initializes a JFrame in which we place the game
* Helper method to control the status message
*/
private void updateMessage() {
if (helperGame.hasWinner())
statusMessage.setText("The game is over! The winner is " + helperGame.getWinner());
else if(helperGame.hasPossibleMoves()) {
statusMessage.setText("Next move from " + helperGame.getCurrentPlayer());
if (game.hasWinner())
statusMessage.setText("The game is over! The winner is " + game.getWinner());
else if(game.hasPossibleMoves()) {
statusMessage.setText("Next move from " + game.getCurrentPlayer());
}else{
statusMessage.setText("The game is over! No one won.");
}
......@@ -144,7 +144,7 @@ s * Initializes a JFrame in which we place the game
@Override
public Dimension getPreferredSize() {
return new Dimension(100*helperGame.height(), 100*helperGame.width());
return new Dimension(100*game.height(), 100*game.width());
}
/**
......@@ -171,7 +171,7 @@ s * Initializes a JFrame in which we place the game
}
private void updateToGame() {
setBackground(pieceToColor(helperGame.getPieceAt(x, y)));
setBackground(pieceToColor(game.getPieceAt(x, y)));
if(filled()) {
makeUnClickable();
}
......@@ -182,11 +182,11 @@ s * Initializes a JFrame in which we place the game
}
private boolean filled() {
return helperGame.getPieceAt(x, y) != Piece.NONE;
return game.getPieceAt(x, y) != Piece.NONE;
}
public void click() {
helperGame.takeTurnforHumanPlayer(x, y);
game.takeTurnforHumanPlayer(x, y);
endOfTurn();
}
......@@ -197,7 +197,7 @@ s * Initializes a JFrame in which we place the game
@Override
public Color getBackground() {
return pieceToColor(helperGame.getPieceAt(x, y));
return pieceToColor(game.getPieceAt(x, y));
}
}
......@@ -207,11 +207,11 @@ s * Initializes a JFrame in which we place the game
public void initialize() {
setLayout(new BorderLayout());
JPanel p = new JPanel();
p.setLayout(new GridLayout(helperGame.height(), helperGame.width()));
p.setLayout(new GridLayout(game.height(), game.width()));
p.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
this.clickablePanels = new Grid<GamePanel>(helperGame.width(), helperGame.height(), null);
for(int y = 0; y<helperGame.height(); y++) {
for (int x=0; x<helperGame.width(); x++) {
this.clickablePanels = new Grid<GamePanel>(game.width(), game.height(), null);
for(int y = 0; y<game.height(); y++) {
for (int x=0; x<game.width(); x++) {
GamePanel pan = new GamePanel(x, y);
pan.setEnabled(true);
pan.setBorder(BorderFactory.createLineBorder(Color.GRAY));
......@@ -245,7 +245,7 @@ s * Initializes a JFrame in which we place the game
playConnectFourButton.setText("Connect Four");
statusMessage = new JLabel();
statusMessage.setText("Welcome to this game! " + helperGame.player1() + " begins.");
statusMessage.setText("Welcome to this game! " + game.player1() + " begins.");
JPanel buttons = new JPanel();
buttons.setLayout(new BorderLayout());
......@@ -260,12 +260,12 @@ s * Initializes a JFrame in which we place the game
private void collectPlayerInfo() {
JFrame frame = new JFrame();
multiplayer = promptMultiplayer(frame);
helperGame.setHumanPlayer1(promptPlayerName(frame, "Player 1"));
game.setHumanPlayer1(promptPlayerName(frame, "Player 1"));
if(multiplayer) {
helperGame.setHumanPlayer2(promptPlayerName(frame, "Player 2"));
game.setHumanPlayer2(promptPlayerName(frame, "Player 2"));
}
else {
helperGame.setAIPlayer2();
game.setAIPlayer2();
}
}
......
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