On 07/07/2013 06:40 PM, 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, so I 
need help. Here is the Python Shell output:

fire cannon 1
Fired!
Enemy health= 75
They fired at you!
Your health is now 55
fire cannon 2
Fired!
Enemy health= 75
They fired at you!
Your health is now 55
fire cannon 1
Fired!
Enemy health= 75
They fired at you!
Your health is now 55





Here is the code:

def lvl4combat():
     print "The barracks are constructed of wood and cobblestone."
     print "A large, single cannon sits on the top, searching the sky for enemy 
airships."
     print "The cannon is manned by a single team of three men."
     print "The cannon is large and industrial."
     print "Remember your training."
     cannonhealth=75
     cannondamage=random.choice([10,17,13])
     currhealth=health
     while cannonhealth > 0:
         print "They fired at you!"
         currhealth-cannonhealth
         print "Your health is now",currhealth
         combat=raw_input(">>")
         if combat.lower()=="fire cannon 1":
             print "Fired!"
             cannonhealth-attack

This expression has no useful effect.  You probably wanted

              cannonhealth -= attack

             print "Enemy health=",cannonhealth
         elif combat.lower()=="fire cannon 2":
             print "Fired!"
             cannonhealth-attack

ditto

             print "Enemy health=",cannonhealth
         if currhealth <= 0:
             break
             defeat1()
         if cannonhealth <= 0:
             break
             victory1()
             if kboost==True:
                 karma+25*.25

ditto

             elif kboost==False:
                 karma+25

ditto


You also have code following break statements that will never execute. In particular, you'll never call defeat1() or victory1()



--
DaveA

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

Reply via email to