-
Notifications
You must be signed in to change notification settings - Fork 0
/
TTTTest.java
85 lines (73 loc) · 2.88 KB
/
TTTTest.java
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
package TicTacToe;
import java.util.*;
public class TTTTest
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
String player1, player2;
int player1num;
String response = "n";
//instructions for the game
System.out.println("Hi! Welcome to TTT (Tic-Tac-Toe)!!");
do
{
TTT test = new TTT();
System.out.println("How to play: Please enter the number of the space you want to put your O's and X's in :)");
System.out.println("Have fun!");
System.out.println("----------------------------------------------------------------------------------------");
System.out.println("Please select the options below for Player 1:");
System.out.println("(1) \"O\"");
System.out.println("(2) \"X\"");
System.out.print("Enter the option (1 or 2): ");
int selection = scan.nextInt();
System.out.println("Thank you!");
if(selection==1)
{
player1 = "O";
player2 = "X";
}
else
{
player1 = "X";
player2 = "O";
}
for(int i = 0; i<4; i++)
{
//player 1
System.out.println("Player 1, please enter in the space (number) you want to put \""+player1+"\": ");
test.board();
player1num = scan.nextInt();
test.assign(player1num,player1);
System.out.println("Updated Board:");
System.out.println("==============");
test.board();
if(test.check()&&test.getPlayer().equals(player1))
{
System.out.println("Player 1 won!");
break;
}
//player 2
System.out.println("Player 2, please enter in the space (number) you want to put \""+player2+"\": ");
test.board();
player1num = scan.nextInt();
test.assign(player1num,player2);
System.out.println("Updated Board:");
System.out.println("==============");
test.board();
if(test.check()&&test.getPlayer().equals(player2))
{
System.out.println("Player 2 won!");
break;
}
}
if(!test.check())
{
System.out.println("Draw!");
}
System.out.println("Do you want to play again?(y/n)");
response = scan.next();
}while(response.equalsIgnoreCase("y"));
System.out.println("Thank you for playing :)");
}
}