Java Reference
In-Depth Information
12 Scanner in =
new
Scanner(System.in);
13 String player =
"x"
;
14 TicTacToe game =
new
TicTacToe();
15 boolean done =
false
;
16
while
(!done)
17 {
18 System.out.print(game.toString());
19 System.out.print(
20
"Row for "
+ player +
" (-1 to
exit): "
);
21
int
row = in.nextInt();
22
if
(row <
0
) done =
true
;
23
else
24 {
25 System.out.print(
"Column for "
+
player +
": "
);
26
int
column = in.nextInt();
27 game.set(row, column, player);
28
if
(player.equals(
"x"
))
29 player =
"o"
;
30
else
31 player =
"x"
;
32 }
33 }
34 }
35 }
308
309
Output
| |
| |
| |
Row for x (-1 to exit):
1
Column for x:
2
| |
| x|
| |
Row for o (-1 to exit):
0
Column for o:
0
|o |
| x|
| |
Row for x (-1 to exit):
-1