Commit 871f7443 authored by Stefano Cobelli's avatar Stefano Cobelli

buttons are disabled when relevant

All thats left is ai player
parent 8ffc004b
......@@ -72,7 +72,11 @@ public class TTTController implements ActionListener {
}
}
this.aiGuy = new AIPlayer(theGame.getBoard(), Mark.O);
this.controlPanel.getNewGameButton().addActionListener(this);
this.controlPanel.getTrainAIButton().addActionListener(this);
this.playerPanel.getGameModeComboBox().addActionListener(this);
this.playerPanel.getaIComboBox().addActionListener(this);
newGame();
}
/*
......@@ -112,6 +116,27 @@ public class TTTController implements ActionListener {
aiGames.switchTurn();
}
}
// handles the statuses of the buttons availability
} else if (e.getSource() == playerPanel.getGameModeComboBox()
|| e.getSource() == playerPanel.getaIComboBox()) {
newGame();
if (playerPanel.getGameModeComboBox().getSelectedItem()
.equals("Player vs. Computer")) {
playerPanel.getaIComboBox().setEnabled(true);
if (playerPanel.getaIComboBox().getSelectedItem()
.equals("AI Player")) {
controlPanel.getTrainAIButton().setEnabled(true);
controlPanel.getTrainNumberField().setEnabled(true);
} else {
controlPanel.getTrainAIButton().setEnabled(false);
controlPanel.getTrainNumberField().setEnabled(false);
}
} else {
playerPanel.getaIComboBox().setEnabled(false);
controlPanel.getTrainAIButton().setEnabled(false);
controlPanel.getTrainNumberField().setEnabled(false);
}
}
// checks all grid buttons if it's the source
else {
......
......@@ -32,6 +32,8 @@ public class TTTControlPanel extends JPanel {
this.trainAIButton = new JButton("Train AI");
this.trainNumberField = new JTextField("10000");
String[] gameModeOptions = { "Player vs. Computer", "Player vs. Player" };
this.trainAIButton.setEnabled(false);
this.trainNumberField.setEnabled(false);
this.add(this.newGameButton);
this.add(this.trainAIButton);
this.add(this.trainNumberField);
......
......@@ -27,8 +27,9 @@ public class TTTPlayerPanel extends JPanel {
private static final long serialVersionUID = 1L;
private JComboBox gameModeComboBox;
private JComboBox aIComboBox;
private String[] gameModeOptions = { "Player vs. Computer", "Player vs. Player" };
private String[] aIOptions = { "Random", "Blocker", "AI Player" };
private String[] gameModeOptions = { "Player vs. Player",
"Player vs. Computer" };
private String[] aIOptions = { "Random", "Blocker", "AI Player" };
public TTTPlayerPanel() {
this.setLayout(new GridLayout(2, 2, 5, 5));
......@@ -38,6 +39,7 @@ public class TTTPlayerPanel extends JPanel {
JLabel aIText = new JLabel("Computer Player:", SwingConstants.CENTER);
this.gameModeComboBox = new JComboBox(gameModeOptions);
this.aIComboBox = new JComboBox(aIOptions);
this.aIComboBox.setEnabled(false);
this.add(gameModeText);
this.add(gameModeComboBox);
this.add(aIText);
......@@ -57,7 +59,7 @@ public class TTTPlayerPanel extends JPanel {
public JComboBox getaIComboBox() {
return aIComboBox;
}
public String[] getGameModeOptions() {
return gameModeOptions;
}
......
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