Hi guys,
I am having a problem with the following code:
#Health set here
def win():
import time
print "You win!"
print "Thanks for playing"
time.sleep(10)
quit()
def lose():
import time
print "You lose!"
print "Thanks for playing"
time.sleep(10)
quit()
from random import randint
pos_damage = randint(15,472)
en_health = 1000
pl_health = 1000
#Define Caves
cave_p1 = "This part of the cave seems quite, strange, it is rather dark too."
cave_p2 = "There is not much here, quite....blank."
cave_p3 = "Rocky area, i'm afraid you might not make it without something"
#Use modules
import os, random
from time import sleep
#Menu
name = raw_input('State your name > ')
print "Welcome,", name, "\n[a] Start\n[b] Quit"
usr_chce = raw_input("> ")
if usr_chce == "a" or "A":
#Game starts *here*
print "You stand on an island, which cave do you go to ?\nType 'help' for a list of commands"
usr_choice = raw_input('>')
if usr_choice == "help":
print "(1) Type Attack to attack"
print "(2) Type Skip to skip attack\n(3) Type explore to explore caves"
if usr_choice == "fight":
for fight in range (9000):
print "Enemies Health:", en_health
print name, "Health:", pl_health
pl_move = raw_input('FIGHT>>')
if pl_move == "attack" or "Attack" or "ATTACK":
print "You attack!"
#Players move
en_health = en_health - pos_damage
if en_health < 1:
win()
break;
#Computers move
comps_choices = ["true", "false"]
comps_choice = random.choice(comps_choices)
if comps_choice == "true":
print "Computer attacks!"
pl_health = pl_health - pos_damage
if pl_health < 1:
lose()
if comps_choice == "false":
print "Computer skips!"
if pl_move == "skip" or "Skip" or "SKIP":
print "You skip!"
if pl_health < 1:
lose()
break;
if pl_move == "":
print "Invalid Move. Lose 100 life."
pl_health = pl_health - 100
else:
print "INVALID MOVE. LOSE 100 LIFE"
pl_health = pl_health - 100
(I know putting the "fight" part into a loop was stupid; but it was for experimental purposes)
State your name > fnewfewfwewfewfewfwnaiv!osgAy
Welcome, fnewfewfwewfewfewfwnaiv!osgAy
[a] Start
[b] Quit
> a
You stand on an island, which cave do you go to ?
Type 'help' for a list of commands
>fight
Enemies Health: 1000
fnewfewfwewfewfewfwnaiv!osgAy Health: 1000
FIGHT>>attack
You attack!
Computer skips!
You skip!
INVALID MOVE. LOSE 100 LIFE
Enemies Health: 633
fnewfewfwewfewfewfwnaiv!osgAy Health: 900
FIGHT>>attack
You attack!
Computer skips!
You skip!
INVALID MOVE. LOSE 100 LIFE
Enemies Health: 266
fnewfewfwewfewfewfwnaiv!osgAy Health: 800
FIGHT>>
You attack!
You win!
Thanks for playing - COPYRIGHT NAVID MOMTAHEN
See the problem? If the player enters random stuff, or a blank line, it by default attacks or skips...Why?