-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.java
70 lines (56 loc) · 1.62 KB
/
game.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
class game
{
int buttonarr[] = new int[9];
int numberOfClicks = 0;
public void setClick(int position, int value)
{
buttonarr[position]= value;
numberOfClicks++;
}
public void resetClick()
{
numberOfClicks = 0;
for(int position = 0; position<9; position++)
{
buttonarr[position]= 0;
}
}
public int getResult()
{
if (buttonarr[0]==1 && buttonarr[1]==1 && buttonarr[2]==1)
return 1;
if (buttonarr[0]==2 && buttonarr[1]==2 && buttonarr[2]==2)
return 2;
if (buttonarr[3]==1 && buttonarr[4]==1 && buttonarr[5]==1)
return 1;
if (buttonarr[3]==2 && buttonarr[4]==2 && buttonarr[5]==2)
return 2;
if (buttonarr[6]==1 && buttonarr[7]==1 && buttonarr[8]==1)
return 1;
if (buttonarr[6]==2 && buttonarr[7]==2 && buttonarr[8]==2)
return 2;
if (buttonarr[0]==1 && buttonarr[3]==1 && buttonarr[6]==1)
return 1;
if (buttonarr[0]==2 && buttonarr[3]==2 && buttonarr[6]==2)
return 2;
if (buttonarr[1]==1 && buttonarr[4]==1 && buttonarr[7]==1)
return 1;
if (buttonarr[1]==2 && buttonarr[4]==2 && buttonarr[7]==2)
return 2;
if (buttonarr[2]==1 && buttonarr[5]==1 && buttonarr[8]==1)
return 1;
if (buttonarr[2]==2 && buttonarr[5]==2 && buttonarr[8]==2)
return 2;
if (buttonarr[0]==1 && buttonarr[4]==1 && buttonarr[8]==1)
return 1;
if (buttonarr[0]==2 && buttonarr[4]==2 && buttonarr[8]==2)
return 2;
if (buttonarr[2]==1 && buttonarr[4]==1 && buttonarr[6]==1)
return 1;
if (buttonarr[2]==2 && buttonarr[4]==2 && buttonarr[6]==2)
return 2;
if (numberOfClicks==9)
return 3;
return 0;
}
}