Commit 87720509 authored by Stefano Cobelli's avatar Stefano Cobelli
Browse files

Started Controller fixing for ai setup

Started train ai in game
added getters of new panels 
parent b76ae08d
...@@ -15,7 +15,9 @@ import javax.swing.JOptionPane; ...@@ -15,7 +15,9 @@ import javax.swing.JOptionPane;
import model.Board.State; import model.Board.State;
import model.Game; import model.Game;
import view.TTTBoardPanel; import view.TTTBoardPanel;
import view.TTTControlPanel;
import view.TTTMainView; import view.TTTMainView;
import view.TTTPlayerPanel;
import view.TTTStatsPanel; import view.TTTStatsPanel;
/** /**
...@@ -33,6 +35,10 @@ public class TTTController implements ActionListener { ...@@ -33,6 +35,10 @@ public class TTTController implements ActionListener {
private TTTStatsPanel statsPanel; private TTTStatsPanel statsPanel;
/** an instance of the board panel from the main veiw */ /** an instance of the board panel from the main veiw */
private TTTBoardPanel boardPanel; private TTTBoardPanel boardPanel;
private TTTControlPanel controlPanel;
private TTTPlayerPanel playerPanel;
/** */
/** /**
* Constructor that sets up the gui buttons as this's actionListener * Constructor that sets up the gui buttons as this's actionListener
...@@ -45,8 +51,10 @@ public class TTTController implements ActionListener { ...@@ -45,8 +51,10 @@ public class TTTController implements ActionListener {
public TTTController(Game theGame, TTTMainView theView) { public TTTController(Game theGame, TTTMainView theView) {
this.theGame = theGame; this.theGame = theGame;
this.theView = theView; this.theView = theView;
statsPanel = this.theView.getStatsPanel(); this.statsPanel = this.theView.getStatsPanel();
boardPanel = this.theView.getBoardPanel(); this.boardPanel = this.theView.getBoardPanel();
this.controlPanel = this.theView.getControlPanel();
this.playerPanel = this.theView.getPlayerPanel();
for (int i = 0; i < boardPanel.getButtonBoard().length; i++) { for (int i = 0; i < boardPanel.getButtonBoard().length; i++) {
for (int j = 0; j < boardPanel.getButtonBoard().length; j++) { for (int j = 0; j < boardPanel.getButtonBoard().length; j++) {
boardPanel.getButtonBoard()[i][j].addActionListener(this); boardPanel.getButtonBoard()[i][j].addActionListener(this);
...@@ -64,6 +72,15 @@ public class TTTController implements ActionListener { ...@@ -64,6 +72,15 @@ public class TTTController implements ActionListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// checks all the buttons if it's the source // checks all the buttons if it's the source
if (e.getSource() == controlPanel.getNewGameButton()) {
theGame.newGame();
clearGUI();
return;
}
if (e.getSource() == controlPanel.getTrainAIButton()) {
for (int i)
}
for (int row = 0; row < boardPanel.getButtonBoard().length; row++) { for (int row = 0; row < boardPanel.getButtonBoard().length; row++) {
for (int col = 0; col < boardPanel.getButtonBoard().length; col++) { for (int col = 0; col < boardPanel.getButtonBoard().length; col++) {
if (e.getSource() == boardPanel.getButtonBoard()[row][col]) { if (e.getSource() == boardPanel.getButtonBoard()[row][col]) {
......
...@@ -98,6 +98,16 @@ public class Game { ...@@ -98,6 +98,16 @@ public class Game {
} }
public void trainAI(int times) {
for (int i = 0; i < times; i++) {
while (isPlayable()) {
// random move
// ai move
}
}
}
/** /**
* main method * main method
*/ */
......
...@@ -64,4 +64,18 @@ public class TTTMainView extends JFrame { ...@@ -64,4 +64,18 @@ public class TTTMainView extends JFrame {
return statsPanel; return statsPanel;
} }
/**
* @return the playerPanel
*/
public TTTPlayerPanel getPlayerPanel() {
return playerPanel;
}
/**
* @return the controlPanel
*/
public TTTControlPanel getControlPanel() {
return controlPanel;
}
} }
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