嗨,各位。我希望有人能帮助我弄清如何增加枚举值。我有一个游戏,用枚举来获取杀死敌人的分数,我想每次杀死一个敌人时,该敌人分数的值增加10。这是我用于枚举的代码:
public enum gamescore// Enumeration to hold the score values of the enemies
{
Martian = 10,
Vesuvian = 20,
Mercurian = 30,
Meteor = 50,
MotherShip = 100,
Destroyer = 200
}
当敌人死亡时,从另一个类中调用得分方法的方式:
public int GetScore()// The method that utilieses the enumeration to get the score for the enemy killed
{
if (this is Martian)
{
return (int)gamescore.Martian;
}
else if (this is Vesuvian)
{
return (int)gamescore.Vesuvian;
}
else if (this is Mercurian)
{
return (int)gamescore.Mercurian;
}
else if (this is Destroyer)
{
return (int)gamescore.Destroyer;
}
else if (this is Meteor)
{
return (int)gamescore.Meteor;
}
else if (this is Mothership)
{
return (int)gamescore.MotherShip;
}
return 0;
}
有什么建议吗?我只能想到一些复杂的方法来做这件事,我认为甚至都行不通。
此外,我想知道,如果高分标签小于分数,则更新高分标签,使其成为分数。但是当应用程序重新启动时,如果游戏完成或玩家没有生命了,高分将重置为零,有没有办法保持高分值,以便最高分始终存在?
感谢你们对我的问题的所有帮助,我真的很感激。
谢谢!