471,596 Members | 786 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

Creating RPG fight code

Can someone please help with some code? I have been making a game, but there is a problem with one scenario. When the playable character encounters an NPC and they fight, the game keeps going until the NPC is dead, even though the Playable Character is dead.
Expand|Select|Wrap|Line Numbers
  1. ranger_health = 10
  2. ranger_damage = 4
  3. print "You head off down some small hills that go off the path."\
  4.       "\nYou encounter a lonely Ranger sitting on a stump.  He asks you if he can join your trip.  \nBear in mind, he will not fight for you."
  5.  
  6. ranger_join = raw_input("\nWill you let him?(y/n)? ")
  7.  
  8. if ranger_join == "y":
  9.     print "The ranger joins you on your trip.  Yay."
  10.  
  11. elif ranger_join == "n":
  12.     print "The ranger is offended and draws his sword.\n"
  13.     # attacking the ranger
  14.     weapon = raw_input("What weapon do you have? Oak Staff or Iron Sword? ")
  15.     #using the Oak Staff
  16.     if weapon == "oak staff":
  17.         attack = 3
  18.         print "\nYou draw your Oak Staff"
  19.         attack = 3
  20.         while ranger_health > 0:
  21.             ranger_health = ranger_health - attack
  22.             health = health - ranger_damage
  23.  
  24.             print "You're hero takes a swing and the ranger has", ranger_health, " health remaining."\
  25.                   "But you have", health, "hit points remaining\n"
  26.             if health <= 0:
  27.                 print "You died.  Bet you wish you stayed at the inn."
  28.  
  29.     # using the Iron Sword
  30.     elif weapon == "iron sword":
  31.         print "\nYou draw your Iron Sword"
  32.         attack = 5
  33.         while ranger_health > 0 or health > 0:
  34.             ranger_health = ranger_health - attack
  35.             health = health - ranger_damage
  36.  
  37.             print "You're hero takes a swing and the ranger has", ranger_health, " health remaining."\
  38.                   "But you have", health, "hit points remaining\n"
  39.             if ranger_health <= 0:
  40.                 print "It sucks"
  41.                 exit
  42.             #gain an item for defeating ranger
  43.  
  44.             elif health <= 0:
  45.                 print "You died.  Bet you wish you stayed at the inn.\n"
  46.  
How do I stop that problem?
Oct 26 '07 #1
1 2289
bartonc
6,596 Expert 4TB
looks like, on line #33, you should use and instead of or:
Expand|Select|Wrap|Line Numbers
  1. while ranger_health > 0 and health > 0:
Please note the use of CODE tags. You can see what the look like if you hit the Reply button. Instructions are also on the right hand side of the page when you post.

Thanks.
Oct 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by SoftComplete Development | last post: by
6 posts views Thread by Malcolm | last post: by
15 posts views Thread by Carlos Lozano | last post: by
12 posts views Thread by Mats Lycken | last post: by
31 posts views Thread by JoeC | last post: by
5 posts views Thread by Scott | last post: by
9 posts views Thread by =?Utf-8?B?YmJn?= | last post: by
5 posts views Thread by TheSaint | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.