Commit 87720509 authored by Stefano Cobelli's avatar Stefano Cobelli

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;
import model.Board.State;
import model.Game;
import view.TTTBoardPanel;
import view.TTTControlPanel;
import view.TTTMainView;
import view.TTTPlayerPanel;
import view.TTTStatsPanel;
/**
......@@ -33,6 +35,10 @@ public class TTTController implements ActionListener {
private TTTStatsPanel statsPanel;
/** an instance of the board panel from the main veiw */
private TTTBoardPanel boardPanel;
private TTTControlPanel controlPanel;
private TTTPlayerPanel playerPanel;
/** */
/**
* Constructor that sets up the gui buttons as this's actionListener
......@@ -45,8 +51,10 @@ public class TTTController implements ActionListener {
public TTTController(Game theGame, TTTMainView theView) {
this.theGame = theGame;
this.theView = theView;
statsPanel = this.theView.getStatsPanel();
boardPanel = this.theView.getBoardPanel();
this.statsPanel = this.theView.getStatsPanel();
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 j = 0; j < boardPanel.getButtonBoard().length; j++) {
boardPanel.getButtonBoard()[i][j].addActionListener(this);
......@@ -64,6 +72,15 @@ public class TTTController implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
// 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 col = 0; col < boardPanel.getButtonBoard().length; col++) {
if (e.getSource() == boardPanel.getButtonBoard()[row][col]) {
......
......@@ -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
*/
......
......@@ -64,4 +64,18 @@ public class TTTMainView extends JFrame {
return statsPanel;
}
/**
* @return the playerPanel
*/
public TTTPlayerPanel getPlayerPanel() {
return playerPanel;
}
/**
* @return the controlPanel
*/
public TTTControlPanel getControlPanel() {
return controlPanel;
}
}
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