-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicTacToe.java
More file actions
93 lines (71 loc) · 1.92 KB
/
Copy pathTicTacToe.java
File metadata and controls
93 lines (71 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.util.*;
/*
Tic Tac Toe
This is a terminal game for two users. User need to input row number and
column number to make a draw. Both are within range [1-3]
When the game starts, it's user1's turn,
1 2 3
----------
1 | | | |
----------
2 | | | |
----------
3 | | | |
----------
For example, user1 can input
row:2
column:3, to make a draw as following
1 2 3
----------
1 | | | |
----------
2 | | | X|
----------
3 | | | |
----------
Now it come to user2's turn. If user2 wants to make a draw at
row:3
column:1, the board will be changed as following:
1 2 3
----------
1 | | | |
----------
2 | | | X|
----------
3 | O| | |
----------
Several warnings:
1. Users can't make a draw at the cell where it is already occupied
2. Users must enter a number within range 1 to 3. Any other characters
such as ./#$%^&FGZsefef will reprompt the instructions.
*/
public class TicTacToe{
private final static String gameStatement= "(N)ew Game (Q)uit";
public static void main(String []args){
Board myBoard = new Board();
Game myGame = new Game(myBoard);
myGame.play();
gameOver();
}
/*
Method to handle the case when the game is over (Either a Tie
or there's a winner). The user can choose either quit the
game or start a new game.
Args: None
Returns: None
*/
public static void gameOver() {
while (true) {
System.out.println(gameStatement);
Scanner scr = new Scanner (System.in);
String userInstr= scr.nextLine();
if(userInstr.equals("N")) {
Game newGame = new Game(new Board());
newGame.play();
}
else if (userInstr.equals("Q")) {
System.exit(0);
}
}
}
}