回答編集履歴

1

位置調整コードの追加

2018/01/24 22:24

投稿

退会済みユーザー
test CHANGED
@@ -10,6 +10,10 @@
10
10
 
11
11
  ```java
12
12
 
13
+
14
+
15
+
16
+
13
17
  import java.awt.Color;
14
18
 
15
19
  import java.awt.Graphics;
@@ -134,9 +138,7 @@
134
138
 
135
139
  // Creates a border around the well and initializes the dropping piece
136
140
 
137
- private void init() {// this.nextBlock = nextBlock;
141
+ private void init() {
138
-
139
-
140
142
 
141
143
  well = new Color[12][24];
142
144
 
@@ -196,6 +198,8 @@
196
198
 
197
199
  nextBlockpanel.setPiece(
198
200
 
201
+ preparedPiece,
202
+
199
203
  Tetraminos[preparedPiece][0],
200
204
 
201
205
  tetraminoColors[preparedPiece]);
@@ -624,6 +628,8 @@
624
628
 
625
629
 
626
630
 
631
+ private int bid;
632
+
627
633
  private Color color;
628
634
 
629
635
  private Point[] points;
@@ -638,16 +644,16 @@
638
644
 
639
645
 
640
646
 
641
- public void setPiece(Point[] points, Color color) {
647
+ public void setPiece(int bid, Point[] points, Color color) {
648
+
649
+
650
+
642
-
651
+ this.bid = bid;
643
-
644
652
 
645
653
  this.points = points;
646
654
 
647
655
  this.color = color;
648
656
 
649
- System.out.println(color);
650
-
651
657
 
652
658
 
653
659
  repaint();
@@ -680,13 +686,19 @@
680
686
 
681
687
 
682
688
 
689
+ int bx = 39, by = 52;
690
+
691
+ if (bid == 0) { bx = 26; by = 39; }
692
+
693
+ else if (bid == 2) by = 26;
694
+
695
+ else if (bid == 3) bx = 52;
696
+
683
697
  g.setColor(color);
684
698
 
685
699
  for (Point p : points) {
686
700
 
687
- System.out.println(p.x + " " + p.y);
688
-
689
- g.fillRect(p.x * 26 + 26, p.y * 26 + 26, 25, 25);
701
+ g.fillRect(p.x * 26 + bx, p.y * 26 + by, 25, 25);
690
702
 
691
703
  }
692
704
 
@@ -695,3 +707,7 @@
695
707
  }
696
708
 
697
709
  ```
710
+
711
+ ---
712
+
713
+ 追記:ブロック位置の調整も入れてみました。