我一直在python 3.5中制作基于文本的RPG。我很好(或者我认为......)直到我试着说不,我不想玩。而且当我想要选择从Mobs运行时,相反它将两者结合起来,并且说出你已经离开的伤害量。'我试图切换一些代码,但这让它变得更糟!我需要帮助。
import time
import random
import sys
import time
global gold
global player_HP
global Mob_HP_1
global Mob_HP_2
global Mob_HP_3
global Mob_HP_0
mob_HP_1 = 100
mob_HP_2 = 125
mob_HP_3 = 130
gold = 0
def Demon_attack():
global Mob_HP_3
Mob_HP_3 = 130
global gold
attack_damage=random.randint(50,200)
rewards=random.randint(1,5)
print('You do')
print(attack_damage)
print('damage!')
Mob_HP_3 = Mob_HP_3 - attack_damage
if Mob_HP_3 < 0:
print ('You killed the')
print ('Demon!')
if Mob_HP_3 > 0:
print('The Demon has')
print(Mob_HP_3)
print('HP left!')
choice_attack_3 = input('Do you attack?')
if choice_attack_3 == 'A'or 'a':
Demon_attack()
if choice_attack_3 == 'R' or 'r':
print('You run away!')
time.sleep (2)
battle_start()
time.sleep (3)
gold=gold+rewards
print('You have')
print(gold)
print('Gold!')
battle_start()
def Headless_Horseman_attack():
global Mob_HP_2
Mob_HP_2 = 125
global gold
attack_damage=random.randint(50,200)
rewards=random.randint(1,5)
print('You do')
print(attack_damage)
print('damage!')
Mob_HP_2 = Mob_HP_2 - attack_damage
if Mob_HP_2 < 0:
print ('You killed the')
print ('Headless Horseman')
if Mob_HP_2 > 0:
print('The Headless Horseman has')
print(Mob_HP_2)
print('HP left!')
choice_attack_2 = input('Do you attack?')
if choice_attack_2 == 'A' or 'a':
Headless_Horseman_attack()
if choice_attack_2 == 'R' or 'r':
print('You run away!')
time.sleep (2)
battle_start()
time.sleep (2)
gold=gold+rewards
print ('You have')
print(gold)
print('Gold!')
battle_start()
def Zombie_attack():
global Mob_HP_1
Mob_HP_1 = 100
global gold
attack_damage=random.randint(50,200)
rewards=random.randint(0,5)
print('You do')
print(attack_damage)
print('damage!')
Mob_HP_1 = Mob_HP_1 - attack_damage
if Mob_HP_1 < 0:
print ('You killed the')
print ('Zombie!')
if Mob_HP_1 > 0:
print('The Headless Horseman has')
print(Mob_HP_1)
print('HP left!')
choice_attack_1 = input('Do you attack?')
if choice_attack_1 == 'A' or 'a':
Zombie_attack()
if choice_attack_1 == 'R' or 'r':
print('You run away!')
time.sleep (2)
battle_start()
time.sleep (1.5)
gold=gold+rewards
print('You have')
print(gold)
print('Gold!')
battle_start()
def battle_start():
global gold
if gold > 50:
print ('You have killed all the monsters!')
play = input('Do you want to play again? Y/N?')
if choice == 'Y' or 'y':
game_start()
if choice == 'N' or 'a':
print ('Okay, battle later')
time.sleep(4)
sys.exit(0)
time.sleep (3)
attack_damage=random.randint(50,200)
rewards=random.randint(1,3)
mob=random.randint(1,3)
if mob==1:
mob_alive = True
print('You ran into a Zombie!')
print('The Zombie has 100 HP!')
choice_attack_1 = input('Do you attack?')
if choice_attack_1 == 'A' or 'a':
Zombie_attack()
if choice_attack_1 == 'R' or 'r':
print('You run away!')
time.sleep (2)
battle_start()
if mob==2:
mob_alive = True
print('You ran into a Headless Horseman!')
print('The Headless Horseman has 125 HP!')
choice_attack_2 = input('Do you attack?')
if choice_attack_2 == 'A' or 'a':
Headless_Horseman_attack()
if choice_attack_2 == 'R' or 'r':
print('You run away!')
time.sleep (2)
battle_start()
if mob==3:
mob_alive = True
print('You ran into a Demon!')
print('The Demon has 130 HP!')
choice_attack_3 = input('Do you attack?')
if choice_attack_3 == 'A' or 'a':
Demon_attack()
if choice_attack_3 == 'R' or 'r':
print('You run away!')
time.sleep (2)
battle_start()
def game_start():
global gold
global Mob_HP_0
Mob_HP_0 = 25
print('You have to get 50 Gold to win!')
attack_damage=random.randint(50,200)
rewards=random.randint(1,3)
print('To Attack, type "A". To Run Away, type "R". Lets pratice...')
print('Pratice Mob has 25 HP!')
choice_attack = input('Do you attack?')
if choice_attack == 'A' or 'a':
print('You do')
print(attack_damage)
print('damage!')
Mob_HP_0 = Mob_HP_0 - attack_damage
if choice_attack == 'R' or 'r':
print('You ran away!')
time.sleep (2)
game_start()
time.sleep (1.5)
gold = gold + rewards
print('You have ')
print(gold)
print('gold!')
print ('Good job')
print ('Lets start the battle...')
battle_start()
print ('Welcome to Battle Deongeons')
myName = input('Whats your name?')
print ('Ok ' + myName + ' you need to kill monsters... Be careful though, its capital Sentsive.')
choice = input("Do you want to play? Y/N")
if choice == "Y" or "y":
print('Lets start the Battle')
game_start()
if choice == "N" or "n":
print ('Okay, battle later')
time.sleep (4)
sys.exit(0)
答案 0 :(得分:1)
这是一个非常糟糕的问题,但是你不了解布尔逻辑而不是if语句。
If choice == "Y" or "y":
总是如此。这扩展到
If choice == "Y" or If "y":
你要么做一个不区分大小写的比较(如果是choice.lower()=&#34; y&#34;),列表比较(如果选择&#34; Yy&#34;)或明确说明两者您的eiterh方面的条件或(如果选择==&#34; y&#34;或选择==&#34; Y&#34;
答案 1 :(得分:0)
or
您需要在'a'
语句的另一侧添加choice_attack_3 ==。 if choice == "Y" or choice == "y":
print('Lets start the Battle')
game_start()
if choice == "N" or choice == "n":
本身在技术上是正确的,因此它同时输入if语句。
编辑:与
相同int newPixel