CS 1713 Week 10:
A Design Example
Tic Tac Toe Tracing Rules
GameInterface
public boolean move(int row, int col);
public void startGame();
public char[][] getBoard();
public char joinGame(UserInterface user);
public char getWinner();
UserInterface
public int[] getMove();
public void setBoard(char[][] board);
Game Constructor:
public Game(int boardsize);
User Constructor:
public User(GameInterface game);
Tic Tac Toe Tracing Demonstration:
One student is the Game (implements GameInterface)
Two students are Users, each implements UserInterface.
The driver program is run:
public static void main(String[] args) {
GameInterface game = new Game(3);
new User(game);
new User(game);
game.startGame();
}
Rules:
- Each object keeps track of its attributes on the whiteboard.
- We assume that only that object can see these attributes.
- Action can only take place in response to a method call.
- You call a method by writing the name of the method and the parameters
on an index card, and giving it to the person simulating that object.
- When you receive a card, tell the class what is on the card.
You may call any private methods, or public methods of objects
you know about. Write the return value on the card and return it.
- After you make a method call which has a return value, you cannot take
any action until you receive the returned value. Tell the class what the
return value is when you get it.