On 07/07/13 23:40, Jack Little wrote:
When the player of my game fire his/her cannon, it is supposed to get
rid of some of the enemy's health. It does not. I have no clue what the
error is,

Its not entirely clear to me who is 'you' and who is 'the enemy'
Why does the enemy firing a cannon at me affect the enemy's
health? I see how it might affect my health but not the enemies
(it might affect their ammunition supplies but that's another story!)


     while cannonhealth > 0:
<snip...>

         if combat.lower()=="fire cannon 1":
             print "Fired!"
             cannonhealth-attack

I assume these lines are supposed to modify cannonhealth?
In fact they do nothing since you don't assign the result.
You probably want

>              cannonhealth -= attack


             print "Enemy health=",cannonhealth
         elif combat.lower()=="fire cannon 2":
             print "Fired!"
             cannonhealth-attack
             print "Enemy health=",cannonhealth
         if currhealth <= 0:
             break
             defeat1()

You do realize that code after a break will never be executed? The break immediately leaves the loop, it does not execute any further statements.


         if cannonhealth <= 0:
             break

same here. All following code is ignored.

             victory1()
             if kboost==True:
                 karma+25*.25

I doubt this does what you think it does. You should really get used to using the >>> prompt to try out things...

>>> 10+25*.25
16.25
>>> (10+25)*.25
8.75
>>> 10+(25*.25)
16.25
>>>

But since you don't assign the result to anything it's pretty harmless in that it has no impact on the code whatsoever except to waste some time.

             elif kboost==False:
                 karma+25

Same here. No assignment means no change.

To be honest, it kind of feels like you don't have any design for
this thing. You are just making it up as you go along. While evolution
is an amazing mechanism for random change it has the downside of
taking a very long time to produce useful results. If you plan to
progress quickly, design wins every time! Paper and pencils are
still effective tools.

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to