1

I want to make a small turn based game. I've only coded so far as to do my turn and my turn only. However, when I perform my turn I don't do any damage to the cpu and I don't heal myself when the option is taken.

import random
print("Let's play a turn based game")
print("Your moves are:")
print("")
print("1) Fire Blast(18 to 25 HP) 2) Aura Sphere(10 to 35 HP) 3) Recover(Recover 10 to 30 HP)")
print("You can go first")
playerHP = 100
cpuHP = 100
fireBlast = random.randint(18,25)
auraSphere = random.randint(10,35)
recover = random.randint(10,30)

while playerHP >= 0 or cpuHP >= 0:
    print("")
    print("You have",playerHP,"HP")
    print("I have",cpuHP,"HP")
    playerMove = input("Which move do you choose?   ")
     print("Initiate player's move!")
        if playerMove == "Fire Blast" or "fire blast":
                         cpuHP == cpuHP - fireBlast
                         print("You used Fire Blast! I now have",cpuHP,"HP")
        elif playerMove == "Aura Sphere" or "aura sphere":
                         cpuHP == cpuHP - auraSphere
                         print("You used Aura Sphere! I now have",cpuHP,"HP")
        elif playerMove == "Recover" or "recover":
                         playerHP == playerHP + recover
                         print("Healed! You now have",playerHP,"HP")
        else:
            print("You didn't choose a move...")
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
  • What is you question? See [help](https://stackoverflow.com/help/how-to-ask) to read what is a good question. What is your Python version? And quiclky you have indentation problems and '=' is not '==' – Rbtnk Nov 24 '15 at 08:54

2 Answers2

2

The first problem lies in the if-line:

if playerMove == "Fire Blast" or "fire blast":
    #(...)
elif playerMove == "Aura Sphere" or "aura sphere":
    #(...)
elif playerMove == "Recover" or "recover": 
    #(...)

The lower-case values won't work. When this will be executed, first the "Fire Blast" or "fire blast" part will be evaluated, resulting in "Fire Blast" value, as boolean or of two non-empty strings is the first string. Instead you should use:

if playerMove == "Fire Blast" or playerMove ==  "fire blast":
    #(...)
elif playerMove == "Aura Sphere" or playerMove == "aura sphere":
    #(...)
elif playerMove == "Recover" or playerMove == "recover": 
    #(...)

or to simplify things you can use lower():

playerMove = playerMove.lower()
if playerMove == "fire blast":
    #(...)
elif playerMove == "aura sphere":
    #(...)
elif playerMove == "recover": 
    #(...)

Second problem is the hp subtraction lines:

cpuHP == cpuHP - fireBlast
cpuHP == cpuHP - auraSphere
playerHP == playerHP + recover

THe == operator is used for comparing values. What you want is the asignment operator =:

cpuHP = cpuHP - fireBlast
cpuHP = cpuHP - auraSphere
playerHP = playerHP + recover
Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
0

Answer

Comparisons in python (to test if values are equal) are ==, assignments in python are =. You need to use cpuHP = cpuHP - fireBlast instead of cpuHP == cpuHP - fireBlast.

Your code, as pasted above, has some indentation errors in it.

You should be using two comparisons on either side of the or eg. x == y or a == b. A string always evaluates to true, so your first if will always run.

Tips (unsolicited advice)

You can use .lower() or .upper() to make your checks for strings easier. Eg:

x = input('stuff').lower()

or for better debugging:

x = input('stuff')
x = x.lower()

It can be really useful to wrap your program in a function, and break it down into smaller functions that help each other ("helper functions") because it allows you to do testing. Early on, the best way to do testing is using assert. Eg:

def execute_damage_move(dmg, hp):
    hp = hp - dmg
    return hp

fireBlastDmg = 20
cpuHP = 40

assert HP_after_damage_move(fireBlastDmg, cpuHP) == 20
# this statement tests to make sure the output of execute_damage_move is as expected

fireBlastDmg = 15
cpuHP = 75

assert HP_after_damage_move(fireBlastDmg, cpuHP) == 60
# this statement tests to make sure the output of execute_damage_move is as expected
NotAnAmbiTurner
  • 2,553
  • 2
  • 21
  • 44