1 |
import javax.swing.JOptionPane; |
2 |
|
3 |
/** |
4 |
This program tests the TicTacToe class by prompting the |
5 |
user to set positions on the board and printing out the |
6 |
result. |
7 |
*/ |
8 |
public class TicTacToeTest |
9 |
{ |
10 |
public static void main(String[] args) |
11 |
{ |
12 |
char player = 'x'; |
13 |
TicTacToe game = new TicTacToe(); |
14 |
while (true) |
15 |
{ |
16 |
System.out.println(game); // calls game.toString() |
17 |
String input = JOptionPane.showInputDialog( |
18 |
"Row for " + player + " (Cancel to exit)"); |
19 |
if (input == null) System.exit(0); |
20 |
int row = Integer.parseInt(input); |
21 |
input = JOptionPane.showInputDialog( |
22 |
"Column for " + player); |
23 |
int column = Integer.parseInt(input); |
24 |
game.set(row, column, player); |
25 |
if (player == 'x') player = 'o'; else player = 'x'; |
26 |
} |
27 |
} |
28 |
} |