我编写了一款游戏塔防。我有3节课。
MoveableGameObject,Tower和Monster。我想将怪物的X坐标发送到Tower类。 getX的方法在MoveAbleGameObject类中。所以我的塔知道怪物何时在范围内。
我的问题是:如何将Monster的X坐标发送到Tower类。
这是我的代码:
public class MonsterDefense extends MoveableGameObject {
private MoveableGameObject target;
private int[][] tilemap;
private Vissenkom mygame;
private int hp;
public MonsterDefense (Vissenkom spel){
this.tilemap = tilemap;
setSprite("leuw");
setDirectionSpeed(90, 7);
mygame = spel;
hp = 100;
setX(0);
setY(280);
}
public class Tower extends MoveableGameObject {
private Vissenkom mygame;
private int prijs;
private int damage;
private int bereik;
}
public Tower(Vissenkom spel) {
mygame = spel;
setSprite("toren");
prijs = 100;
damage = 50;
}
答案 0 :(得分:1)
为什么不添加Tower方法getCoordinates(Monster)?
public class Tower extends MoveableGameObject{
public int getCoordinates(Monster x){
return x.X;
}
}
我认为您的Monster类有int X;
个值,您使用setX(0);