118 lines
2.4 KiB
Java
118 lines
2.4 KiB
Java
package org.artisanlogiciel.games;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
class LabyMap implements WallsProvider
|
|
{
|
|
|
|
Brick[][] tileMap;
|
|
LinkedList<Position> exits = new LinkedList<Position>();
|
|
|
|
public LabyMap(Brick[][] tileMap, LinkedList<Position> exits)
|
|
{
|
|
this.tileMap = tileMap;
|
|
this.exits = exits;
|
|
}
|
|
|
|
Brick getAt(int x, int y)
|
|
{
|
|
return tileMap[x][y];
|
|
}
|
|
|
|
public short getWalls(int x, int y)
|
|
{
|
|
return getAt(x, y).getWalls();
|
|
}
|
|
|
|
public int getWidth()
|
|
{
|
|
return tileMap[0].length;
|
|
}
|
|
|
|
public int getHeight()
|
|
{
|
|
return tileMap.length;
|
|
}
|
|
|
|
public String toString()
|
|
{
|
|
int entryX = -1;
|
|
int entryY = -1;
|
|
for (Position exit : exits)
|
|
{
|
|
if (exit.getX() == -1)
|
|
{
|
|
entryY = exit.getY();
|
|
}
|
|
if (exit.getY() == -1)
|
|
{
|
|
entryX = exit.getX();
|
|
}
|
|
}
|
|
String laby = "H";
|
|
for (int x = 0; x < tileMap.length; x++)
|
|
{
|
|
if (entryX == x)
|
|
{
|
|
laby += " H";
|
|
}
|
|
else
|
|
{
|
|
laby += "HH";
|
|
}
|
|
}
|
|
laby += "\n";
|
|
for (int y = 0; y < tileMap[0].length; y++)
|
|
{
|
|
if (entryY == y)
|
|
{
|
|
laby += ">";
|
|
}
|
|
else
|
|
{
|
|
laby += "H";
|
|
}
|
|
for (int x = 0; x < tileMap.length; x++)
|
|
{
|
|
laby += tileMap[x][y].getUpString();
|
|
}
|
|
laby += "\n";
|
|
laby += "H";
|
|
for (int x = 0; x < tileMap.length; x++)
|
|
{
|
|
laby += tileMap[x][y].getLowString();
|
|
}
|
|
laby += "\n";
|
|
}
|
|
return laby;
|
|
}
|
|
|
|
public String toShortString()
|
|
{
|
|
int entryX = -1;
|
|
int entryY = -1;
|
|
for (Position exit : exits)
|
|
{
|
|
if (exit.getX() == -1)
|
|
{
|
|
entryY = exit.getY();
|
|
}
|
|
if (exit.getY() == -1)
|
|
{
|
|
entryX = exit.getX();
|
|
}
|
|
}
|
|
String laby = "";
|
|
for (int y = 0; y < tileMap[0].length; y++)
|
|
{
|
|
for (int x = 0; x < tileMap.length; x++)
|
|
{
|
|
laby += "" + tileMap[x][y].getChar();
|
|
}
|
|
laby += "\n";
|
|
}
|
|
return laby;
|
|
}
|
|
|
|
}
|