Каков наилучший способ увеличить перечисление?C#

Место общения программистов C#
Ответить
Anonymous
 Каков наилучший способ увеличить перечисление?

Сообщение Anonymous »


Как увеличить перечисление?
У меня есть игра, в которой перечисление используется для получения очков за убийство врага, и я хочу, чтобы значение врага увеличивалось на 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
}
and the method to get the score called from another class when an enemy dies:

Код: Выделить всё

    public int GetScore() // The method that uses 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;
}
How can I do it? I can only come up with complicated ways to do this, that I don't think even works.
Also I was wondering, I have a highscore label that is updated if it is less than score, so the highscore becomes score. But when the application restarts, if the game is completed or if the player runs out of lives, the highscore resets back to zero. Is there a way to keep the highscore value in there, so the highest score is always there?


Источник: https://stackoverflow.com/questions/462 ... numeration
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»