回答編集履歴
1
位置調整コードの追加
answer
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
作ったパネルはmain()のところでadd()しています。これを踏まえて、スタートボタンや点数表示などを追加してみてはいかがですか?
|
5
5
|
|
6
6
|
```java
|
7
|
+
|
8
|
+
|
7
9
|
import java.awt.Color;
|
8
10
|
import java.awt.Graphics;
|
9
11
|
import java.awt.Point;
|
@@ -66,8 +68,7 @@
|
|
66
68
|
private static NextBlockPanel nextBlockpanel;
|
67
69
|
|
68
70
|
// Creates a border around the well and initializes the dropping piece
|
69
|
-
private void init() {
|
71
|
+
private void init() {
|
70
|
-
|
71
72
|
well = new Color[12][24];
|
72
73
|
for (int i = 0; i < 12; i++) {
|
73
74
|
for (int j = 0; j < 23; j++) {
|
@@ -97,6 +98,7 @@
|
|
97
98
|
preparedPiece = createIndex();
|
98
99
|
}
|
99
100
|
nextBlockpanel.setPiece(
|
101
|
+
preparedPiece,
|
100
102
|
Tetraminos[preparedPiece][0],
|
101
103
|
tetraminoColors[preparedPiece]);
|
102
104
|
}
|
@@ -311,6 +313,7 @@
|
|
311
313
|
public static final int WIDTH = 26 * 6;
|
312
314
|
public static final int HEIGHT = 26 * 6;
|
313
315
|
|
316
|
+
private int bid;
|
314
317
|
private Color color;
|
315
318
|
private Point[] points;
|
316
319
|
|
@@ -318,11 +321,11 @@
|
|
318
321
|
setPreferredSize(new Dimension(WIDTH, HEIGHT));
|
319
322
|
}
|
320
323
|
|
321
|
-
public void setPiece(Point[] points, Color color) {
|
324
|
+
public void setPiece(int bid, Point[] points, Color color) {
|
322
325
|
|
326
|
+
this.bid = bid;
|
323
327
|
this.points = points;
|
324
328
|
this.color = color;
|
325
|
-
System.out.println(color);
|
326
329
|
|
327
330
|
repaint();
|
328
331
|
}
|
@@ -339,11 +342,16 @@
|
|
339
342
|
|
340
343
|
if (points == null) return;
|
341
344
|
|
345
|
+
int bx = 39, by = 52;
|
346
|
+
if (bid == 0) { bx = 26; by = 39; }
|
347
|
+
else if (bid == 2) by = 26;
|
348
|
+
else if (bid == 3) bx = 52;
|
342
349
|
g.setColor(color);
|
343
350
|
for (Point p : points) {
|
344
|
-
System.out.println(p.x + " " + p.y);
|
345
|
-
g.fillRect(p.x * 26 +
|
351
|
+
g.fillRect(p.x * 26 + bx, p.y * 26 + by, 25, 25);
|
346
352
|
}
|
347
353
|
}
|
348
354
|
}
|
349
|
-
```
|
355
|
+
```
|
356
|
+
---
|
357
|
+
追記:ブロック位置の調整も入れてみました。
|