-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathUseBombAction.java
328 lines (232 loc) · 8.43 KB
/
UseBombAction.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
package actionListener;
import house.Location;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import others.MainT;
import player.Player;
import basicFrame.BFrame;
public class UseBombAction implements ActionListener {
private BFrame basicFrame;
static Player[] player;
JTextField[] showPlayerInfo;
public UseBombAction(BFrame frame) {
this.basicFrame = frame;
}
public UseBombAction()
{
}
@Override
public void actionPerformed(ActionEvent e) {
ButtonDiceAction btnDA =new ButtonDiceAction();
int flag = btnDA.getFlag();
if(flag==1 && player[0].getState()!=3)
{
List<JButton> labelList = basicFrame.getButtonList();
if(player[0].getBomb()>0)
{
if((!MainT.isNumeric((basicFrame.getBombLocation().getText().trim()))))
{
JOptionPane.showMessageDialog(basicFrame.getFrame(), "请输入数字");
}
else if(Integer.parseInt(basicFrame.getBombLocation().getText().trim())>10)
{
JOptionPane.showMessageDialog(basicFrame.getFrame(), "请输入10以内的数字");
}
else
{
int loclab=Integer.parseInt(basicFrame.getBombLocation().getText().trim());//获得label中的String值并转化成int型
JOptionPane.showMessageDialog(null,basicFrame.getBombLocation().getText().trim()+player[0].getPlayerName());
int locply= player[0].getLocation();//获得当前玩家的地址值
Location loc3 = MainT.markLocation.get(locply+loclab);//获得要安置炸弹的位置的对象
if(loc3.getIsToolState()=="isBomb")//判断该位置的道具状态
{
JOptionPane.showMessageDialog(null, "此处有炸弹,不能添加炸弹!");
}
else if (loc3.getIsToolState()=="isRoadBlock")
{
JOptionPane.showMessageDialog(null, "此处有路障,不能添加炸弹!");
}
else if (loc3.getIsToolState()=="isForbid")
{
JOptionPane.showMessageDialog(null, "此处属于公共场所,不能添加炸弹!");
}
else
{
loc3.setIsToolState("isBomb");
int NumBomb = player[0].getBomb()-1;//获得玩家的炸弹数
player[0].setBomb(NumBomb);//将玩家的炸弹数减一
labelList.get(loc3.getLocation()).setText("<html>"+"<br>"+" B "+"<html>");//表示该位置有炸弹,并换行
}
}
for(int i =0;i<70;i++) {
System.out.println(i + ":" + MainT.markLocation.get(i).getIsHouseState() + "," + MainT.markLocation.get(i).getIsToolState());
}
}
else
{
JOptionPane.showMessageDialog(null, player[0].getPlayerName()+"没有炸弹!");
}
}
if(flag==2 && player[flag-1].getState()!=3)
{
List<JButton> labelList = basicFrame.getButtonList();
if(player[flag-1].getBomb()>0)
{
if((!MainT.isNumeric((basicFrame.getBombLocation().getText().trim()))))
{
JOptionPane.showMessageDialog(basicFrame.getFrame(), "请输入数字");
}
else if(Integer.parseInt(basicFrame.getBombLocation().getText().trim())>10)
{
JOptionPane.showMessageDialog(basicFrame.getFrame(), "请输入10以内的数字");
}
else
{
int loclab=Integer.parseInt(basicFrame.getBombLocation().getText().trim());//获得label中的String值并转化成int型
JOptionPane.showMessageDialog(null,basicFrame.getBombLocation().getText().trim()+player[flag-1].getPlayerName());
int locply= player[flag-1].getLocation();//获得当前玩家的地址值
Location loc3 = MainT.markLocation.get(locply+loclab);//获得要安置炸弹的位置的对象
if(loc3.getIsToolState()=="isBomb")//判断该位置的道具状态
{
JOptionPane.showMessageDialog(null, "此处有炸弹,不能添加炸弹!");
}
else if (loc3.getIsToolState()=="isRoadBlock")
{
JOptionPane.showMessageDialog(null, "此处有路障,不能添加炸弹!");
}
else if (loc3.getIsToolState()=="isForbid")
{
JOptionPane.showMessageDialog(null, "此处属于公共场所,不能添加炸弹!");
}
else
{
loc3.setIsToolState("isBomb");
int NumBomb = player[flag-1].getBomb()-1;//获得玩家的炸弹数
player[flag-1].setBomb(NumBomb);//将玩家的炸弹数减一
labelList.get(loc3.getLocation()).setText("<html>"+"<br>"+" B "+"<html>");//表示该位置有炸弹,并换行
}
}
}
else
{
JOptionPane.showMessageDialog(null, player[flag-1].getPlayerName()+"没有炸弹!");
}
}
if(player.length>=3) {
if(flag==3) {
if(player[flag-1].getState()!=3) {
List<JButton> labelList = basicFrame.getButtonList();
if(player[flag-1].getBomb()>0)
{
if((!MainT.isNumeric((basicFrame.getBombLocation().getText().trim()))))
{
JOptionPane.showMessageDialog(basicFrame.getFrame(), "请输入数字");
}
else if(Integer.parseInt(basicFrame.getBombLocation().getText().trim())>10)
{
JOptionPane.showMessageDialog(basicFrame.getFrame(), "请输入10以内的数字");
}
else
{
int loclab=Integer.parseInt(basicFrame.getBombLocation().getText().trim());//获得label中的String值并转化成int型
JOptionPane.showMessageDialog(null,basicFrame.getBombLocation().getText().trim()+player[flag-1].getPlayerName());
int locply= player[flag-1].getLocation();//获得当前玩家的地址值
Location loc3 = MainT.markLocation.get(locply+loclab);//获得要安置炸弹的位置的对象
if(loc3.getIsToolState()=="isBomb")//判断该位置的道具状态
{
JOptionPane.showMessageDialog(null, "此处有炸弹,不能添加炸弹!");
}
else if (loc3.getIsToolState()=="isRoadBlock")
{
JOptionPane.showMessageDialog(null, "此处有路障,不能添加炸弹!");
}
else if (loc3.getIsToolState()=="isForbid")
{
JOptionPane.showMessageDialog(null, "此处属于公共场所,不能添加炸弹!");
}
else
{
loc3.setIsToolState("isBomb");
int NumBomb = player[flag-1].getBomb()-1;//获得玩家的炸弹数
player[flag-1].setBomb(NumBomb);//将玩家的炸弹数减一
labelList.get(loc3.getLocation()).setText("<html>"+"<br>"+" B "+"<html>");//表示该位置有炸弹,并换行
}
}
}
else
{
JOptionPane.showMessageDialog(null, player[flag-1].getPlayerName()+"没有炸弹!");
}
}
}
if(flag==4) {
if(player[flag-1].getState()!=3) {
List<JButton> labelList = basicFrame.getButtonList();
if(player[flag-1].getBomb()>0)
{
if((!MainT.isNumeric((basicFrame.getBombLocation().getText().trim()))))
{
JOptionPane.showMessageDialog(basicFrame.getFrame(), "请输入数字");
}
else if(Integer.parseInt(basicFrame.getBombLocation().getText().trim())>10)
{
JOptionPane.showMessageDialog(basicFrame.getFrame(), "请输入10以内的数字");
}
else
{
int loclab=Integer.parseInt(basicFrame.getBombLocation().getText().trim());//获得label中的String值并转化成int型
JOptionPane.showMessageDialog(null,basicFrame.getBombLocation().getText().trim()+player[flag-1].getPlayerName());
int locply= player[flag-1].getLocation();//获得当前玩家的地址值
Location loc3 = MainT.markLocation.get(locply+loclab);//获得要安置炸弹的位置的对象
if(loc3.getIsToolState()=="isBomb")//判断该位置的道具状态
{
JOptionPane.showMessageDialog(null, "此处有炸弹,不能添加炸弹!");
}
else if (loc3.getIsToolState()=="isRoadBlock")
{
JOptionPane.showMessageDialog(null, "此处有路障,不能添加炸弹!");
}
else if (loc3.getIsToolState()=="isForbid")
{
JOptionPane.showMessageDialog(null, "此处属于公共场所,不能添加炸弹!");
}
else
{
loc3.setIsToolState("isBomb");
int NumBomb = player[flag-1].getBomb()-1;//获得玩家的炸弹数
player[flag-1].setBomb(NumBomb);//将玩家的炸弹数减一
labelList.get(loc3.getLocation()).setText("<html>"+"<br>"+" B "+"<html>");//表示该位置有炸弹,并换行
}
}
}
else
{
JOptionPane.showMessageDialog(null, player[flag-1].getPlayerName()+"没有炸弹!");
}
}
}
}
/**
* 制造2或者3或者4人轮转效果
*/
if(player.length==2) {
flag = (flag%2==0) ? 1 : 2;
} else if (player.length==3) {
if(flag==3) {
flag=1;
} else {
flag++;
}
} else {
if(flag==4) {
flag=1;
} else {
flag++;
}
}
}
}