練習のためにJavaでローグライクを作ろうとしています。これは、床を生成するための私のコードです (現在は、端に壁のタイルがある大きな部屋です)。タイル配列の特定のタイルを壁タイルまたは床タイルに設定しようとしています。ただし、setTile メソッドを終了すると、メソッドに入る前の値に戻ります。私は気が狂ってしまいます。これが私のコードです:
public Floor(int width, int height) {
this.tiles = new Tile[(width+1)*(height+1)];
this.width = width;
this.height = height;
generateTiles();
boolean test = false;
}
public Tile getTile(int x, int y)
{
return tiles[y * width + x];
}
public void setTile(int x, int y, Tile tile)
{
Tile tileToSet = getTile(x,y);
tileToSet = tile;
}
private void generateTiles() {
for (int i = 0; i < tiles.length; i++)
{
tiles[i] = new Tile();
}
//make the top wall
for (int i = 0; i<width;i++)
{
setTile(i,0,new WallTile());
}
}
}