猫史档案馆


【Python作品分享】猜数字 GuessNumber

用户:...SOKs...SOKs查看:3 回复:3 评论:3 创建时间:2020-04-08T15:01:46


【作品展示】

center_image

 

【作品介绍】

全部是本人自己敲代码敲出来的,没有用积木模式(测试积木模式无法运行本程序)。自带作弊、综合评分系统、难度选择系统等等。共计512行代码。注意:本猜数字和模版中的猜数字没有任何关系,这个是我原创的。

 

【作品源代码】

import random
import time
n = random.randint(0,100)
print('猜数字游戏,这个数不大于100。你整个游戏中只有20次机会。')
count = 19
countb = 1
chet = 0
chet = int(chet)
chc = 0
chc = int(chc)
bilm = 0
bbl = 0
score = "【计算失败】"
print('输入1选择简单,输入2选择普通或输入3选择困难。')
bbl = int(input('请输入难度选择代码:'))
if bbl == 666:
    print('你启动了炼狱难度,随机数将在-50到150间抽取。祝你好运!')
    n = random.randint(-50,150)
elif bbl == 1:
    print('你选择的难度为简单,随机数将在0-100间抽取。')
    n = random.randint(0,100)
elif bbl == 2:
    print('你选择的难度为普通,随机数将在0-110间抽取。')
    n = random.randint(0,110)
elif bbl == 3:
    print('你选择的难度为困难,随机数将在-10-110间抽取。')
    n = random.randint(-10,110)
else:
    print('系统无法识别难度代码,将默认选择普通。随机数将在0-110间抽取。')
    n = random.randint(0,110)
bilm = int(input('请输入你想玩的次数:'))
hhc = 1
while bilm > 0:
    ua = int(input('此次为第%s次。请输入你猜的数(不要输入非数字字符!):'% hhc))
    if ua == 86862323 and chet == 1:
        chc += 1
        print('作弊代码模式开启。')
        continue
    if chc == 1 and ua == 23238686:
        chc -= 1
        print('作弊代码模式关闭。')
    if ua == 8686868:
        print('[CONSOLE]已挂载模塊:CHEAT')
        print('[CONSOLE]来自模块"CHEAT"的消息:此作弊仅供测试使用,请不要随意启动。')
        chet += 1
        continue
    if chet == 1 and chc == 1:
        if ua == 8688668:
            print('作弊代码 SKIPGAME 已激活。')
            print('[CONSOLE]停止游戏。')
            print('[MODULE:CHEAT]本次游戏使用了作弊,不会生效。成绩对正式场合无效。3秒后结束游戏。')
            time.sleep(3)
            break
        if ua == 23333333:
            print('作弊代码 GETANSW 已激活。')
            print('[MODULE:CHEAT]激活测试作弊。答案为:%s。'% n)
            continue
        if ua == 32222222:
            print('作弊代码 CHEATSTO 已激活。')
            print('[MODULE:CHEAT]作弊功能已关闭。')
            chet -= 1
            continue
        if ua == 23233232:
            print('作弊代码 SKIPROUND 已激活')
            print('[MODULE:CHEAT]即将在2秒后跳过本回合。')
            bilm -= 1
            time.sleep(2)
            continue    
    if count == 0:
        print('你的机会耗尽了!')
        print('游戏失败。再接再厉!正确答案为:%s'% n)
        break
    if ua > n:
        print('猜大了。你还有%s次机会。'% count)
        count -= 1
        countb += 1
        continue
    elif ua < n:
        print('猜小了。你还有%s次机会。'% count)
        count -= 1
        countb += 1
        continue
    else:
        if countb >= 5:
            print('你要加油哦,用了%s次才猜对呢。'% countb)
        elif countb >= 3:
            print('不错不错,只用了%s次就猜对了!下次也要保持!'% countb)
        else:
            print('太棒了!你竟然只使用%s次就猜对了!这难道是巧合?'% countb)
    hhc += 1
    bilm -= 1
    if bbl == 1:
        n = random.randint(0,100)
    elif bbl == 2:
        n = random.randint(-10,100)
    elif bbl == 3:
        n = random.randint(-25,100)
    elif bbl == 666:
        n = random.randint(-50,150)
    if bilm == 0:
        print('你所设定的游玩次数已达到。')
        break
    else:
        continue  
print('如果觉得好玩,可以前往www.bytes-library.online查询更多信息。')
print('游戏由Bytes Library使用Python编写,版权所有。')
print('感谢您的游玩!')
print('此简体版本由Bytes Library承担翻译工作。访问我们的网站,加入我们的志愿团队。')
print('输入1退出,输入2查看本次游玩的详细信息与评分。')
exse = int(input('请输入退出选项:'))
if exse == 1:
    print('即将在3秒后退出游戏......')
    time.sleep(3)
