Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3758398
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:09:20+00:00 2026-05-19T10:09:20+00:00

How can I increment an enumeration? I have a game that uses enumeration to

  • 0

How can I increment an enumeration?

I have a game that uses enumeration to get the points for killing an enemy, and 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 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T10:09:21+00:00Added an answer on May 19, 2026 at 10:09 am

    This design is not very object-oriented. A better approach would be to have an IEnemy interface. That interface would require a method of GetScore (presumably among others). That method could then return the value of the enemy. Then you have a separate class for each of your enemies that implements the IEnemy interface.

    public interface IEnemy{
       int GetScore();
    }
    
    public class Martian : IEnemy{
       int GetScore(){ return 10; }
    }
    
    public class Vesuvian : IEnemy{
       int GetScore(){ return 20; }
    }
    ...
    

    This has many benefits over using an enumeration, for example you can have enemies that have the same score but different other attributes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I increment a Integer's value in Java? I know I can get
Every time that I want to do a Layout, I'm getting a black layout
I want to know if I can create an Identity (auto increment on a
I have table with auto increment primary key. I want insert a bunch of
If all tables I want to delete from have the column gamer_id can i
In Vim I can :set wrapscan so that when I do an incremental search,
Can somebody point me to a resource that explains how to go about having
Can a LINQ enabled app run on a machine that only has the .NET
Can I get a 'when to use' for these and others? <% %> <%#
Can increment of a register (in a loop) be used to determine the (effective)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.