TIC TAC TOE - Seattle CoderDojo

TIC TAC TOE
1
Developing a simple game in Java
RECAP
Name of the file and name of the public java class
Class object = new Class(properties);
MyProgram.java => public class MyProgram
JButton myButton = new JButton(“OK”);
object.function(parameters);
myButton.setText(“Not OK”);
2
Created for Seattle CoderDojo 2015
RECAP (2)
Inheritance
class DrawingArea extends JPanel
Event Driven programming
myButton.addMouseListener(myButton)
3
Created for Seattle CoderDojo 2015
BUILDING BLOCKS FOR TIC TAC TOE
Draw a Grid
Listen to the mouse clicks
Determine the winner
4
Created for Seattle CoderDojo 2015
DRAW A GRID
5
Created for Seattle CoderDojo 2015
LISTEN TO MOUSE CLICKS
6
Created for Seattle CoderDojo 2015
DETERMINE THE WINNER
7
Created for Seattle CoderDojo 2015
DRAW A GRID
Draw lines
Draw boxes
Draw rectangles
Add Labels
Add Buttons
8
Created for Seattle CoderDojo 2015
LISTEN TO MOUSE CLICKS
Add mouse listener to the component (panel /
label / button)
Implement mouseClicked() function
Change appearance ( O or X) based on player
9
Created for Seattle CoderDojo 2015
DETERMINE THE WINNER
Know the winning patterns
0
1
2
3
4
5
6
7
8
10
Created for Seattle CoderDojo 2015