if exse == 2:
    score == str(score)
    if count >= 18:
        score = "A++"
    elif count <= 17 and count >= 15:
        score = "A+"
    elif count <= 14 and count >= 10:
        score = "A"
    elif count <= 10 and count >= 5:
        score = "B+"
    elif count <= 5 and count >= 0:
        score = "B"
    print('--------------------')
    print('综合评分系统')
    if bbl == 666:
        print('你启动了炼狱难度等级!')
    chettr = "【无法获取信息】"
    if chet == 1:
        chettr = "是"
    else:
        chettr = "否"
    a = "【读取失败】"
    if bbl == 1:
        a = "简单"
    elif bbl == 2:
        a = "普通"
    elif bbl == 3:
        a = "困难"
    elif bbl == 666:
        a = "炼狱"
    else:
        a = "普通"
    print('你是否启动作弊:%s'% chettr)
    print('你总共玩了%s回合。'% bilm)
    print('你总共猜了%s次。'% countb)
    print('你选择的难度为%s。'% a)
    print('你的评分为%s 。'% score)
    print('游戏将在30秒后退出。')
    time.sleep(30)    

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
...SOKs...SOKs

打错了,是152行代码。

点赞0


评论


Sx_Sx_

emotion_编程猫_加油

点赞0


评论


蒟蒻OIer1048576蒟蒻OIer1048576

151行:

import time,threading,random


class Cat:
    def __init__(self,Type,name):
        self.Type = Type
        self.name = name
        self.hungryValue = 100
        self.happyValue = 100
        self.IQ = 50

    def cry(self):
        print('喵~呜~(伤心)')

    def happy(self):
        print('喵~(快乐)')

    def hungry(self):
        print('喵~咕噜噜~(饿了)')

    def study(self):
        print('喵~')
        self.IQ+=5

    def eat(self,food):
        self.hungryValue += food*3


class SingCat(Cat):
    def __init__(self, Type, name):
        self.Type = Type
        self.name = name
        self.hungryValue = 100
        self.happyValue = 100
        self.IQ = 100

    def sing(self):
        print('啦啦啦')
        evaluate = input('我唱的好不好啊?')
        if evaluate == '好':
            self.happyValue = min(100,happyValue+10)
            self.happy()
        elif evaluate == '不好':
            print('喵~我可能还需要学习')
            self.happyValue-=15
            self.IQ+=10


class CodeMao(SingCat):
    def __init__(self, Type, name):
        self.Type = Type
        self.name = name
        self.hungryValue = 100
        self.happyValue = 100
        self.IQ = 200

    def code(self,time):
        for i in range(int(time)):
            print('打代码ing')
            time.sleep(1)
        self.happyValue = min(100, happyValue+10)
        self.happy()
        self.IQ += 10


class AICodeMao(CodeMao):
    def __init__(self, Type, name):
        self.Type = Type
        self.name = name
        self.hungryValue = 100
        self.happyValue = 100
        self.IQ = 400

    def SuperStudy(self,times):
        for i in range(int(times)):
            IQ+=0.01
            time.sleep(0.005)


class Person:
    def __init__(self):
        self.food=0
        self.Cat=Cat('可爱','喵喵')
    def work(self):
        print('今天,你赚了¥200,买了10袋喵粮')
        self.food+=10

def see(person):
    while person.Cat.happyValue >= 0 and person.Cat.hungryValue >= 0:
        print('喵喵的饥饿值=', person.Cat.hungryValue)
        print('喵喵的开心度=', person.Cat.happyValue)
        print('喵喵的IQ=', person.Cat.IQ)
        time.sleep(5)

def catset(person):
    while person.Cat.happyValue >= 0 and person.Cat.hungryValue >= 0:
        time.sleep(3)
        person.Cat.happyValue -= 1
        if person.Cat.happyValue <= 20:
            person.Cat.cry()
            if person.Cat.happyValue <0:
                print('我这么伤心,你不来安慰我么?')
        person.Cat.hungryValue -= 2
        if person.Cat.hungryValue <= 20:
            person.Cat.hungry()
            if person.Cat.hungryValue < 0:
                print('我这么饿!')

def main(person):
    cls=1
    while person.Cat.happyValue >= 0 and person.Cat.hungryValue >= 0:
        a=input('请输入行为(1——玩耍)(2——学习)(3——喂食)(4——工作):')
        if a == '1':
            if cls>=1:
                person.Cat.happy()
                person.Cat.happyValue += 5
            if cls>=2:
                person.Cat.sing()
                person.Cat.happyValue += 5
            if cls>=3:
                person.Cat.code(random.randint(1,5))
        elif a == '2':
            if cls == 4:
                person.Cat.SuperStudy(random.randint(1, 5)*200)
            else:
                person.Cat.study()
        elif a == '3':
            person.Cat.eat(person.food)
        elif a == '4':
            time.sleep(3)
            person.work()
        if person.Cat.IQ >=400:
            print('恭喜你,喵喵已升级为AI编程猫')
            person.Cat = AICodeMao('可爱', '喵喵')
        elif person.Cat.IQ >= 200:
            print('恭喜你,喵喵已升级为编程猫')
            person.Cat = CodeMao('可爱', '喵喵')
        elif person.Cat.IQ >= 100:
            print('恭喜你,喵喵已升级为唱歌喵')
            person.Cat = SingCat('可爱', '喵喵')
        else:
            person.Cat = Cat('可爱', '喵喵')
        time.sleep(1.5)

p=Person()
a1=threading.Thread(target=see, args=(p,))
a2=threading.Thread(target=catset, args=(p,))
a3 = threading.Thread(target=main, args=(p,))
a1.start()
a2.start()
a3.start()

喵喵的进化

点赞0


评论