-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicTacToe.java
More file actions
134 lines (77 loc) · 1.9 KB
/
Copy pathTicTacToe.java
File metadata and controls
134 lines (77 loc) · 1.9 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
public class TicTacToe {
public static void main (Strin[] args) {
char[][] = { {' ',' ',' '},
{' ',' ',' '},
{' ',' ',' '}}
Scanner input = new Scanner(System.in);
System.out.println("Where would you play? (1-9)")
Syting userInput = input.nextLine();
Rander rand = new Random;
int computerPlay - rand.nextInt(9)+ 1;
while(true) {
int computerMove = rand.nextInt(9) + 1;
if (isValidMove(board, computerPlay)) {
private static void boolean isValidMove(char [] [] board,int position) {
Switch(position) {
case "1":
return (board[0][0] == '' );
case "2":
return (board[0][1] == ' ');
case "3":
return (board[0][2] == ' ');
case "4":
return (board[1][0] == ' ');
case "5":
return (board[01][1] = ' ');
case "6":
return (board[1][2] = ' ');
case "7":
return (board[2][1] = ' ');
case "8":
return (board[2][1] = ' ');
case "9":
return (board[2][2] = ' ');
default:
return false;
private static void playerTurn (char [] [] board,Scanner input) {
System.out.println ("where where would you like to play? (1-9);
String userInput = scanner.nextLine();
Switch(userInput) {
case "1":
board[0][0] = 'X';
break;
case "2":
board[0][1] = 'X';
break;
case "3":
board[0][2] = 'X';
break;
case "4":
board[1][0] = 'X';
break;
case "5":
board[01][1] = 'X';
break;
case "6":
board[1][2] = 'X';
break;
case "7":
board[2][1] = 'X';
break;
case "8":
board[2][1] = 'X';
break;
case "9":
board[2][2] = 'X';
break;
default:
System.out.print(*:(*);
}
}
System.out.println(board[0][0] + "|" + board[0][1]+ "|" +board[0][2]
System.out.println("-+-+-");
System.out.println(board[1][0] + "|" + board[1][1]+ "|" +board[1][2]
System.out.println("-+-+-");
System.out.println(board[2][0] + "|" + board[1][1]+ "|" +board[1][2]
}
}