Recently, my friend and I began working on a text-based battle sequence (in console) on Python for a fantasy style game.
Overview
The way it works is that the user is presented with: the current situation of their Attack (Att) + HP (HP), and whoever has the higher Intellect (Inl) will go first. If the user goes first, they get given three options - attack, scare away and any other move. in the example I've used 'Bide your time'.
The opponent (who is not user controlled) then randomly picks between any 3 of their moves,with varying chances for it, and then carries it out.It should then switch back to the users turn, now regardless of whether one has a higher Intellect than the other.
This should continue alternating until one of the HPs are = 0. If the user defeats the opponent, then it should have the choice of absorbing one of the opponent's stats/attributes.
In the code, the 'battle' variable depends whether the battle is initiated or not. If the 'battle' is 1, the loop should continue, but if it is 0, then it should stop (the 0 is added after either you scare it away, or
The Problem:
Whenever I run the code, it just continues the loop regardless to anything that happens, and is continuously my turn.
- Have I misunderstood how while loops actually work?
Future Plans
I am planning to add different races (i.e dwarves, elves, orcs etc.) that will change the users HP, Attack and Intellect in a balanced way.
I am also planning to add classes, which will eventually replace the 'Bide your time' move with a class specific move.
Thanks for reading and in advance for any suggestions/fixes you make!
import random
import time
Att = 10
Inl = 5
HP = 100
OpAtt = 10
OpInl = 4
OpHP = 100
FirstMove = 1
OpFirstMove = 0
battle = 1
while battle == 1:
if Inl > OpInl:
FirstMove == 1
OpFirstMove == 0
else:
FirstMove == 0
OpFirstMove == 1
if FirstMove > OpFirstMove:
print("Your Current stats are:")
print("Attack:", Att)
print("HP:", HP)
time.sleep(2)
print("Your Opponent's current stats are:")
print("Attack:", OpAtt)
print("HP:", OpHP)
time.sleep(2)
print("Your turn!")
time.sleep(1)
else:
print("Your Current stats are:")
print("Attack:", Att)
print("HP:", HP)
time.sleep(2)
print("Your Opponent's current stats are:")
print("Attack:", OpAtt)
print("HP:", OpHP)
time.sleep(2)
print("Opponent's turn!")
time.sleep(1)
if FirstMove > OpFirstMove:
print("Select a move:")
Move1 = str(input(print("[A] Attack opponent\n[B] Bide your time\n[C] Try to scare your opponent off")))
if Move1 == 'A' or Move1 == 'a':
Hit1 = random.randint(1, 4)
if Hit1 == 4 or 3 or 2:
damageRand = random.randint(8, 12)
OpHP = OpHP - damageRand
print("Success!, Opponet's HP is now", OpHP, ".")
FirstMove == 0
OpFirstMove == 1
else:
print("Failure, no damage dealt.")
FirstMove == 0
OpFirstMove == 1
elif Move1 == 'b' or Move1 == "B":
print("You do nothing")
FirstMove == 0
OpFirstMove == 1
elif Move1 == "c" or "C":
Scare1 = random.randint(1, 7)
if OpHP > 71:
if Scare1 == 7 or 6:
print("Congratulations!, you scared the opponent away, however, this means you gained no loot.")
battle == 0
elif OpHP < 70:
if Scare1 == 7 or 6 or 5 or 4:
print("Congratulations!, you scared the opponent away, however, this means you gained no loot.")
battle == 0
else:
print("Failure, the opponent stands his ground")
FirstMove == 0
OpFirstMove == 1
if OpFirstMove > FirstMove:
OpMove1 = random.randint(1, 8)
if OpMove1 == 1 or OpMove1 == 2 or OpMove1 == 3 or OpMove1 == 4 or OpMove1 == 5:
OpHit1 = random.randint(1, 4)
if OpHit1 == 4 or 3 or 2:
damageRand = random.randint(8, 12)
HP = HP - damageRand
print("Your Opponent Attacks!, Your HP is now", HP, ".")
FirstMove = 1
OpFirstMove = 0
else:
print("Your Opponent failed to attack you, no damage received.")
FirstMove = 1
OpFirstMove = 0
elif OpMove1 == 6:
print("Your Opponent does nothing")
FirstMove = 1
OpFirstMove = 0
elif OpMove1 == 7 or OpMove1 == 8:
OpScare1 = random.randint(1, 7)
if HP > 71:
if OpScare1 == 7 or 6:
print("Aargh!, you were scared away, don't worry though, this has no bad affects.")
battle == 0
elif HP < 70:
if OpScare1 == 7 or 6 or 5 or 4:
print("Aargh!, you were scared away, don't worry though, this has no bad affects.")
battle == 0
else:
print("Your Opponent tried to scare you away, but failed")
FirstMove = 1
OpFirstMove = 0
else:
print("Pies are tasty")
if OpHP < 1:
print ("Congratulations! You deafeated your Opponent, which one of their stats would you like to absorb?")
print("Your Opponent's current stats are:")
print("Attack:", OpAtt)
print("HP:", OpHP)
print ("Intellect:", OpInl)
absorb1 = print (str(input("[A] Intellect\n[B] Attack\n[C] HP\n[D] None of the above")))
if absorb1 == "a" or absorb1 == "A":
Inl == OpInl
print ("Opponent's intellect absorbed")
elif absorb1 == "b" or absorb1 == "B":
Att == OpAtt
print ("Opponent's Attack absorbed")
elif absorb1 == "c" or absorb1 == "C":
HP == OpHP
print ("Opponent's HP absorbed")
elif (absorb1 == "d" or absorb1 == "D"):
print ("None of your Opponent's stats absorbed")
print("Your current stats are:")
print("Attack:", Att)
print("HP:", HP)
print ("Intellect:", Inl)
elif HP < 1:
print ("Oh no! You were defeated by your Opponent!")
battle == 0