Hey there guys. I was hoping someone would be able to help me figure out how to increment enumeration. I have a game that uses enumeration to get the points for killing an enemy, I want the value of the enemy to increment by 10 every time one of the enemies is killed. Here is the code I have for the enumeration:

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 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;
        }

Any suggestions? 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 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 any way to keep the highscore value in there so the highest score is always there?

I appreciate all your help with my questions guys, I really do.

Thanks!

My suggestion would be to make your code more OO. You should have something like a 'enemy' class, and derive new classes from this for each enemy. These could then have a method (GetValue maybe) that would return the value of that enemy.

As for your highscore problem, you'll need to store that value somewhere: a text file, in the properties, etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.