だから私はジェネリッククラスとインターフェイスと私は間違って行ってきたかなり確信していない迷路を作ろうとしている。私の主な問題は、初めてクラスをパラメータとして持つため、コンストラクタを完成させる方法です。この汎用コンストラクタが動作するには何が必要ですか?
これは私の最初の投稿ですので、悪いとお詫び申し上げます。
import java.awt.Color;
public class Labyrinth implements ILabyrinth {
private int height;
private int width;
**********************************************
public Labyrinth(IGrid<LabyrinthTile> tiles){
tiles.copy();
this.height=height;
this.width=width; <---Here?
**********************************************
}
@Override
public LabyrinthTile getCell(int x, int y) {
return getCell(x,y);
}
@Override
public Color getColor(int x, int y) {
return getCell(x,y).getColor();
}
@Override
public int getHeight() {
return height;
}
@Override
public int getPlayerGold() {
return 0;
}
@Override
public int getPlayerHitPoints() {
return 0;
}
@Override
public int getWidth() {
return width;
}
@Override
public boolean isPlaying() {
return true;
}
@Override
public void movePlayer(Direction dir) throws MovePlayerException {
if(dir.equals(Direction.EAST)){
width+=1;
}
if(dir.equals(Direction.NORTH)){
height+=1;
}
if(dir.equals(Direction.SOUTH)){
height-=1;
}
if(dir.equals(Direction.WEST)){
width-=1;
}
}
@Override
public boolean playerCanGo(Direction d) {
if(d.equals(LabyrinthTile.WALL))
return false;
return true;
}
}
'tiles.copy()は何をしますか、タイルのコピーを返しますか?その場合はどこにも保存しませんでした。 – Alex
はい、どこに保存すればいいですか? – ruubel
タイルのコピーはどこに必要ですか?または、タイルのデータが必要なだけです。この場合、コピーは必要ありません。 – Alex