public class Dungeon
{
private Tile[][] theDungeon;
public Dungeon()
{
theDungeon = new Tile[10][10];
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
theDungeon[i][j] = new Tile();
}
}
}
/* ************************************************************* */
public void addMonsters(Monster m, int x, int y)
{
if(x < 0 || x > 10)
System.out.println("Out of Range");
if(y < 0 || y > 10)
System.out.println("Out of Range");
// Add the monster
theDungeon[x][y].addTheMonster(m);
}
/* ***************************************************************** */
public void deleteMonsters(int x, int y)
{
// Gets the array of monsters at Dungeon[x][y]
Monster[] m_xy = theDungeon[x][y].getMonsters();
for(int i = 0; i < theDungeon[x][y].getSize(); i++)
{
m_xy[i].setLiveStatus(Monster.LiveStatus.DEAD);
System.out.println("Monster: "
+ m_xy[i] + " AT DUNGEON[" + x + "][" + y + "] GETS EATEN UP");
}
// Creating an empty array of Monster[] type:
Monster[] newMonsterArray = new Monster[100];
// Replace the Monster[] array of this TILE with an empty one
theDungeon[x][y].setMonsters(newMonsterArray);
theDungeon[x][y].setSize(0);
}
/* ***************************************************************** */
// Returns the 2D Array
public Tile[][] getTheDungeon()
{
return theDungeon;
}
/* ***************************************************************** */
public String toString()
{
String Str = "";
String contents = "";
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
contents = theDungeon[i][j].toString();
if(!contents.equals(""))
{
Str += String.format("DUNGEON[%d][%d] CONTAINS :: %n %s %n",i, j, contents);
}
else
{
//Str += String.format("DUNGEON[%d][%d] CONTAINS :: %n EMPTY %n",i, j);
}
}
}
return Str;
}
/* ***************************************************************** */
}
Tuesday, October 26, 2010
LabTest#2: Revised Solution -- Section 5 -- Class: Dungeon
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment