473,390 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 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."
  6. ranger_join = raw_input("\nWill you let him?(y/n)? ")
  8. if ranger_join == "y":
  9.     print "The ranger joins you on your trip.  Yay."
  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
  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."
  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
  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
  44.             elif health <= 0:
  45.                 print "You died.  Bet you wish you stayed at the inn.\n"
How do I stop that problem?
Oct 26 '07 #1
1 2366
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.

Oct 26 '07 #2

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

Similar topics

by: SoftComplete Development | last post by:
Recently the company SoftComplete Development http://www.softcomplete.com launched the new revolutionary release of software code protection tool. This is large and important step in the software...
by: Malcolm | last post by:
I'm writing a fight engine for a fantasy role-playing game. The program involves monsters of various types as well as player characters, using different weapons and also casting spells. There...
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
by: JoeC | last post by:
I have read books and have ideas on how to create objects. I often create my own projects and programs. They end up getting pretty complex and long. I often use objects in my programs they are...
by: Andrew Poulos | last post by:
If I code something like the following it results in a memory leak in IE (as Leak 0.5 tells me): var frm = document.createElement("FORM"); document.body.appendChild(frm); fDeleteForm =...
by: Scott | last post by:
I'm sorry if most of my question's seem "petty", but as I've said before, I need to know the petty just because I need to know. This question is more along the lines of just having you guys...
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
by: TheSaint | last post by:
Hi, I'm very new with classes. I still reading something around ;) I got started to try a concatenation of 2 type of string, which have a particular property to start with A or D. My class...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.