python 控制台 猜谜语闯关游戏

import random


class Riddle:
    def __init__(self, question, answer):
        self.__question = question
        self.__answer = answer

    def getQuestion(self):
        return self.__question

    def isRight(self, answer):
        if self.__answer == answer:
            return True
        else:
            return False


class Riddles:

    @staticmethod
    def riddles():
        riddles = []
        riddles.append(Riddle("山上还有山,打一字", "出"))
        riddles.append(Riddle("十张口,一颗心,打一字", "思"))
        riddles.append(Riddle("说它小,下边大 说它大,上边小,打一字", "尖"))
        riddles.append(Riddle("一只黑狗,不叫不吼,打一字", "默"))
        riddles.append(Riddle("差一点六斤,打一字", "兵"))
        riddles.append(Riddle("家中添一口,打一字", "豪"))
        riddles.append(Riddle("自小在一起,目前少联系,打一字", "省"))
        riddles.append(Riddle("点点成金,打一字", "全"))
        riddles.append(Riddle("一人一张口,下面长只手,打一字", "拿"))
        riddles.append(Riddle("四面都是山,山山都相连,打一字", "田"))
        return riddles


class Game:
    def __init__(self, num):
        self.num = num
        self.count = 0

    def getRiddles(self):
        riddles = Riddles.riddles()
        myRiddles = random.sample(riddles, self.num)
        return myRiddles


def main():
    game = Game(5)
    myRiddles = game.getRiddles()
    lens = (len(myRiddles))
    for i in range(lens):
        answer = input("请猜谜语:" + myRiddles[i].getQuestion() + ":")
        if myRiddles[i].isRight(answer):
            print("恭喜您答对了!")
            game.count += 1
        else:
            print("真可惜,打错了!")
            print("太可惜了!闯关失败!")
            break
        if game.count == 5:
            print("恭喜您,闯关成功!")
            break
    print("本次闯关您猜对了", game.count, "个谜语")


main()
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