teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

2017/04/18 03:32

投稿

syo17
syo17

スコア11

title CHANGED
File without changes
body CHANGED
File without changes

3

2017/04/18 03:32

投稿

syo17
syo17

スコア11

title CHANGED
File without changes
body CHANGED
@@ -1,59 +1,7 @@
1
1
  java eclipseでスライドパズルを作成しています。
2
2
  9枚の画像で作成しており、現在は9枚の画像を実行するたびにランダムで表示するところまでいきました。
3
3
  その後ですが9枚の画像のうち一枚を空白にし、上下左右のキーを押すと空白になった部分と対応した押したキーの位置にあるピースが入れ替わるようにしたいのですが時間がかかっておりなかなか進めません。
4
- よろしければソースコードを教えてもらえると嬉しいです、、、! 3つのクラスを使用しています。 ```ここに言語を入力
5
- コード
6
- ```import java.awt.Container;
7
- import java.awt.GridLayout;
8
4
 
9
- import javax.swing.JFrame;
10
-
11
- public class Puzzle00 extends JFrame{
12
-
13
- PuzzlePiece Puzzlepiece[];
14
-
15
- Container c;
16
-
17
- public Puzzle00(){
18
- setBounds(550, 250, 318, 341);
19
- setTitle("PuzzleGame");
20
- setDefaultCloseOperation(EXIT_ON_CLOSE);
21
- c = getContentPane();
22
- c.setLayout(new GridLayout( 3 , 3 , 0 , 0) );
23
- init();
24
- }
25
-
26
-
27
- public void init(){
28
- Puzzlepiece = new PuzzlePiece[9];
29
-
30
- //元の配列
31
- for(int i = 0 ; i < Puzzlepiece.length ; i++){
32
- Puzzlepiece[i] = new PuzzlePiece(i);
33
- }
34
-
35
- //配列の中身をランダムに
36
- for ( int i = 0; i < Puzzlepiece.length; ++ i ) {
37
- int a = (int)( Math.random() * (double)Puzzlepiece.length );
38
- PuzzlePiece b = Puzzlepiece[i];
39
- Puzzlepiece [i] = Puzzlepiece [a];
40
- Puzzlepiece[a] = b;
41
-
42
- }
43
-
44
- for(int i = 0 ; i < Puzzlepiece.length ; i++){
45
- c.add(Puzzlepiece[i]);
46
- }
47
-
48
- }
49
-
50
- public static void main(String[] args) {
51
-
52
- Puzzle00 mainFrame = new Puzzle00();
53
- mainFrame.setVisible( true );
54
- }
55
-
56
- }
57
5
  ```ここに言語を入力
58
6
  コード
59
7
  ```public interface Gazo {
@@ -69,60 +17,4 @@
69
17
  "画像8枚目",
70
18
  "画像9枚目"
71
19
  };
72
- }
20
+ }
73
- ```ここに言語を入力
74
- コード
75
- ```import java.awt.Graphics;
76
- import java.awt.Image;
77
-
78
- import javax.swing.ImageIcon;
79
- import javax.swing.JPanel;
80
-
81
-
82
-
83
- public class PuzzlePiece extends JPanel implements Gazo{
84
-
85
- public static final int PIECE_V = 300;
86
- public static final int PIECE_H = 300;
87
-
88
- private int nowPosition;
89
- private int correctPosition;
90
-
91
- ImageIcon imageIcon;
92
- Image image;
93
-
94
- public PuzzlePiece(int i) {
95
- nowPosition = i;
96
- correctPosition = i;
97
- setSize(PIECE_H, PIECE_V);
98
- imageIcon = new ImageIcon(s[i]);
99
- image = imageIcon.getImage();
100
- }
101
-
102
- public void paintComponent( Graphics g ){
103
- super.paintComponent(g);
104
- g.drawImage( image , 0, 0, null);
105
- }
106
-
107
- public int getNowPosition() {
108
- return nowPosition;
109
- }
110
-
111
- public void setNowPosition(int nowPosition) {
112
- this.nowPosition = nowPosition;
113
- }
114
-
115
- public int getCorrectPosition() {
116
- return correctPosition;
117
- }
118
-
119
- public void setCorrectPosition(int correctPosition) {
120
- this.correctPosition = correctPosition;
121
- }
122
-
123
-
124
-
125
- }
126
- ```ここに言語を入力
127
- コード
128
- ```

2

2017/04/18 03:30

投稿

syo17
syo17

スコア11

title CHANGED
File without changes
body CHANGED
File without changes

1

2017/04/17 23:38

投稿

syo17
syo17

スコア11

title CHANGED
File without changes
body CHANGED
File without changes