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

  • Home
  • SEARCH
  • 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 7500135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:04:39+00:00 2026-05-29T20:04:39+00:00

I am developing a game in which the user can turn on / off

  • 0

I am developing a game in which the user can turn on / off certain effects. These effects cause a drain on the users’ energy and various parts of the program must be able to check if an affect is active. Currently, I’m using an enum type to store and check the effects:

public static enum Effects { SUPER_FIRE, FIRE_SHIELD }

if (someEffect == Effects.SUPER_FIRE) {
    // Breath fire etc..
}

Saying this, I have to store other variables for each effect – such as the level required to use it or the rate at which it drains energy. So, the other method I thought of was to use a class:

public class SuperFire extends Effect {

    public static int levelRequired = 10;
    public static int drainRate = 5;        

    public boolean active() {
        // Check if it's active
    }

    public boolean activate() {
    }

    public boolean deactivate() {
    }

}


SuperFireEffect sfe = new SuperFire();
sfe.activate();
if (sfe.active()) {
    energyLevel -= sfe.drainRate;
}
sfe.deactivate();

Which implementation (or any other) is the best for this situation?

  • 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-29T20:04:42+00:00Added an answer on May 29, 2026 at 8:04 pm

    I hesitate to say “best” in any case, but it would appear that your second example is “better” in the “more flexible” meaning of the word.

    Of course, from your very small code snippets, you are not encapsulating the functionality very well, so it would appear you may wish to do some more design work first.

    In the end, you want to have the game code think in terms of the Effect base class and what it can do, and not have to know anything about the implementation of things like SuperFireEffect.

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

Sidebar

Related Questions

i'm developing a android game which uses libgdx and bullet physics engine. I can
I'm developing a game which is based around the user controlling a ball which
I am developing an iPhone game in which birds bounce. I have set up
I'm developing a sim game based on Theme Hospital, which is quite an old
i'm developing a game which contained some view (as memory card game) and i
I am developing an android game, in which i have some trains moving on
I am developing a game in which I have some game play screens, game
I am developing a Quiz game application which is being developed completely but at
I'm talking about ROOT's CINT . I've been developing a game in c++ which
I'm developing a game in which I want my image to reduce in size

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.