473,413 Members | 1,799 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,413 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 2368
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

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

Similar topics

4
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...
6
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...
15
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...
12
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...
31
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...
6
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 =...
5
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...
9
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
5
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.