📄 dungeon.java
字号:
package istarion.core;
import java.util.*;
public class Dungeon
{
public static final int NOWHERE = 0;
public static final int NORTH = 1;
public static final int SOUTH = 2;
public static final int EAST = 3;
public static final int WEST = 4;
public static final int NOTHING = 0;
public static final int WALL = 1;
public static final int FLOOR = 2;
private char[][] __maze = null;
private Mobile[][] __mobiles = null;
private Vector[][] __items = null;
private String __dungeonname = null;
private int __depth = 1; //the dungeon level
private int __startX = 0; //starting position for the player
private int __startY = 0;
private int __height = 0;
private int __width = 0;
/**
* Constructs a dungeon for istarion.
*/
public Dungeon(char[][] maze, String name, int level, int startx, int starty)
{
__maze = maze;
__height = __maze[0].length;
__width = __maze.length;
__items = new Vector[__width][__height];
__mobiles = new Mobile[__width][__height];
__dungeonname = name;
__startX = startx;
__startY = starty;
__depth = level;
}
public String getName()
{
return __dungeonname;
}
public int getHeight()
{
return __height;
}
public int getWidth()
{
return __width;
}
public void setDungeonLevel(int d)
{
__depth = d;
}
public int getDungeonLevel()
{
return __depth;
}
public int getStartingLocationX()
{
return __startX;
}
public int getStartingLocationY()
{
return __startY;
}
public boolean addMobile(Mobile m, int x, int y)
{
if (__mobiles[x][y] == null)
{
__mobiles[x][y] = m;
return true;
} else
return false;
}
public Mobile removeMobile(int x, int y)
{
Mobile retval = __mobiles[x][y];
__mobiles[x][y] = null;
return retval;
}
public void moveMobile(int sx, int sy, int tx, int ty)
{
if (__mobiles[tx][ty] != null)
throw new IllegalStateException(
"Zielort schon besetzt: " + tx + "|"+ ty);
addMobile(removeMobile(sx, sy), tx, ty);
}
public void addItem(Item i, int x, int y)
{
if (__items[x][y] == null)
__items[x][y] = new Vector();
__items[x][y].addElement(i);
}
public Vector getItems(int x, int y)
{
return __items[x][y];
}
public Mobile getMobile(int x, int y)
{
return __mobiles[x][y];
}
/**
* Returns whether the cell at the specified position
* blocks sight or not.
*/
public boolean isCellBlockingSight(int x, int y)
{
if ((x >= __width) || (x < 0) || (y >= __height) || (y < 0))
return true; //ausserhalb des dungeons kann man nicht gucken.
if (__maze[x][y] == Dungeon.WALL) return true;
return false;
}
/*
public char getCellFace(int x, int y)
{
char symbol = ' ';
//blocked cell? (e.g. wand?)
if (getStaticItem(x, y) > 0)
{
symbol = '#';
//color = Toolkit.COLOR_BLACK;
//free cell. stuff can be in here.
} else {
symbol = '.'; //free cell as default
//color = Toolkit.COLOR_BLACK;
Mobile mobile = getMobile(x, y);
//a mobile to draw?
if (mobile != null)
{
symbol = mobile.getSymbol();
//color = mobile.getColor();
//if not: an item to draw?
} else {
Vector items = getItems(x, y);
if ((items != null) && (items.size() > 0))
{
symbol = ((Entity)items.lastElement()).getSymbol();
//color = ((Entity)items.lastElement()).getColor();
}
}
}
return symbol;
}
*/
/**
* Returns the static item in the specified dungeon cell.
*/
public char getStaticItem(int x, int y)
{
if ((x >= __width) || (x < 0) || (y >= __height) || (y < 0))
return Dungeon.WALL; //ausserhalb des dungeons fels zur點kgeben.
else
return __maze[x][y];
}
/**
* Return whether the specified cell can be entered by a
* creature.
*/
public boolean isFree(int x, int y)
{
boolean retval = false;
if ((__maze[x][y] == Dungeon.FLOOR) && (__mobiles[x][y] == null)) retval = true;
return retval;
}
/**
* Calls act() on all mobiles in the dungeon.
*/
public void callAllMobiles()
{
Vector mobcop = new Vector();
for (int x = 0; x < getWidth(); x++)
for (int y = 0; y < getHeight(); y++)
{
if (__mobiles[x][y] == null) continue;
mobcop.addElement(__mobiles[x][y]);
}
int i;
for (i = 0; i < mobcop.size(); i++)
{
((Mobile)mobcop.elementAt(i)).act();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -