import random
import time
class Dragon:
def __init__(self):
# 游戏完成标志
self.gameIsDone = False
print(
"You are in a land full of dragons.In front of you,you see two caves.the dragon is friendly and will share his "
"treasure with you.The other dragon is greedy and hungry,and will eat you on sight.")
# 电脑洞穴号码
self.num = random.randint(1, 2)
def choose_cave(self):
# 玩家选择洞穴
try:
chosen = int(input("Which cave will you go into?(1 or 2)"))
except Exception:
print('please check your number and retry!')
return self.choose_cave()
else:
if (chosen != self.num) and (chosen in [1, 2]):
print("You approach the cave......")
time.sleep(2)
print("It is dark and spooky......")
time.sleep(2)
print("A large dragon jumps out in front of you!He opens his jaws and ......")
time.sleep(2)
print("Gobbles you down in one bite!")
elif chosen == self.num:
print("You approach the cave......")
time.sleep(2)
print("It is dark and spooky......")
time.sleep(2)
print("A large dragon jumps out in front of you!He opens his jaws and ......")
time.sleep(2)
print("Share his treasure with you.")
else:
print('please check your input and retry!')
return self.choose_cave()
def re_play(self):
a = input("Would you like try again?(yes/no)")
while True:
if a == 'yes' or a == 'y':
self.__init__()
return self.start_game()
elif a == 'no' or a == 'n':
print('Hope for your next replay!')
input("Press <ENTER> to exit")
break
else:
print("please re-input and retry!")
return self.re_play()
def start_game(self):
while self.gameIsDone is False:
self.choose_cave()
self.gameIsDone = True
print('\n')
self.re_play()
playDragon = Dragon()
playDragon.start_game()
Dragon
最新推荐文章于 2024-07-04 16:04:39 发布