我不明白为什么这个游戏不工作。每当健康低于0时,它应该是游戏结束或获胜,但它只是跳过并进入底片。我的Python游戏不检查敌人是否死亡
这是我到目前为止的代码:
def Battle(E,H,S,PH):
print('Battle starting')
win = False
while win == False:
while True:
Answer = input('Attack(\033[0;37;41mA\033[0;0;0m) or Defend(\033[0;37;41mA\033[0;0;0m)')
if Answer == 'A':
D = randint(0, S)
PH = PH - D
print(E,'attacking')
print('deals',D,'damage')
print('you now have',PH,'health')
PA = randint(1,5)
print('you deal',PA,'damage')
H = H - PA
print('the ',E,' has',H,'health')
break
elif A == 'D':
D = randint(0, S-randint(0,2))
PH = PH - D
print(E,'atacking')
print('deals',D,'damage')
print('you now have',PH,'health')
break
if H <= 0:
print('You killed the',E)
win = True
break
elif PH <= 0:
GameOver()
底部的部分是当你失去应该退出和显示文本或赢位:
if H <= 0:
print('You killed the',E)
win = True
break
elif PH <= 0:
GameOver()
完整程序
#COPYRIGHT TYLER JAMES 2017
import random
from random import randint
#_________________________________________________________________
#_________________________________________________________________
print('\033[0;0;0m')
print('\033[0;30;42m <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>')
print('\033[0;30;42m <> <>')
print('\033[0;30;42m <> _ _______ _______ _______ _ ______ <>')
print('\033[0;30;42m <>(\ ( ____ \( ____ \( ____ \(( /|( __ \ <>')
print('\033[0;30;42m <>| ( | ( \/| ( \/| ( \/| \ (|| ( \ )<>')
print('\033[0;30;42m <>| | | (__ | | | (__ | \ | || | ) |<>')
print('\033[0;30;42m <>| | | __) | | ____ | __) | (\ \) || | | |<>')
print('\033[0;30;42m <>| | | ( | | \_ )| ( | | \ || | ) |<>')
print('\033[0;30;42m <>| (____/\| (____/\| (___) || (____/\|) \ || (__/OX)<>')
print('\033[0;30;42m <>(_______/(_______/(_______)(_______/|/ )_)(______/ <>')
print('\033[0;30;42m <> By Tyler James<>')
print('\033[0;30;42m <> <>')
print('\033[0;30;42m <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>')
print('\033[0;0;0m have Fun playing this game,i worked hard to make it thanks')
print('___________________________________________________________')
#_________________________________________________________________
#_________________________________________________________________
#DEFINITION OF GAMEOVER
def GameOver():
while True:
print('GAME OVER')
#DEFINITION OF GAMEOVER
def Battle(E,H,S,PH):
print('Battle starting')
win = False
while win == False:
while True:
Answer = input('Attack(\033[0;37;41mA\033[0;0;0m) or Defend(\033[0;37;41mD\033[0;0;0m)')
if Answer == 'A':
D = randint(0, S)
PH = PH - D
print(E,'attacking')
print('deals',D,'damage')
print('you now have',PH,'health')
PA = randint(1,5)
print('you deal',PA,'damage')
H = H - PA
print('the ',E,' has',H,'health')
break
elif A == 'D':
D = randint(0, S-randint(0,2))
PH = PH - D
print(E,'atacking')
print('deals',D,'damage')
print('you now have',PH,'health')
break
if H <= 0:
print('You killed the',E)
win = True
break
elif PH <= 0:
GameOver()
#DEFINITION OF QUIZ
def Quiz(Q,AN):
print(Q)
INP = input('Answer?')
if INP == 'debug42':
print('debug42')
elif INP != AN:
GameOver()
else:
print('CORRECT')
#DEFINITION OF QUIZ
#_________________________________________________________________
#_________________________________________________________________
#LEVEL 1
Name = input('What is your Name?')
print('Ok your name is','\033[0;37;41m',Name)
print('\033[0;0;0m')
print('You are in a small room with a door, opposite sits a dresser')
key = False
while True:
A = input('What do you do?')
if A == 'open door':
if key == True:
print('you try the key in the door')
print('it works, you open the door and walk through')
break
elif key == False:
print('The door wont open')
elif A == 'look door':
print('the door has a panel design and a keyhole on the right hand side')
elif A == 'look dresser':
print('their are two drawers')
elif A == 'open dresser':
print('there is nothing in the top drawer')
print('but in the second is a brass key')
key = True
elif A == 'help':
print('---------------------------------------------')
print('Commands')
print('open object...use object')
print('look object...describe object')
print('room...repeats the infomation given at start')
print('COMMANDS NEED TO BE\033[1m \033[4mLOWERCASE\033[0m NEVER USE \033[1m\033[4mCAPS\033[0m')
print('---------------------------------------------')
elif A == 'room':
print('You are in a small room with a door, opposite sits a dresser')
elif A == 'debug42':
break
else:
print('\033[0;37;41m Incorrect command or string', '\033[0;0;0m')
print('congrats you escaped the room')
#LEVEL 1
#_________________________________________________________________
#_________________________________________________________________
#LEVEL 2
print('____________________________________________')
print('A wise looking man walks up to you')
print('\033[1;33;40m"Here is 3 riddles get ONE wrong DIE!!"\033[0;0;0m')
Quiz('\033[1;33;40m"You will always find me in the past. I can be created in the present, But the future can never taint me. What am I?"\033[0;0;0m','history')
Quiz('\033[1;33;40m"Which vehicle is spelled the same forwards and backwards?"\033[0;0;0m','racecar')
Quiz('\033[1;33;40m"What is it that no man ever yet did see, which never was, but always is to be?"\033[0;0;0m','tomorrow')
print('\033[1;33;40m"Fine you can pass take these Jems, I wish you luck... If you ever make it out of this town "\033[0;0;0m')
print('\033[1;33;42m',Name,' got 5₪ (₪ = Ducat) \033[0;0;0m')
Money = 5
#LEVEL 2
#_________________________________________________________________
#_________________________________________________________________
#LEVEL 3
print('You enter a shop')
print('\033[1;33;40m"Welcome too my shop would you like to purchase a level 1 sword and sheild for 5₪?"\033[0;0;0m')
print('you have', Money,'₪')
print('you buy the item -5₪')
print('\033[1;33;42m',Name,'got a Sword[1] and Shield[1]')
print('you leave the shop')
print('_____________________________________________________')
Battle('Bat',10,5,50)
你得到什么错误?通常这个错误会告诉你发生了什么事。 –
它不会返回一个错误,它只是没有激活如果看看 – Catmantj
https://repl.it/FCtI/28 – Catmantj