Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stefano Cobelli
205_hw02
Commits
87720509
Commit
87720509
authored
Nov 11, 2014
by
Stefano Cobelli
Browse files
Started Controller fixing for ai setup
Started train ai in game added getters of new panels
parent
b76ae08d
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/controller/TTTController.java
View file @
87720509
...
...
@@ -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
])
{
...
...
src/model/Game.java
View file @
87720509
...
...
@@ -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
*/
...
...
src/view/TTTMainView.java
View file @
87720509
...
...
@@ -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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment