-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetXO
More file actions
62 lines (55 loc) · 1.58 KB
/
setXO
File metadata and controls
62 lines (55 loc) · 1.58 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
setXO = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
JButton button = (JButton) event.getSource();
if (count % 2 == 0) {
player1 = "X";
player2 = "O";
boolean check = false;
for (int i = 0; i < oSpots.size(); i++) {
for (int j = 0; j < xSpots.size(); j++) {
int convertbutton = Integer.parseInt(button
.getName());
if (oSpots.get(i) == convertbutton
|| xSpots.get(j) == convertbutton) {
check = true;
}
}
}
if (!check) {
count++;
button.setText("X");
UIManager.put("Button.font",
new javax.swing.plaf.FontUIResource(
"Century Gothic", Font.BOLD, 30));
xSpots.add(Integer.parseInt(button.getName()));
System.out.println(winOrLose(xSpots));
} else {
System.out.println("Spot already taken!");
}
} else {
boolean check = false;
for (int i = 0; i < xSpots.size(); i++) {
for (int j = 0; j < oSpots.size(); j++) {
int convertbutton = Integer.parseInt(button
.getName());
if (xSpots.get(i) == convertbutton
|| oSpots.get(j) == convertbutton) {
check = true;
}
}
}
if (!check) {
count++;
button.setText("O");
UIManager.put("Button.font",
new javax.swing.plaf.FontUIResource(
"Century Gothic", Font.BOLD, 30));
oSpots.add(Integer.parseInt(button.getName()));
System.out.println(winOrLose(oSpots));
} else {
System.out.println("Spot already taken!");
}
}
}
};