質問編集履歴
1
ソースコードをそのまま写すのではなく、私の考える要所のみを抜き取りました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
まず、私はプログラミングを独学ではじめ、なかなか理解できず、とにかく触って慣れていこうと思い、ネット上の様々な情報を切り貼りし、
|
3
|
-
現在昔段ボールで作ったすごろくゲームの再現に取り組んでいます。
|
3
|
+
現在、昔 段ボールで作ったすごろくゲームの再現に取り組んでいます。
|
4
4
|
そこで9×9のマス目の盤面において、以下のようにマスに番号を付け、1から、サイコロででた目xだけ進んで1+xにたどり着くという状況を作りたいです。
|
5
5
|
|73|74|75|76|77|78|79|80|81|
|
6
6
|
____________________________
|
@@ -22,222 +22,28 @@
|
|
22
22
|
|
23
23
|
### 発生している問題・エラーメッセージ
|
24
24
|
エラーはありません。ですが上記の通り全くの初心者であり、できる限りネットを駆使して検索をかけたものの答えが出ず、どうすれば思い道理になるのかが全く見当がつかないため、見識のある方々に伺おうと思った次第です。
|
25
|
+
具体的には下記の(250,300,50,50)を一番目として四角にそれぞれ番号を付けたいです。
|
25
26
|
### 該当のソースコード
|
26
27
|
|
27
|
-
|
28
|
+
```Java
|
28
|
-
|
29
|
-
import java.awt.Color;
|
30
|
-
import java.awt.Graphics;
|
31
|
-
|
32
|
-
import javax.swing.JFrame;
|
33
|
-
import javax.swing.JPanel;
|
34
|
-
|
35
29
|
public class C{
|
36
30
|
public static void main(String[] args) {
|
37
|
-
GameWindow gw = new GameWindow("
|
31
|
+
GameWindow gw = new GameWindow("マス目",550,600);
|
38
|
-
gw.add(new DrawCanvas());
|
32
|
+
gw.add(new DrawCanvas());
|
39
33
|
gw.setVisible(true);
|
40
34
|
}
|
41
35
|
}
|
42
36
|
|
43
|
-
//ウィンドウクラス
|
44
|
-
class GameWindow extends JFrame{
|
45
|
-
public GameWindow(String title, int width, int height) {
|
46
|
-
super(title);
|
47
|
-
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
48
|
-
setSize(width,height);
|
49
|
-
setLocationRelativeTo(null);
|
50
|
-
setResizable(false);
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
//描画する紙を表すクラス
|
55
37
|
class DrawCanvas extends JPanel{
|
56
|
-
public void paintComponent(Graphics g) {
|
57
|
-
g.setColor(Color.yellow);
|
58
|
-
g.fillRect(500,100,50,50);
|
59
|
-
g.setColor(new Color(0,170,0));
|
60
|
-
g.fillRect(50,100, 450, 450);
|
61
|
-
|
62
|
-
g.setColor(Color.black);
|
63
|
-
g.drawRect(250,300,50,50);//
|
38
|
+
g.drawRect(250,300,50,50);//四角1
|
64
|
-
g.drawRect(300,300,50,50);
|
39
|
+
g.drawRect(300,300,50,50);//四角2
|
65
|
-
g.drawRect(300,350,50,50);
|
40
|
+
g.drawRect(300,350,50,50);//四角3
|
66
|
-
g.drawRect(250,350,50,50);
|
67
|
-
g.drawRect(200,350,50,50);
|
68
|
-
g.drawRect(200,300,50,50);
|
69
|
-
g.drawRect(200,250,50,50);
|
70
|
-
g.drawRect(250,250,50,50);
|
71
|
-
g.drawRect(300,250,50,50);
|
72
|
-
g.drawRect(350,250,50,50);
|
73
|
-
g.drawRect(350,300,50,50);
|
74
|
-
g.drawRect(350,350,50,50);
|
75
|
-
g.drawRect(350,400,50,50);
|
76
|
-
g.drawRect(300,400,50,50);
|
77
|
-
g.drawRect(250,400,50,50);
|
78
|
-
g.drawRect(200,400,50,50);
|
79
|
-
g.drawRect(150,400,50,50);
|
80
|
-
g.drawRect(150,350,50,50);
|
81
|
-
g.drawRect(150,300,50,50);
|
82
|
-
g.drawRect(150,250,50,50);
|
83
|
-
g.drawRect(150,200,50,50);
|
84
|
-
g.drawRect(200,200,50,50);
|
85
|
-
g.drawRect(250,200,50,50);
|
86
|
-
g.drawRect(300,200,50,50);
|
87
|
-
g.drawRect(350,200,50,50);
|
88
|
-
g.drawRect(400,200,50,50);
|
89
|
-
g.drawRect(400,250,50,50);
|
90
|
-
g.drawRect(400,300,50,50);
|
91
|
-
g.drawRect(400,350,50,50);
|
92
|
-
g.drawRect(400,400,50,50);
|
93
|
-
g.drawRect(400,450,50,50);
|
94
|
-
g.drawRect(350,450,50,50);
|
95
|
-
g.drawRect(300,450,50,50);
|
96
|
-
g.drawRect(250,450,50,50);
|
97
|
-
g.drawRect(200,450,50,50);
|
98
|
-
g.drawRect(150,450,50,50);
|
99
|
-
g.drawRect(100,450,50,50);
|
100
|
-
g.drawRect(100,400,50,50);
|
101
|
-
g.drawRect(100,350,50,50);
|
102
|
-
g.drawRect(100,300,50,50);
|
103
|
-
g.drawRect(100,250,50,50);
|
104
|
-
g.drawRect(100,200,50,50);
|
105
|
-
g.drawRect(100,150,50,50);
|
106
|
-
g.drawRect(150,150,50,50);
|
107
|
-
g.drawRect(200,150,50,50);
|
108
|
-
g.drawRect(250,150,50,50);
|
109
|
-
g.drawRect(300,150,50,50);
|
110
|
-
g.drawRect(350,150,50,50);
|
111
|
-
g.drawRect(400,150,50,50);
|
112
|
-
g.drawRect(450,150,50,50);
|
113
|
-
g.drawRect(450,200,50,50);
|
114
|
-
g.drawRect(450,250,50,50);
|
115
|
-
g.drawRect(450,300,50,50);
|
116
|
-
g.drawRect(450,350,50,50);
|
117
|
-
g.drawRect(450,400,50,50);
|
118
|
-
g.drawRect(450,450,50,50);
|
119
|
-
g.drawRect(450,500,50,50);
|
120
|
-
g.drawRect(400,500,50,50);
|
121
|
-
g.drawRect(350,500,50,50);
|
122
|
-
g.drawRect(300,500,50,50);
|
123
|
-
g.drawRect(250,500,50,50);
|
124
|
-
g.drawRect(200,500,50,50);
|
125
|
-
g.drawRect(150,500,50,50);
|
126
|
-
g.drawRect(100,500,50,50);
|
127
|
-
g.drawRect( 50,500,50,50);
|
128
|
-
g.drawRect( 50,450,50,50);
|
129
|
-
g.drawRect( 50,400,50,50);
|
130
|
-
g.drawRect( 50,350,50,50);
|
131
|
-
g.drawRect( 50,300,50,50);
|
132
|
-
g.drawRect( 50,250,50,50);
|
133
|
-
g.drawRect( 50,200,50,50);
|
134
|
-
g.drawRect( 50,150,50,50);
|
135
|
-
g.drawRect( 50,100,50,50);
|
136
|
-
g.drawRect(100,100,50,50);
|
137
|
-
g.drawRect(150,100,50,50);
|
138
|
-
g.drawRect(200,100,50,50);
|
139
|
-
g.drawRect(250,100,50,50);
|
140
|
-
g.drawRect(300,100,50,50);
|
141
|
-
g.drawRect(350,100,50,50);
|
142
|
-
g.drawRect(400,100,50,50);
|
143
|
-
g.drawRect(450,100,50,50);
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
//点線1,2
|
151
|
-
for(int x=0;x<50;x=x+10) {
|
152
|
-
g.drawLine(275+x,325,280+x,325);
|
153
|
-
g.drawLine(325,325+x,325,330+x) ;
|
154
|
-
|
41
|
+
.
|
155
|
-
//点線3、4
|
156
|
-
for(int x=0;x<100;x=x+10) {
|
157
|
-
g.drawLine(325-x,375,320-x,375);
|
158
|
-
|
159
|
-
g.drawLine(225,375-x,225,370-x) ;
|
160
|
-
|
42
|
+
.
|
161
|
-
for(int x=0;x<150;x=x+10) {
|
162
|
-
g.drawLine(225+x,275,230+x,275);
|
163
|
-
g.drawLine(375,275+x,375,280+x) ;
|
164
|
-
|
43
|
+
.
|
165
|
-
for(int x=0;x<200;x=x+10) {
|
166
|
-
g.drawLine(375-x,425,370-x,425);
|
167
|
-
g.drawLine(175,425-x,175,420-x) ;
|
168
|
-
|
44
|
+
.
|
169
|
-
for(int x=0;x<250;x=x+10) {
|
170
|
-
g.drawLine(175+x,225,180+x,225);
|
171
|
-
g.drawLine(425,225+x,425,230+x) ;
|
172
|
-
}
|
173
|
-
for(int x=0;x<300;x=x+10) {
|
174
|
-
g.drawLine(425-x,475,420-x,475);
|
175
|
-
g.drawLine(125,475-x,125,470-x) ;
|
176
|
-
}
|
177
|
-
for(int x=0;x<350;x=x+10) {
|
178
|
-
g.drawLine(125+x,175,130+x,175);
|
179
|
-
g.drawLine(475,175+x,475,180+x) ;
|
180
|
-
}
|
181
|
-
for(int x=0;x<400;x=x+10) {
|
182
|
-
g.drawLine(475-x,525,480-x,525);
|
183
|
-
g.drawLine(75,525-x,75,520-x) ;
|
184
|
-
}
|
185
|
-
for(int x=0;x<430;x=x+10) {
|
186
|
-
g.drawLine(75+x,125,80+x,125);
|
187
|
-
}
|
188
|
-
//スタート、ゴール
|
189
|
-
g.drawString("ゴール", 500, 115);
|
190
|
-
g.drawString("スタート", 252, 320);
|
191
|
-
//イヴェント
|
192
|
-
int a=new java.util.Random().nextInt(5)+2;
|
193
|
-
int b=new java.util.Random().nextInt(8)+1;
|
194
|
-
int c=new java.util.Random().nextInt(8)+2;
|
195
|
-
int d=new java.util.Random().nextInt(8)+1;
|
196
|
-
int e=new java.util.Random().nextInt(8)+2;
|
197
|
-
int f=new java.util.Random().nextInt(8)+1;
|
198
|
-
int s=new java.util.Random().nextInt(8)+2;
|
199
|
-
int h=new java.util.Random().nextInt(8)+1;
|
200
|
-
int i=new java.util.Random().nextInt(8)+2;
|
201
|
-
int j=new java.util.Random().nextInt(8)+1;
|
202
|
-
int k=new java.util.Random().nextInt(8)+2;
|
203
|
-
int l=new java.util.Random().nextInt(5)+2;
|
204
|
-
int m=new java.util.Random().nextInt(5)+2;
|
205
|
-
int n=new java.util.Random().nextInt(5)+2;
|
206
|
-
int o=new java.util.Random().nextInt(5)+2;
|
207
|
-
int p=new java.util.Random().nextInt(5)+2;
|
208
|
-
int q=new java.util.Random().nextInt(6)+4;
|
209
|
-
int r=new java.util.Random().nextInt(8)+2;
|
210
|
-
int t=new java.util.Random().nextInt(8)+1;
|
211
|
-
int u=new java.util.Random().nextInt(8)+2;
|
212
|
-
int v=new java.util.Random().nextInt(8)+1;
|
213
|
-
int w=new java.util.Random().nextInt(8)+2;
|
214
|
-
int y=new java.util.Random().nextInt(8)+1;
|
215
|
-
int z=new java.util.Random().nextInt(8)+2;
|
216
|
-
if(b!=5&c!=5) {
|
217
|
-
g.drawString("+"+a+"マス", 50*b+5, 50*c+15);}
|
218
|
-
if(d!=5&e!=5) {if(d!=b&e!=c) {
|
219
|
-
g.drawString("盤面",50*d+5 , 50*e+15);
|
220
|
-
g.drawString("⤵90°",50*d+5,50*e+28);}}
|
221
|
-
if(f!=5&s!=5) {if(f!=b&s!=c) {if(f!=d&s!=e) {
|
222
|
-
g.drawString("+"+l+"マス",50*f+5,50*s+15);}}}
|
223
|
-
if(h!=5&i!=5) {if(h!=b&i!=c) {if(h!=d&i!=e) {if(h!=f&i!=s) {
|
224
|
-
g.drawString("盤面",50*h+5 , 50*i+15);
|
225
|
-
g.drawString(" ⤵ 180°",50*h+5 ,50*i+25 );}}}}
|
226
|
-
if(j!=5&k!=5) {if(j!=b&k!=c) {if(j!=d&k!=e) {if(j!=f&k!=s) {if(j!=h&k!=i){
|
227
|
-
g.drawString("+"+o+"マス",50*j+5,50*k+15);}}}}}
|
228
|
-
if(q!=5&r!=5) {if(q!=b&r!=c) {if(q!=d&r!=e) {if(q!=f&r!=s) {if(q!=h&r!=i){if(q!=j&r!=k) {
|
229
|
-
g.drawString("2マス",50*q+5, 50*r+15);
|
230
|
-
g.drawString("左へ",50*q+5,50*r+25);}}}}}}
|
231
|
-
if(t!=5&u!=5) {if(t!=b&u!=c) {if(t!=d&u!=e) {if(t!=f&u!=s) {if(t!=h&u!=i){if(t!=j&u!=k) {if(t!=q&u!=r) {
|
232
|
-
g.drawString("+"+m+"マス",50*q+5, 50*r+15);}}}}}}}
|
233
|
-
if(v!=5&w!=5) {if(v!=b&w!=c) {if(v!=d&w!=e) {if(v!=f&w!=s) {if(v!=h&w!=i){if(v!=j&w!=k) {if(v!=q&w!=r) {if(v!=t&w!=u) {
|
234
|
-
g.drawString("+"+n+"マス",50*q+5, 50*r+15);}}}}}}}}
|
235
|
-
if(y!=5&z!=5) {if(y!=b&z!=c) {if(y!=d&z!=e) {if(y!=f&z!=s) {if(y!=h&z!=i){if(y!=j&z!=k) {if(y!=q&z!=r) {if(y!=t&z!=u) {if(y!=v&z!=w) {
|
236
|
-
g.drawString("+"+p+"マス",50*q+5, 50*r+15);}}}}}}}}}
|
237
|
-
|
238
|
-
|
239
|
-
}
|
240
45
|
}
|
46
|
+
```
|
241
47
|
### 試したこと
|
242
48
|
マス目の座標を変数で置き、マス目に番号を振るクラスを別で設けようとしたり、ネットで情報を探りましたが、有効な手段は見つけられませんでした。
|
243
49
|
|