java
1package othello; 2 3import java.awt.Color; 4 5public class CommonConstants { 6 7 // 一つのマスの大きさ 8 public static final int SIZE = 100; 9 // マスの数 10 public static final int MASS = 8; 11 // 縦の幅 12 public static final int HEGHT = SIZE * MASS; 13 // 横の幅 14 public static final int WIDETH = SIZE * MASS; 15 // 駒の色 16 public static final Color PEICE_COLOR1 = Color.BLACK; 17 // 駒の色 18 public static final Color PEICE_COLOR2 = Color.WHITE; 19 // 黒色 20 public static final int BLACK = 1; 21 // 白色 22 public static final int WHITE = 2; 23 // 駒無し 24 public static final int EMPTY = 0; 25 // ボードの色 26 public static final Color BOARDCOLOR = Color.GREEN; 27 // ボードの線の色 28 public static final Color LINECOLOR = Color.BLACK; 29 // 自分のターン 30 public static final int PLAYER1 = 1; 31 // 相手のターン 32 public static final int PLAYER2 = -1; 33 // ボード配列 34 public int[][] BOARD_ARRAY = new int[MASS][MASS]; 35 36}
定数クラスで上記の配列を作ったのですが、他のクラスで使用することができません。
newをしてしまうとデータが消えてしまうので出来ないのですが
どのように宣言+使用したらいいのでしょうか?
java
1package othello; 2 3import java.awt.event.MouseEvent; 4import javax.swing.event.MouseInputListener; 5import static othello.CommonConstants.*; 6 7public class Reverse implements MouseInputListener { 8 Decision decision = new Decision(); 9 public Reverse() { 10 int turn = -1; 11 12 } 13 14 @Override 15 public void mouseClicked(MouseEvent e) { 16 // TODO 自動生成されたメソッド・スタブ 17 18 } 19 20 @Override 21 public void mousePressed(MouseEvent e) { 22 // TODO 自動生成されたメソッド・スタブ 23 24 Decision decision = new Decision(); 25 int x = e.getX(); 26 int y = e.getY(); 27 // 1マスのSIZEを割った数の整数だけ取得すると2次元配列が取得できる 28 x = x / SIZE; 29 y = y / SIZE; 30 31 if(decision.canReverse(x, y,BOARD_ARRAY)==false){ 32 System.out.println("ここには置くことができません"); 33 } 34 System.out.println(x + "," + y); 35 36 }
回答2件
あなたの回答
tips
プレビュー