質問編集履歴

4

2017/04/18 03:32

投稿

syo17
syo17

スコア11

test CHANGED
File without changes
test CHANGED
File without changes

3

2017/04/18 03:32

投稿

syo17
syo17

スコア11

test CHANGED
File without changes
test CHANGED
@@ -4,111 +4,7 @@
4
4
 
5
5
  その後ですが9枚の画像のうち一枚を空白にし、上下左右のキーを押すと空白になった部分と対応した押したキーの位置にあるピースが入れ替わるようにしたいのですが時間がかかっておりなかなか進めません。
6
6
 
7
- よろしければソースコードを教えてもらえると嬉しいです、、、! 3つのクラスを使用しています。 ```ここに言語を入力
8
7
 
9
- コード
10
-
11
- ```import java.awt.Container;
12
-
13
- import java.awt.GridLayout;
14
-
15
-
16
-
17
- import javax.swing.JFrame;
18
-
19
-
20
-
21
- public class Puzzle00 extends JFrame{
22
-
23
-
24
-
25
- PuzzlePiece Puzzlepiece[];
26
-
27
-
28
-
29
- Container c;
30
-
31
-
32
-
33
- public Puzzle00(){
34
-
35
- setBounds(550, 250, 318, 341);
36
-
37
- setTitle("PuzzleGame");
38
-
39
- setDefaultCloseOperation(EXIT_ON_CLOSE);
40
-
41
- c = getContentPane();
42
-
43
- c.setLayout(new GridLayout( 3 , 3 , 0 , 0) );
44
-
45
- init();
46
-
47
- }
48
-
49
-
50
-
51
-
52
-
53
- public void init(){
54
-
55
- Puzzlepiece = new PuzzlePiece[9];
56
-
57
-
58
-
59
- //元の配列
60
-
61
- for(int i = 0 ; i < Puzzlepiece.length ; i++){
62
-
63
- Puzzlepiece[i] = new PuzzlePiece(i);
64
-
65
- }
66
-
67
-
68
-
69
- //配列の中身をランダムに
70
-
71
- for ( int i = 0; i < Puzzlepiece.length; ++ i ) {
72
-
73
- int a = (int)( Math.random() * (double)Puzzlepiece.length );
74
-
75
- PuzzlePiece b = Puzzlepiece[i];
76
-
77
- Puzzlepiece [i] = Puzzlepiece [a];
78
-
79
- Puzzlepiece[a] = b;
80
-
81
-
82
-
83
- }
84
-
85
-
86
-
87
- for(int i = 0 ; i < Puzzlepiece.length ; i++){
88
-
89
- c.add(Puzzlepiece[i]);
90
-
91
- }
92
-
93
-
94
-
95
- }
96
-
97
-
98
-
99
- public static void main(String[] args) {
100
-
101
-
102
-
103
- Puzzle00 mainFrame = new Puzzle00();
104
-
105
- mainFrame.setVisible( true );
106
-
107
- }
108
-
109
-
110
-
111
- }
112
8
 
113
9
  ```ここに言語を入力
114
10
 
@@ -141,115 +37,3 @@
141
37
  };
142
38
 
143
39
  }
144
-
145
- ```ここに言語を入力
146
-
147
- コード
148
-
149
- ```import java.awt.Graphics;
150
-
151
- import java.awt.Image;
152
-
153
-
154
-
155
- import javax.swing.ImageIcon;
156
-
157
- import javax.swing.JPanel;
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
- public class PuzzlePiece extends JPanel implements Gazo{
166
-
167
-
168
-
169
- public static final int PIECE_V = 300;
170
-
171
- public static final int PIECE_H = 300;
172
-
173
-
174
-
175
- private int nowPosition;
176
-
177
- private int correctPosition;
178
-
179
-
180
-
181
- ImageIcon imageIcon;
182
-
183
- Image image;
184
-
185
-
186
-
187
- public PuzzlePiece(int i) {
188
-
189
- nowPosition = i;
190
-
191
- correctPosition = i;
192
-
193
- setSize(PIECE_H, PIECE_V);
194
-
195
- imageIcon = new ImageIcon(s[i]);
196
-
197
- image = imageIcon.getImage();
198
-
199
- }
200
-
201
-
202
-
203
- public void paintComponent( Graphics g ){
204
-
205
- super.paintComponent(g);
206
-
207
- g.drawImage( image , 0, 0, null);
208
-
209
- }
210
-
211
-
212
-
213
- public int getNowPosition() {
214
-
215
- return nowPosition;
216
-
217
- }
218
-
219
-
220
-
221
- public void setNowPosition(int nowPosition) {
222
-
223
- this.nowPosition = nowPosition;
224
-
225
- }
226
-
227
-
228
-
229
- public int getCorrectPosition() {
230
-
231
- return correctPosition;
232
-
233
- }
234
-
235
-
236
-
237
- public void setCorrectPosition(int correctPosition) {
238
-
239
- this.correctPosition = correctPosition;
240
-
241
- }
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
- }
250
-
251
- ```ここに言語を入力
252
-
253
- コード
254
-
255
- ```

2

2017/04/18 03:30

投稿

syo17
syo17

スコア11

test CHANGED
File without changes
test CHANGED
File without changes

1

2017/04/17 23:38

投稿

syo17
syo17

スコア11

test CHANGED
File without changes
test CHANGED
File without changes