-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
133 lines (124 loc) · 4.95 KB
/
Controller.java
File metadata and controls
133 lines (124 loc) · 4.95 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//Controller class includes the actionperformed on button click
public class Controller implements ActionListener {
public final View newView;
public Controller(View newView) {
this.newView = newView;
}
public void actionPerformed(ActionEvent e){
//On each button click,setText on button,update state array,runs wincheck method and switch the player using count.
if((e.getSource()==View.b1)&&(Model.count%2==1)&&(Model.state[0][0]==0)&&(Model.win==0)){
View.b1.setText("1");
Model.state[0][0] = 1;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b1)&&(Model.count%2==0)&&(Model.state[0][0]==0)&&(Model.win==0)){
View.b1.setText("2");
Model.state[0][0] = 2;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b2)&&(Model.count%2==1)&&(Model.state[0][1]==0)&&(Model.win==0)) {
View.b2.setText("1");
Model.state[0][1] = 1;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b2)&&(Model.count%2==0)&&(Model.state[0][1]==0)&&(Model.win==0)){
View.b2.setText("2");
Model.state[0][1] = 2;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b3)&&(Model.count%2==1)&&(Model.state[0][2]==0)){
View.b3.setText("1");
Model.state[0][2]=1;
Model.wincheck( Model.state);
Model.count++;
}
else if((e.getSource()==View.b3)&&(Model.count%2==0)&&(Model.state[0][2]==0)&&(Model.win==0)){
View.b3.setText("2");
Model.state[0][2]=2;
Model.wincheck( Model.state);
Model.count++;
}
else if((e.getSource()==View.b4)&&( Model.count%2==1)&&( Model.state[1][0]==0)&&( Model.win==0)){
View.b4.setText("1");
Model.state[1][0]=1;
Model.wincheck( Model.state);
Model.wincheck( Model.state);
Model.count++;
}
else if((e.getSource()==View.b4)&&(Model.count%2==0)&&(Model.state[1][0]==0)&&(Model.win==0)){
View.b4.setText("2");
Model.state[1][0]=2;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b5)&&(Model.count%2==1)&&(Model.state[1][1]==0)&&(Model.win==0)){
View.b5.setText("1");
Model.state[1][1]=1;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b5)&&(Model.count%2==0)&&(Model.state[1][1]==0)&&(Model.win==0)){
View.b5.setText("2");
Model.state[1][1]=2;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b6)&&(Model.count%2==1)&&(Model.state[1][2]==0)&&(Model.win==0)){
View.b6.setText("1");
Model.state[1][2]=1;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b6)&&(Model.count%2==0)&&(Model.state[1][2]==0)&&(Model.win==0)){
View.b6.setText("2");
Model.state[1][2]=2;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b7)&&(Model.count%2==1)&&(Model.state[2][0]==0)&&(Model.win==0)){
View.b7.setText("1");
Model.state[2][0]=1;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b7)&&(Model.count%2==0)&&(Model.state[2][0]==0)&&(Model.win==0)){
View.b7.setText("2");
Model.state[2][0]=2;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b8)&&(Model.count%2==1)&&(Model.state[2][1]==0)&&(Model.win==0)){
View.b8.setText("1");
Model.state[2][1]=1;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b8)&&(Model.count%2==0)&&(Model.state[2][1]==0)&&(Model.win==0)){
View.b8.setText("2");
Model.state[2][1]=2;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b9)&&(Model.count%2==1)&&(Model.state[2][2]==0)&&(Model.win==0)){
View.b9.setText("1");
Model.state[2][2]=1;
Model.wincheck(Model.state);
Model.count++;
}
else if((e.getSource()==View.b9)&&(Model.count%2==0)&&(Model.state[2][2]==0)&&(Model.win==0)){
View.b9.setText("2");
Model.state[2][2]=2;
Model.wincheck(Model.state);
Model.count++;
}
else if(Model.win==1){
View.post(View.message);
}
}
}