Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

CODE

Input input = gc.getInput();
            int xpos = Mouse.getX();
            int ypos = Mouse.getY();
            emu = "Enemy Life : " + enemyLife; 
            Life = "Your Life Is" + life;
            Mousepos = "X:" + xpos + "Y:" + ypos;
            //test
            test1 = "Test INT" + test1int;
            if(!repeatStop)
            {
                       //if this button is press, the damage will add up. When 
                        //pressed fight, it would start reducing the enemy health.

            if(input.isKeyPressed(Input.KEY_1))
            {
                test1int += 1;
            }

            }
            if((xpos>1007 &xpos<1297)&&(ypos>881 && ypos<971))
            {
                            //Fight button
                if(Mouse.isButtonDown(0)){
                    finishTurn=true;
                }
            }
                  //fight has started
            if(finishTurn==true)
            {
                         //this would reduce the enemy life
                if(floodControl1==false)
                {
                enemyLife-=test1int;
                }
                           //PROBLEM: Does not stop reducing! 

                           //the below code was not successful. It did not stop it //         from reducing further.
                if(test1int>10)
                {
                    floodControl1=true;
                }
            }

QUESTION: Ok now, this is what is does. When I press the key, 1, it adds up the damage to the enemy. When I press fight, It will then start to reduce the enemy's health. Now my problem is, it kept on reducing and deducting it until negative! How do I deduct it to my desired damage (My desired damage is the one when press key 1)?

share|improve this question

closed as too localized by Jari Komppa, Jonathan Hobbs, bummzack, Byte56, Nicol Bolas Sep 28 '12 at 15:27

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

4  
-1 This is not a question about game development, but about a basic programming problem. –  Markus von Broady Sep 28 '12 at 11:17
    
SystemNetworks. You really, really need to read the FAQ about what kinds of questions to ask here. I've told you this a few times, and you're still posting these localized-asking-for-code questions. That's not what this site is about. Please read and understand the FAQ. –  Byte56 Sep 28 '12 at 14:49

2 Answers 2

Just make a global field that records the damage to be dealt (the value obtained when pressing one), then when you press left, before decrementing the life, deduct the amount to decrement it with from the damage to be dealt value and check if that damage to be dealt value is still positive. When it becomes negative that means you've dealt enough damage and you should stop.

share|improve this answer
    
can you give me a code at least? I don't understand –  SystemNetworks Sep 28 '12 at 12:10

Your will stop decrementing enemyLife when the floodControl1 is set to true right?

And you do:

if(test1int>10)
{
    floodControl1=true;
}

test1int is incremented when you press the key 1. I can't see how you initialize the test1int variable in your code but assuming the following:

  • test1int = 0
  • I press the key 1 less than 10 times (so the value of test1int will be lower than 10)
  • I press the left click of the mouse

You will never stop decreasing your enemyLife variable since test1int < 10.

Here is a more natural way to do what you want:

if (floodControl1==false) {
    if (enemyLife - test1int < 0) { //check if reducing the enemyLife will not make it negative
        //stop decreasing
        enemyLife = 0;
        floodControl1 = true;
    } else {
        //continue decreasing
        enemyLife -= test1int;
    }
}
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.