Monster HP goes down to about 20 then every Attack starts adding to Player and Monster HP. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

Monster HP goes down to about 20 then every Attack starts adding to Player and Monster HP.

In this code the player and monster exchange attacks until one of them dies but after the monster’s hp reaches about 20 they start add to each other’s health. Does anyone know a fix? Code in answers.

2nd Jan 2018, 5:36 PM
RuthlessDust
RuthlessDust - avatar
1 ответ
+ 2
php = 100 patk = 10 pdef = 2 matk = 10 mhp = 40 mdef = 2 #Turn variables Battle = False PlayerTurn = False PlayerMenu = False x = "Attack" MonsterTurn = False MonsterAtk = False #Battle code Battle = True while Battle == True: PlayerTurn = True #Performs Player operations. if PlayerTurn == True and MonsterTurn == False: PlayerMenu = True if PlayerMenu == True: #TODO: Add item state. print("Attack or Item?") #Player attack action if x == "Attack": PlayerMenu = False patk = patk - mdef mhp = mhp - patk print("Player attacked") print("Monster's HP: ") print(mhp) print("Player's HP:") print(php) MonsterTurn = True PlayerTurn = False #Performs Monster operations if MonsterTurn == True and PlayerTurn == False: MonsterAtk = True #Monster attack action if MonsterAtk == True: matk = matk - pdef php = php - matk print("Monster attacked.") print("Player's HP:") print(php) print("Monster's HP:") print(mhp) MonsterTurn = False PlayerTurn = True if php <= 0 and mhp > 0: print("Player died. Monster won.") Battle = False if mhp <= 0 and php > 0: print("Monster died. Player won.") Battle = False
2nd Jan 2018, 5:36 PM
RuthlessDust
RuthlessDust - avatar