-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlay.java
More file actions
97 lines (66 loc) · 2.06 KB
/
Copy pathPlay.java
File metadata and controls
97 lines (66 loc) · 2.06 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
import java.util.Random;
import javax.swing.JOptionPane;
/**
*
* brief: Play tic tac toe game
*
*/
public class Play {
public static void play() {
String ans = JOptionPane.showInputDialog("I might be a while. Want to play ticktacktoe? Yes/no");
int i = -1;
Random rand = new Random();
int wrong = rand.nextInt(10);
while(ans.contains("no")) {
i++;
ReaderAndWriter.readSoundFile("no.wav");
if(i > wrong) {
//t.run();
ans = JOptionPane.showInputDialog("I might be a while. Want to play ticktacktoe? Yes/no");
//t.interrupt();
wrong = rand.nextInt(10);
}
}
if(ans.contains("yes")) {
Play.playGame();
}
}
public static void playGame()
{
// Create game and initialize it. First player will be 'x'
TicTacToe game = new TicTacToe();
// Print initial state of the board
game.printBoard();
// Play
int[] move = new int[2];
boolean playin = true;
while(playin) {
// Choose a move
System.out.println("Player " + game.getMark() + " turn!");
if ('x' == game.getMark()) {
game.movePlayer(move);
}
else {
game.moveAI(move);
}
// Make the move
if (!game.placeMark(move))
continue; // same player moves again if invalid move
// Print Board
game.printBoard();
// Do we have a winner ?!
if (game.checkForWin()) {
System.out.println("We have a winner! Congrats player " + game.getMark() + "!");
playin = false;
}
// It is a draw ?!
if (game.isBoardFull()) {
System.out.println("Appears we have a draw!");
playin = false;
}
// No winner or draw yet => switch players
game.changePlayer();
}
//return JOptionPane.showInputDialog("I might be a while. Want to play ticktacktoe again? Yes/no");
}
}