我正在使用libgdx Java Framework和Eclipse IDE设计游戏。
我定义了一个角色类。我想使用这个类来定义所有可能的角色,因为它包含可用于敌人,玩家和老板的属性。
然而,我无法弄清楚我是否应该延长课程或正确地完成课程。如果有人能让我开始朝着正确的方向前进,我们将不胜感激。
到目前为止,这是我在记事本中输入的内容(Eclipse尚未完全接受):
package com.mygdx.game;
public class Character
{
//variable declaration
private int health;
private int dmg;
private String image;
//constructor methods
public Character(int setHealth, int setDamage, String setImg)
{
health = setHealth;
dmg = setDamage;
image = setImg;
}
//movement methods
public void walkLeft()
{
}
public void walkRight()
{
}
public void jump()
{
}
public void hit(int damage)
{
health -= damage;
if (health <= 0)
{
//getWorld().removeObject(this);
//this is code that was written while I was using Greenfoot but Greenfoot works differently than a regular IDE so I need to adapt this code
}
}
public int attack()
{
return dmg;
}
}
以下是我想要创建为角色的类的示例。
public class SilverGeneral extends Character
{
private boolean alliesDead;
public void attackArrow()
{
dmg = 1
Arrow a = new Arrow();
getWorld().addObject(a, getX(), getY());
}
public void checkAllies()
{
if (alliesDead == false);
{
}
else
{
}
}
}