質問編集履歴

3

見やすいように修正

2016/03/26 14:21

投稿

sobue
sobue

スコア329

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,5 @@
1
+ ```java
2
+
1
3
  package othello;
2
4
 
3
5
 

2

コードの追記

2016/03/26 14:21

投稿

sobue
sobue

スコア329

test CHANGED
File without changes
test CHANGED
@@ -1,5 +1,3 @@
1
- ```java
2
-
3
1
  package othello;
4
2
 
5
3
 
@@ -79,3 +77,79 @@
79
77
  newをしてしまうとデータが消えてしまうので出来ないのですが
80
78
 
81
79
  どのように宣言+使用したらいいのでしょうか?
80
+
81
+ ```java
82
+
83
+ package othello;
84
+
85
+
86
+
87
+ import java.awt.event.MouseEvent;
88
+
89
+ import javax.swing.event.MouseInputListener;
90
+
91
+ import static othello.CommonConstants.*;
92
+
93
+
94
+
95
+ public class Reverse implements MouseInputListener {
96
+
97
+ Decision decision = new Decision();
98
+
99
+ public Reverse() {
100
+
101
+ int turn = -1;
102
+
103
+
104
+
105
+ }
106
+
107
+
108
+
109
+ @Override
110
+
111
+ public void mouseClicked(MouseEvent e) {
112
+
113
+ // TODO 自動生成されたメソッド・スタブ
114
+
115
+
116
+
117
+ }
118
+
119
+
120
+
121
+ @Override
122
+
123
+ public void mousePressed(MouseEvent e) {
124
+
125
+ // TODO 自動生成されたメソッド・スタブ
126
+
127
+
128
+
129
+ Decision decision = new Decision();
130
+
131
+ int x = e.getX();
132
+
133
+ int y = e.getY();
134
+
135
+ // 1マスのSIZEを割った数の整数だけ取得すると2次元配列が取得できる
136
+
137
+ x = x / SIZE;
138
+
139
+ y = y / SIZE;
140
+
141
+
142
+
143
+ if(decision.canReverse(x, y,BOARD_ARRAY)==false){
144
+
145
+ System.out.println("ここには置くことができません");
146
+
147
+ }
148
+
149
+ System.out.println(x + "," + y);
150
+
151
+
152
+
153
+ }
154
+
155
+ ```

1

コードの追加

2016/03/26 14:20

投稿

sobue
sobue

スコア329

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,76 @@
1
1
  ```java
2
2
 
3
+ package othello;
4
+
5
+
6
+
7
+ import java.awt.Color;
8
+
9
+
10
+
11
+ public class CommonConstants {
12
+
13
+
14
+
15
+ // 一つのマスの大きさ
16
+
17
+ public static final int SIZE = 100;
18
+
19
+ // マスの数
20
+
21
+ public static final int MASS = 8;
22
+
23
+ // 縦の幅
24
+
25
+ public static final int HEGHT = SIZE * MASS;
26
+
27
+ // 横の幅
28
+
29
+ public static final int WIDETH = SIZE * MASS;
30
+
31
+ // 駒の色
32
+
33
+ public static final Color PEICE_COLOR1 = Color.BLACK;
34
+
35
+ // 駒の色
36
+
37
+ public static final Color PEICE_COLOR2 = Color.WHITE;
38
+
39
+ // 黒色
40
+
41
+ public static final int BLACK = 1;
42
+
43
+ // 白色
44
+
45
+ public static final int WHITE = 2;
46
+
47
+ // 駒無し
48
+
49
+ public static final int EMPTY = 0;
50
+
51
+ // ボードの色
52
+
53
+ public static final Color BOARDCOLOR = Color.GREEN;
54
+
55
+ // ボードの線の色
56
+
57
+ public static final Color LINECOLOR = Color.BLACK;
58
+
59
+ // 自分のターン
60
+
61
+ public static final int PLAYER1 = 1;
62
+
63
+ // 相手のターン
64
+
65
+ public static final int PLAYER2 = -1;
66
+
67
+ // ボード配列
68
+
3
- public int[][] BOARD_ARRAY = new int[MASS][MASS];
69
+ public int[][] BOARD_ARRAY = new int[MASS][MASS];
70
+
71
+
72
+
73
+ }
4
74
 
5
75
  ```
6
76