📄 mobile.java
字号:
package istarion.core;
import java.util.Vector;
/**
* A 'creature' in istarion.
* The abstract base class of all mobile things.
*/
public abstract class Mobile extends Entity
{
public static final int CURRENT = 0;
public static final int MAX = 1;
public static final int RESIST_HEAT = 0;
public static final int RESIST_COLD = 1;
public static final int RESIST_LIGHTNING = 2;
public static final int RESIST_POISON = 3;
private int[] __hitpoints = new int[2];
private int[] __mana = new int[2];
private int __attacke;
private int __parade;
private int __ruestung;
private int[] __resistances = new int[4];
/**
* A mobile having a speed of 8 may act exactly once every turn.
* The higher speed value, the more actions it has per turn.
*/
private int __speed;
private int __positionX;
private int __positionY;
private Dungeon __dungeon;
/**
* Protected constructor.
*/
protected Mobile(String n, char s, int c)
{
super(n, s, c);
}
/**
* This creature enters a dungeon.
* Adds the creature to the dungeon and positions itself onto
* the dungeon's starting location.
*/
public void enterDungeon(Dungeon d)
{
setDungeon(d);
setLocation(d.getStartingLocationX(), d.getStartingLocationY());
d.addMobile(this, d.getStartingLocationX(), d.getStartingLocationY());
}
public void setDungeon(Dungeon d)
{
__dungeon = d;
}
public Dungeon getDungeon()
{
return __dungeon;
}
public void setHitpoints(int hp)
{
__hitpoints[CURRENT] = hp;
}
public int getHitpoints()
{
return __hitpoints[CURRENT];
}
public void setHitpointsMax(int hp)
{
__hitpoints[MAX] = hp;
}
public int getHitpointsMax()
{
return __hitpoints[MAX];
}
/**
* Sets hp and hpmax to the specified value.
*/
public void initHitpoints(int starthp)
{
setHitpointsMax(starthp);
setHitpoints(starthp);
}
public void setMana(int mana)
{
__mana[CURRENT] = mana;
}
public int getMana()
{
return __mana[CURRENT];
}
public void setManaMax(int mana)
{
__mana[MAX] = mana;
}
public int getManaMax()
{
return __mana[MAX];
}
public void setLocation(int x, int y)
{
__positionX = x;
__positionY = y;
}
public int getXLocation()
{
return __positionX;
}
public int getYLocation()
{
return __positionY;
}
public void setAttacke(int a)
{
__attacke = a;
}
public int getAttacke()
{
return __attacke;
}
public void setParade(int p)
{
__parade = p;
}
public int getParade()
{
return __parade;
}
public void setRuestung(int rk)
{
__ruestung = rk;
}
public int getRuestung()
{
return __ruestung;
}
public void setSpeed(int s)
{
__speed = s;
}
public int getSpeed()
{
return __speed;
}
public void setResistance(int type, int value)
{
__resistances[type] = value;
}
public int getResistance(int type)
{
return __resistances[type];
}
public void hasPlayerContact(Player p)
{
}
/**
* Returns a vector containing all items the creature was carrying.
* Should be implemented by subclasses of Mobile.
*
* This is an empty default implementation.
*/
public Vector getLoot()
{
//drop gold coins per default?
return new Vector();
}
/**
* The actions of the Mobile when attacking another Mobile.
*/
public void attack(Mobile m)
{
doDamage(m);
}
/**
* Subclasses of mobile have to implement this, if the Mobile
* should deal damage on attacks.
* @returns the damage dealt on the specified mobile.
*/
protected int doDamage(Mobile m)
{
return 0;
}
/**
* Identifies itself as a Mobile.
*/
public int getEntityType()
{
return Entity.IS_MOBILE;
}
/**
* Tries to move the creature into the specified direction.
* @returns true if the move was successful. False otherwise.
*/
public boolean move(int direction)
{
if (direction == Dungeon.NORTH)
{
if (getDungeon().isFree(getXLocation(), getYLocation() - 1))
{
changePosition(Dungeon.NORTH);
return true;
}
} else if (direction == Dungeon.SOUTH) {
if (getDungeon().isFree(getXLocation(), getYLocation() + 1))
{
changePosition(Dungeon.SOUTH);
return true;
}
} else if (direction == Dungeon.EAST) {
if (getDungeon().isFree(getXLocation() + 1, getYLocation()))
{
changePosition(Dungeon.EAST);
return true;
}
} else if (direction == Dungeon.WEST) {
if (getDungeon().isFree(getXLocation() - 1, getYLocation()))
{
changePosition(Dungeon.WEST);
return true;
}
}
return false;
}
private void changePosition(int direction)
{
if (direction == Dungeon.NORTH)
{
getDungeon().moveMobile(
getXLocation(), getYLocation(),
getXLocation(), getYLocation() - 1
);
__positionY--;
} else if (direction == Dungeon.SOUTH) {
getDungeon().moveMobile(
getXLocation(), getYLocation(),
getXLocation(), getYLocation() + 1
);
__positionY++;
} else if (direction == Dungeon.EAST) {
getDungeon().moveMobile(
getXLocation(), getYLocation(),
getXLocation() + 1, getYLocation()
);
__positionX++;
} else if (direction == Dungeon.WEST) {
getDungeon().moveMobile(
getXLocation(), getYLocation(),
getXLocation() - 1, getYLocation()
);
__positionX--;
}
}
/**
* Executes an action (every game turn).
*/
public void act()
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -