DotInfo.javaというクラスがあります。このクラスには、3つのパラメータを持つコンストラクタがあります。ゲームにドットを格納するための配列を作成することに混乱しています。
DotInfo(int x, int y, int color) {
...
}
GameModel.javaという別のクラスがあります。 DotInfoのインスタンスを配列に格納する方法を理解しようとしています。また、私はボードに円を置くことによってxとyを増やす必要があるか分からない。誰も助けることができますか?
これは私のDotInfoクラスです:
/**
* The class <b>DotInfo</b> is a simple helper class to store the initial color and state
* (captured or not) at the dot position (x,y)
*/
public class DotInfo {
private int x;
private int y;
private int color;
private boolean captured;
/**
* Constructor
*
* @param x
* the x coordinate
* @param y
* the y coordinate
* @param color
* the initial color
*/
public DotInfo(int x, int y, int color){
this.x = x;
this.y = y;
this.color = color;
captured = false;
}
/**
* Getter method for the attribute x.
*
* @return the value of the attribute x
*/
public int getX(){
return x;
}
/**
* Getter method for the attribute y.
*
* @return the value of the attribute y
*/
public int getY(){
return y;
}
/**
* Setter for captured
* @param captured
* the new value for captured
*/
public void setCaptured(boolean captured) {
this.captured = captured;
}
/**
* Get for captured
*
* @return captured
*/
public boolean isCaptured(){
return captured;
}
/**
* Get for color
*
* @return color
*/
public int getColor() {
return color;
}
}
これは私のGameModel.javaクラスです:
import java.util.Random;
/**
* The class GameModel holds the model, the state of the systems.
* It stores the followiung information:
* - the state of all the ``dots'' on the board (color, captured or not)
* - the size of the board
* - the number of steps since the last reset
* - the current color of selection
*
* The model provides all of this informations to the other classes through
* appropriate Getters.
* The controller can also update the model through Setters.
* Finally, the model is also in charge of initializing the game
*/
public class GameModel {
/**
* predefined values to capture the color of a DotInfo
*/
public static final int COLOR_0 = 0;
public static final int COLOR_1 = 1;
public static final int COLOR_2 = 2;
public static final int COLOR_3 = 3;
public static final int COLOR_4 = 4;
public static final int COLOR_5 = 5;
public static final int NUMBER_OF_COLORS = 6;
private DotInfo[][] dots;
private int size;
private Random generator;
/**
* Constructor to initialize the model to a given size of board.
*
* @param size
* the size of the board
*/
public GameModel(int size) {
this.size = size;
dots = new DotInfo[size][size];
}
/**
* Resets the model to (re)start a game. The previous game (if there is one)
* is cleared up .
*/
public void reset(){
dots = new DotInfo[size];
for (int i=0;i<dots.length;i++) {
for (int j=0;j<dots[i].length;j++) {
dots[i][j] =
}
}
}
/**
* Getter method for the size of the game
*
* @return the value of the attribute sizeOfGame
*/
public int getSize(){
return size;
}
/**
* returns the current color of a given dot in the game
*
* @param i
* the x coordinate of the dot
* @param j
* the y coordinate of the dot
* @return the status of the dot at location (i,j)
*/
public int getColor(int i, int j){
dot = new DotInfo(i, j, COLOR_0);
return dot.getColor();
}
/**
* returns true is the dot is captured, false otherwise
*
* @param i
* the x coordinate of the dot
* @param j
* the y coordinate of the dot
* @return the status of the dot at location (i,j)
*/
public boolean isCaptured(int i, int j){
dot = new DotInfo(i, j, COLOR_0);
}
/**
* Sets the status of the dot at coordinate (i,j) to captured
*
* @param i
* the x coordinate of the dot
* @param j
* the y coordinate of the dot
*/
public void capture(int i, int j){
//ここ
}
/**
* Getter method for the current number of steps
*
* @return the current number of steps
*/
public int getNumberOfSteps(){
をあなたのコードを追加します。 //ここにコードを追加してください
}
/**
* Setter method for currentSelectedColor
*
* @param val
* the new value for currentSelectedColor
*/
public void setCurrentSelectedColor(int val) {
//ここにコード
}
/**
* Getter method for currentSelectedColor
*
* @return currentSelectedColor
*/
public int getCurrentSelectedColor() {
//が
}
/** ここにコードを追加します//ここにコード
}
/**
* Getter method for the model's dotInfo reference
* at location (i,j)
*
* @param i
* the x coordinate of the dot
* @param j
* the y coordinate of the dot
*
* @return model[i][j]
*/
public DotInfo get(int i, int j) {
を追加* metod ステップはステップ数を更新します。支払人が新しい色を選択した後にモデルが更新されたら、それは *と呼ばれなければなりません。 */ ます。public voidステップ(){
//は、 *であることを、
は}
/** は* metod が終了したゲームの場合はtrueリターンをisFinishedここにコードを追加します。すべてのデータがキャプチャされます。 * * @return真のゲームが終了した場合は、そうでない場合はfalse */ 公共ブールはisFinished(){
//ここに/ **
}
をあなたのコードを追加するには、*文字列を作成しますモデルのモデル * * @return String表現の表現*/ パブリック文字列のtoString(){
// YOUR Cを追加ODE HERE
}
}
で動作します;' –
私は残念ながら –
をリストを使用することはできませんので、これは宿題であることがありますか? –