Commit 877c8305 authored by Anna Maria Eilertsen's avatar Anna Maria Eilertsen
Browse files

improved docs + reordered methods

parent bc3d1743
......@@ -117,6 +117,19 @@ s * Initializes a JFrame in which we place the game
ai.makeMove(game);
endOfTurn();
}
/**
* Helper method to control the status message
*/
private void updateMessage() {
if (game.hasWinner())
statusMessage.setText("The game is over! The winner is " + getPlayerName(game.getWinner()));
else if(game.hasPossibleMoves()) {
statusMessage.setText("Next move from " + getPlayerName(game.getCurrent()));
}else{
statusMessage.setText("The game is over! No one won.");
}
}
/**
* Should be called once a game stops
......@@ -251,7 +264,10 @@ s * Initializes a JFrame in which we place the game
validate();
}
public JPanel createButtonPanel() {
/**
* Helper method that creates the button panel
*/
private JPanel createButtonPanel() {
playTicTacToeButton = new JButton();
playTicTacToeButton.addActionListener(this);
playTicTacToeButton.setText("Tic-Tac-Toe");
......@@ -269,18 +285,11 @@ s * Initializes a JFrame in which we place the game
buttons.add(playTicTacToeButton, BorderLayout.EAST);
return buttons;
}
private void updateMessage() {
if (game.hasWinner())
statusMessage.setText("The game is over! The winner is " + getPlayerName(game.getWinner()));
else if(game.hasPossibleMoves()) {
statusMessage.setText("Next move from " + getPlayerName(game.getCurrent()));
}else{
statusMessage.setText("The game is over! No one won.");
}
}
public void collectPlayerInfo() {
/**
* Helper method to collect player info
*/
private void collectPlayerInfo() {
JFrame frame = new JFrame();
multiplayer = promptMultiplayer(frame);
player1_screenName = promptPlayerName(frame, "Player 1");
......@@ -292,7 +301,11 @@ s * Initializes a JFrame in which we place the game
}
}
public String promptPlayerName(JFrame frame, String player) {
/**
* Helper method that prompts for player name
* @param player the name of the player that will be used in the prompt dialog
*/
private String promptPlayerName(JFrame frame, String player) {
String name = (String)JOptionPane.showInputDialog(
frame,
"Welcome " + player + ":\n"
......@@ -309,6 +322,10 @@ s * Initializes a JFrame in which we place the game
return name;
}
/**
* Helper method that prompts for multiplayer or not
* @return true if multiplayer is selected, false otherwise
*/
private boolean promptMultiplayer(JFrame frame) {
Object[] possibilities = {"Multiplayer", "Single Player (against AI)"};
String s = (String)JOptionPane.showInputDialog(
......
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