-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXO_Game.java
More file actions
59 lines (49 loc) · 1.48 KB
/
Copy pathXO_Game.java
File metadata and controls
59 lines (49 loc) · 1.48 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
import java.util.Scanner;
public class XO_Game extends Game {
Scanner input = new Scanner(System.in);
XO_Game()
{
board = new XO_Board();
players = new XO_Player[2];
move = new _2DIndex();
turn = 0;
}
void play_game()
{
System.out.println("Hello in XO_GAME");
System.out.println("enter your name player1: ");
String name1 = input.nextLine();
System.out.println("enter your name player2: ");
String name2 = input.nextLine();
players[0] = new XO_Player(name1,'X');
players[1] = new XO_Player(name2,'O');
while (true)
{
board.display_board();
do {
players[turn].get_move(move);
}
while (!board.update_board(move.x, move.y, players[turn].symbol));
board.n_moves++;
if (board.is_winner(players[turn].get_symbol()))
{
board.display_board();
System.out.println("Game over. " + players[turn].get_name() + " Win!");
break;
}
else if(board.is_draw())
{
board.display_board();
System.out.println("Game over. Draw ");
break;
}
if(turn == 0){
turn = 1;
}
else
{
turn = 0;
}
}
}
}