Dragon

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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值