質問編集履歴

1

コードを全体部分に変更しました。

2019/01/25 06:21

投稿

rink
rink

スコア80

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,147 @@
4
4
 
5
5
  ```java
6
6
 
7
+ import java.awt.*;
8
+
9
+ import java.awt.event.*;
10
+
11
+ import javax.swing.ImageIcon;
12
+
13
+ import javax.swing.JButton;
14
+
15
+ import javax.swing.JLabel;
16
+
17
+ import javax.swing.JFrame;
18
+
19
+
20
+
21
+ class YPanel extends Panel {
22
+
23
+ //Panel innerPanel3;
24
+
25
+ //Panel innerPanel4;
26
+
27
+ Color bgcolor;
28
+
29
+ static int puyomatrix[][];
30
+
31
+ // static Panel mypanels[][];
32
+
33
+ //int i,Y;
34
+
35
+ public YPanel() {
36
+
37
+
38
+
39
+ bgcolor = super.getBackground();//親クラスのBackgroundを参照しているらしい
40
+
41
+ }
42
+
43
+ public void setBounds(int x, int y, int width, int height) {
44
+
45
+ super.setBounds(x,y,width,height);
46
+
47
+ // innerPanel3.setBounds(4,height-4,width-8,8);
48
+
49
+ // innerPanel4.setBounds(width-8,4,8,height-8);
50
+
51
+ }
52
+
53
+ public Color getBackground() {
54
+
55
+ return bgcolor;
56
+
57
+ }
58
+
59
+ public void setBackground(Color color) {
60
+
61
+ bgcolor = color;
62
+
63
+ super.setBackground(color);//一連の動き確認
64
+
65
+ }
66
+
67
+ }
68
+
69
+
70
+
71
+ public class A {
72
+
73
+ static Frame myframe;
74
+
75
+ static JLabel mylabel;
76
+
77
+ static Panel mypanels[][];
78
+
79
+ static int puyomatrix[][];
80
+
81
+ static Color colorList[];
82
+
83
+ static int score = 0;
84
+
85
+ static int puyoX = 3, puyoY = 1;//上の方のブロックのx座標とY座標
86
+
87
+ //static int puyoX2 = 3, puyoY2 = 2;
88
+
89
+ //static int puyoX = 9, puyoY = 2;
90
+
91
+ static int puyoX2 = 9, puyoY2 = 3;
92
+
93
+ static int color3 = (int)(Math.random()*3)+2;
94
+
95
+ static int color4 = (int)(Math.random()*3)+2;
96
+
97
+ static int color1 = 0, color2 = 0;
98
+
99
+ static int rotate = 0;
100
+
101
+ static boolean lock = false;
102
+
103
+ static boolean lock2 = false;
104
+
105
+
106
+
107
+ static JButton[][] Btn;//ボタン
108
+
109
+
110
+
111
+
112
+
113
+ static int puyoX3=9;
114
+
115
+ static int puyoY3=2;
116
+
117
+ static int puyoX4=9;
118
+
119
+ static int puyoY4=3;
120
+
121
+
122
+
123
+ public static void main(String args[]) {
124
+
125
+ int i,x,y;
126
+
127
+ final int puyoSize = 32;
128
+
129
+
130
+
131
+ myframe = new Frame();
132
+
133
+ myframe.setLayout(null); // does not use layout manager
134
+
135
+ myframe.setSize(400,600); // window size : width = 400, height = 600
136
+
137
+ myframe.setVisible(true); // make the window visible
138
+
139
+ //myframe.addWindowListener(new MyWindowAdapter());
140
+
141
+
142
+
143
+
144
+
145
+
146
+
7
- ImageIcon backicon = new ImageIcon("./png/4.png");
147
+ /*ImageIcon backicon = new ImageIcon("./png/4.png");
8
148
 
9
149
  myframe = new JFrame(backicon);
10
150
 
@@ -16,6 +156,330 @@
16
156
 
17
157
  //myframe.addWindowListener(new MyWindowAdapter());
18
158
 
159
+ */
160
+
161
+
162
+
163
+ ImageIcon labelicon = new ImageIcon("./png/4.png");//背景?
164
+
165
+ mylabel = new JLabel(labelicon);
166
+
167
+ mylabel.setLayout(null); // does not use layout manager
168
+
169
+ mylabel.setSize(400,600); // window size : width = 400, height = 600
170
+
171
+ mylabel.setVisible(true); // make the window visible
172
+
173
+ //mylabel.addWindowListener(new MyWindowAdapter());
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+ ImageIcon buttonicon = new ImageIcon("./png/1.png");//配列上に出る、透明のやつ
182
+
183
+ Btn = new JButton[13][6];//真ん中
184
+
185
+ for(int j = 0; j < 13; j ++) {
186
+
187
+ for(int q = 0; q < 6; q ++) {
188
+
189
+ Btn[j][q] = new JButton(buttonicon);
190
+
191
+ myframe.add(Btn[j][q]);//myframeにBtnを加える
192
+
193
+ Color transparent = new Color(0, 0, 0, 0);
194
+
195
+ Btn[j][q].setBackground(transparent);
196
+
197
+ Btn[j][q].setBounds(80+(32*q),200+(32*j),32,32);
198
+
199
+ }
200
+
201
+ }
202
+
203
+ mypanels = new Panel[13][6];
204
+
205
+ puyomatrix = new int[13][6];
206
+
207
+ colorList = new Color[5];
208
+
209
+ colorList[0] = Color.gray;
210
+
211
+ colorList[1] = Color.white;
212
+
213
+ colorList[2] = Color.yellow;
214
+
215
+ colorList[3] = Color.red;
216
+
217
+ colorList[4] = Color.green;
218
+
219
+
220
+
221
+ for( x = 0; x < 6; x++ ) {
222
+
223
+ for( y = 0; y < 13; y++ ) {
224
+
225
+ Panel p = new YPanel();
226
+
227
+ mypanels[y][x] = p;
228
+
229
+ myframe.add(p);
230
+
231
+ p.setBounds(80+puyoSize*x,200+puyoSize*y,puyoSize,puyoSize);
232
+
233
+ setpuyo(x,y,0); // no puyo is here
234
+
235
+ }
236
+
237
+ }
238
+
239
+ for( x = 0; x < 6; x++ ) {
240
+
241
+ setpuyo(x,12,1); // ground is here、 この値を221行目の仮引数に代入
242
+
243
+ }
244
+
245
+
246
+
247
+ for( y = 0; y < 12; y++ ) {
248
+
249
+ setpuyo(0,y,1); // wall is here
250
+
251
+ setpuyo(5,y,1); // wall is here
252
+
253
+ }
254
+
255
+
256
+
257
+ boolean firstPlacing = true;
258
+
259
+ boolean gameIsOver = false;
260
+
261
+ int fallCount = 0;
262
+
263
+
264
+
265
+ while( gameIsOver != true) {
266
+
267
+ lock = false;
268
+
269
+ sleep(100);//降りてくるのが遅くなる
270
+
271
+ lock = true;
272
+
273
+ while( lock2 ) { sleep(10); }
274
+
275
+ if( firstPlacing ) {
276
+
277
+ firstPlacing = false;
278
+
279
+ color1 = (int)(Math.random()*3)+2;
280
+
281
+ color2 = (int)(Math.random()*3)+2;
282
+
283
+ rotate = 0;
284
+
285
+ puyoX = 3; puyoY = 1; // initialPlace
286
+
287
+
288
+
289
+ if( puyomatrix[puyoY][puyoX] == 0//上のぷよの座標が0になる=上に当たってしまった
290
+
291
+ && puyomatrix[puyoY2][puyoX2] == 0 ) {//下の‥↑
292
+
293
+ setpuyo(puyoX,puyoY,color1);
294
+
295
+ setpuyo(puyoX2,puyoY2,color2);
296
+
297
+ //System.out.print("next puyo is here.\n");
298
+
299
+ } else {
300
+
301
+ // GAME OVER
302
+
303
+ // ImageIcon icon7 = new ImageIcon("./img/7.png");
304
+
305
+ setpuyo(puyoX,puyoY,color1);
306
+
307
+ setpuyo(puyoX2,puyoY2,color2);
308
+
309
+ System.out.print("batan kyu-\n");
310
+
311
+ gameIsOver = true;
312
+
313
+ System.exit(0);
314
+
315
+ }
316
+
317
+ }
318
+
319
+ if( fallCount > 5 ) {
320
+
321
+ fallCount = 0; // counter reset;
322
+
323
+ puyoY++; // fall it for one block
324
+
325
+ puyoY2++;
326
+
327
+ if( (rotate == 0 || puyomatrix[puyoY][puyoX] == 0)
328
+
329
+ && (rotate == 2 || puyomatrix[puyoY2][puyoX2] == 0) ) {
330
+
331
+ setpuyo(puyoX,puyoY-1,0);
332
+
333
+ setpuyo(puyoX2,puyoY2-1,0);
334
+
335
+ setpuyo(puyoX,puyoY,color1);
336
+
337
+ setpuyo(puyoX2,puyoY2,color2);
338
+
339
+ } else {
340
+
341
+ firstPlacing = true;
342
+
343
+ // undo falling
344
+
345
+ puyoY--;
346
+
347
+ puyoY2--;
348
+
349
+ // fall each puyo
350
+
351
+ while(rotate != 0 && puyomatrix[puyoY+1][puyoX] == 0) {
352
+
353
+ setpuyo(puyoX,puyoY,0);
354
+
355
+ puyoY++;
356
+
357
+ setpuyo(puyoX,puyoY,color1);
358
+
359
+ }
360
+
361
+ while(puyomatrix[puyoY2+1][puyoX2] == 0) {
362
+
363
+ setpuyo(puyoX2,puyoY2,0);
364
+
365
+ puyoY2++;
366
+
367
+ setpuyo(puyoX2,puyoY2,color2);
368
+
369
+ }
370
+
371
+ while(rotate == 0 && puyomatrix[puyoY+1][puyoX] == 0) {
372
+
373
+ setpuyo(puyoX,puyoY,0);
374
+
375
+ puyoY++;
376
+
377
+ setpuyo(puyoX,puyoY,color1);
378
+
379
+ }
380
+
381
+ // clear connected puyos and falldown other puyos...
382
+
383
+ // !!--check here--!!
384
+
385
+
386
+
387
+ // !!--check here--!!
388
+
389
+ }
390
+
391
+ } else {
392
+
393
+ fallCount++;
394
+
395
+ }
396
+
397
+ }
398
+
399
+
400
+
401
+ }
402
+
403
+
404
+
405
+
406
+
407
+ static void setpuyo(int x, int y, int color) {
408
+
409
+ puyomatrix[y][x] = color;
410
+
411
+ mypanels[y][x].setBackground(colorList[color]);
412
+
413
+ }
414
+
415
+ static int getpuyo(int x, int y) { // why don't you use this!?
416
+
417
+ // System.out.print(puyomatrix[y][x]);
418
+
419
+ return puyomatrix[y][x];
420
+
421
+ }
422
+
423
+
424
+
425
+ static void fallPuyos() {
426
+
427
+ int fallcount;
428
+
429
+ int nx,ny,nr;
430
+
431
+
432
+
433
+ do {
434
+
435
+ fallcount = 0;
436
+
437
+ int x,y;
438
+
439
+ for( y = 10; y > 0; y-- ) {
440
+
441
+ for( x = 1; x <= 6; x++ ) {
442
+
443
+ if( puyomatrix[y][x] != 0 && puyomatrix[y+1][x] == 0 ) {
444
+
445
+ setpuyo(x,y+1,puyomatrix[y][x]); // fall the puyo
446
+
447
+ setpuyo(x,y,0); // the last position should be empty
448
+
449
+ fallcount++; // count-up fallout counter
450
+
451
+ }
452
+
453
+ }
454
+
455
+ }
456
+
457
+ } while( fallcount != 0 );
458
+
459
+
460
+
461
+ }
462
+
463
+
464
+
465
+
466
+
467
+ static void sleep(long msec) {
468
+
469
+ try{
470
+
471
+ Thread.sleep(msec);//指定した時間の長さにわたって現在のスレッドを中断
472
+
473
+ }catch(InterruptedException ie) {
474
+
475
+ }
476
+
477
+ }
478
+
479
+ }
480
+
481
+
482
+
19
483
  ```
20
484
 
21
485
  エラーは以下の通りです。