Python Forum
Question with while loop placement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question with while loop placement
#1
I'm trying to make a game that has a "fight" loop that it runs when the user encounters a demon. I pretty much have a basic version done but was wondering how to format a while loop so that the user keeps attacking until they or the enemy runs out of health. When I run the program I don't get any errors, it successfully randomizes critical attacks, regular attacks, and other stuff. If someone could help me understand how to make a while loop that keeps the attacks going. Any help would be appreciated, thanks!
import random

DemonOne = 0
DemonTwo = 1
DemonThree = 2
#DemonOneStats
DemonOneHealth = 25
DemonOnePower = 25
DemonOneLuck = 250
DemonOneLuckDisplayed = DemonOneLuck/10
DemonOneArmour = 10
DemonOneAttack = DemonOnePower/4
DemonOneAttackCalc = (DemonOneLuck/25) - 1
#DemonTwoStats
DemonTwoHealth = 50
DemonTwoPower = 50
DemonTwoLuck = 100
DemonTwoLuckDisplayed = DemonTwoLuck/2
DemonTwoArmour = 25
#DemonThreeStats
DemonThreeHealth = 100
DemonThreePower = 100
DemonThreeLuck = 50
DemonThreeLuckDisplayed = DemonThreeLuck * 2
DemonThreeArmour = 100
#UserStats
BaseHealth = 100
BaseLuck = 100
BaseLuckDisplayed = BaseLuck/2
BasePower = 100
Armour = 0
BaseAttack = BasePower/4
#FirstAttack
FirstAttackCalc = (BaseLuck/25) - 1
def stats():
    print("Health: " + str(BaseHealth), "Luck: " + str(BaseLuckDisplayed), "Power: " + str(BasePower), "Armour: " + str(Armour), "Weapon(s) equipped: " )
def DemonOneStats():
    print("The demon's stats are: Health- "+str(DemonOneHealth),"Luck- "+str(DemonOneLuckDisplayed), "Power- "+str(DemonOnePower), "Armour- " +str(DemonOneArmour))
def DemonTwoStats():
    print("The demon's stats are: Health- "+str(DemonTwoHealth),"Luck- "+str(DemonTwoLuckDisplayed), "Power- "+str(DemonTwoPower), "Armour- " +str(DemonTwoArmour))
def DemonThreeStats():
    print("The demon's stats are: Health- "+str(DemonThreeHealth),"Luck- "+str(DemonThreeLuckDisplayed), "Power- "+str(DemonThreePower), "Armour- " +str(DemonThreeArmour))

DemonChooser = random.randint(0,2)
FirstAttack = random.randint(0,FirstAttackCalc)
DemonOneCritical = random.randint(0,DemonOneAttackCalc)


#DemonOneFightLoop
if DemonChooser == 0:
    DemonOneStats()
    #while DemonOneHealth <= 0 or BaseHealth <= 0 is True:
    if FirstAttack != 0:
            DemonOneHealth = DemonOneHealth - BaseAttack
            print("You attack the demon first:")
            DemonOneStats()
            if FirstAttack == 2:
                DemonOneHealth = DemonOneHealth - BaseAttack
                print("You caught the enemy off guard! Critical hit!")
                DemonOneStats()
            elif FirstAttack == 0:
                BaseHealth = BaseHealth - DemonOneAttack
                print("You were unlucky and the demon attacked you first:")
                stats()
            if DemonOneCritical == 0:
                BaseHealth = BaseHealth - DemonOneAttack
                print("You were caught off guard by the demon! Critical hit!")
                stats()
elif DemonChooser == 1:
    DemonTwoStats()
elif DemonChooser == 2:
    DemonThreeStats()
Reply


Messages In This Thread
Question with while loop placement - by Tunechi - May-15-2018, 10:41 PM
RE: Question with while loop placement - by Larz60+ - May-16-2018, 01:47 AM
RE: Question with while loop placement - by Tunechi - May-16-2018, 02:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Preventing Duplicate Placement in 2D Array nickdavis2017 2 1,529 Feb-03-2022, 11:06 PM
Last Post: nickdavis2017
  A question about 'Event loop is closed' fc5igm 2 2,165 Oct-05-2021, 02:00 AM
Last Post: fc5igm
Exclamation question about input, while loop, then print jamie_01 5 2,616 Sep-30-2021, 12:46 PM
Last Post: Underscore
  for loop question KEYS 1 1,697 Oct-27-2020, 11:42 PM
Last Post: jefsummers
  Netmiko Loop question sc00ter 2 3,265 Oct-24-2020, 10:54 PM
Last Post: sc00ter
  while loop question KEYS 2 1,976 Sep-26-2020, 11:02 PM
Last Post: KEYS
  New to programming, loop question tomyan 1 1,590 Sep-25-2020, 04:32 PM
Last Post: Larz60+
  while loop question spalisetty06 2 1,814 Aug-13-2020, 04:18 PM
Last Post: buran
  question about for loop Than999 5 2,427 Jun-09-2020, 02:16 PM
Last Post: Emekadavid
  Data placement nboogerz 1 1,812 May-16-2020, 11:20 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020