Python——青蛙旅行项目

'''
    青蛙旅行项目开发

    测试账号:qq  密码:11
    项目核心:随机
    作者:擎天小猪♥
'''

import os, sys, time, random

def index():

    while True:

        os.system("cls")

        print("\t\t欢迎体验青蛙旅行小游戏")

        print("* ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ *")

        print("\t\t1. 登录游戏")

        print("\t\t2. 退出游戏")

        print("* ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ *")

        choice = int(input("请输入选项: "))

        if choice == 1:

            # 登录

            login()

        elif choice == 2:

            #退出游戏

            input("客官走好...")

            sys.exit(1)

        else:

            input("选项有误,重新选择!")

            os.system("cls")

users = [

    ['qq', 11]

]

foods = list()  #食物列表

boxs = list()   #行李列表

state = False   #判断青蛙是否存在状态

count_food = 0   #统计缺食次数

count_box = 0   #统计缺行李次数

n = 3   #缺食/行李上限

num = 0   #记录等级经验值

frog_name = ''   #青蛙昵称

frog_grade = 0   #青蛙等级

grades = list()   #等级列表

base = 24   #基础经验值

#设置1~50关每关升级需要的经验值

for r in range(2, 51):

    t = r // 10 + 1

    groups = [r, t * base]

    grades.append(groups)

def login():

    while True:

        os.system("cls")

        print("\t\t登录界面")

        print("* ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ")

        userName = input("\t账号(R/r返回): ")

        if userName == 'R' or userName == 'r':

            break

        passWord = int(input("\t请输入选项: "))

        judge = False

        for u in users:

            if userName == u[0] and passWord == u[1]:

                judge = True

                break

        if judge:

            print("\t登录成功,跳转中...")

            time.sleep(1)

            main(userName)

        else:

            input("\t账号或密码错误,重新输入...")

            os.system("cls")



def main(userName):

    global state, frog_name, frog_grade

    while True:

        os.system("cls")

        print("\t\t青蛙旅行小窝")

        print("* ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ *")

        print("\t\t1. 领养一只青蛙")

        print("\t\t2. 查看食物行李")

        print("\t\t3. 查看青蛙状态")

        print("\t\t4. 提供行李食物")

        print("\t\t5. 注销登录")

        print("\t\t6. 退出游戏")

        print("* ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ *")

        choice = int(input("请输入选项: "))

        if choice == 1:

            #领养宠物

            if state:

                input("您已领取过一只青蛙,不可重复领取!")

            else:

                print("青蛙领养中,请稍后.")

                time.sleep(3)

                print("青蛙领养中,请稍后..")

                time.sleep(2)

                print("青蛙领养中,请稍后...")

                time.sleep(1)

                input("领养成功!按任意键继续-->")

                frog = ['小青蛙', 1]

                frog_name = frog[0]

                frog_grade = frog[1]

                for u in users:

                    if userName == u[0]:

                        u.append(frog)

                        if len(u) == n:

                            state = True

                        break       

            os.system("cls")

        elif choice == 2:

            #行李食物列表

            if not judges(userName):

                find()

        elif choice == 3:

            #青蛙信息及当前状态

            if not judges(userName):

                frog_state(userName) 

        elif choice == 4:

            #提供补助

            if not judges(userName):

                add()

        elif choice == 5:

            #注销

            print("游戏注销中,即将退出登录...")

            time.sleep(1)

            break

        elif choice == 6:

            #退出游戏

            input("主人走好...")

            sys.exit(1)

        else:

            input("选项有误,重新选择!")

            os.system("cls")

def judges(userName):

    global state

    result = False

    for u in users:

        if userName == u[0]:

            if len(u) == n:

                state = True

            else:

                state = False

    if not state:

        result = True

        input("尚未领取青蛙,请先前去领取宠物--》")

        os.system("cls")

    return result

def add():

    while True:

        os.system("cls")

        print("\t\t提供行李食物")

        print("\t\t用户可以增加多条记录")

        print("* ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ *")

        box = input("\t请添加行李(R/r返回): ")

        if box == 'R' or box == 'r':

            break

        food = input("\t请添加食物: ")

        # group = [box, food]

        print("\t添加中,请稍后...")

        time.sleep(1)

        boxs.append(box)

        foods.append(food)

        input("\t添加成功,任意键继续...")

        is_add = input("\t是否继续添加(y/n)?")

        if is_add == 'y':

            os.system("cls")

        elif is_add == 'n':

            break 

        else:

            input("选项有误,重新选择!")

            os.system("cls")

def find():

    print("剩余库存资源:")

    print("##########################")

    print("行李")

    for b in boxs:

        print(b)

    print("------------------------->")

    print("食物")

    for f in foods:

        print(f)

    print("##########################")

    input("任意键返回")



def frog_state(userName):

    global frog_grade, num, count_food, count_box, n

    states = [

        ['吃饭', 2, 3],

        ['睡觉', 9, 2],

        ['玩耍', 8, 1],

        ['出门', 3, 0],

        ['写作业', 2, 4]

    ]

    f_state = random.choice(states)

    judge_frog_grade = False

    for s in states:

        if f_state[0] == s[0]:

            num += s[2]

            break

    for g in grades:

        if frog_grade < g[0]:

            if num >= g[1]:

                frog_grade += 1

                num -= g[1]

                judge_frog_grade = True

                break

    os.system("cls")

    # print(num)

    print("* ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ *")

    print("\t\t宠物: ", frog_name)

    print("\t\t等级: ", frog_grade)

    print("\t\t宠物状态: ", f_state[0])

    if f_state[0] == '吃饭':

        if len(foods):

            eat = random.choice(foods)

            foods.remove(eat)

            print("\t\t宠物正在吃着热腾腾的", eat)

            count_food = 0

        else:

            count_food += 1

            # print(count_food)

            if count_food <= n:

                print("\t\t主人主人,没粮食啦!")

            else:

                for u in users:

                    if userName == u[0]:

                        # users.remove(u[2])

                        del u[2]

                        # count_food = 0

                        count_food = count_box = 0

                        break

                print("哎呀,青蛙饿的断气了...")

    elif f_state[0] == '睡觉':

        print("\t\t主人小点声,我在睡觉zzz")

    elif f_state[0] == '玩耍':

        print("\t\t宠物正在打闹中...")

    elif f_state[0] == '出门':

        if len(boxs):

            move = random.choice(boxs)

            boxs.remove(move)

            print("\t\t宠物拖着{}离家出走啦,赶紧找去...".format(move))

            count_box = 0

        else:

            # print("\t\t主人好穷啊,连行李都没有!")

            count_box += 1

            # print(count_box)

            if count_box <= n:

                print("\t\t主人好穷啊,连行李都没有!")

            else:

                for u in users:

                    if userName == u[0]:

                        # users.remove(u[2])

                        del u[2]

                        count_food = count_box = 0

                        # count_box = 0

                        break

                print("哎呀,青蛙出门没带行李,冻死啦...")

    elif f_state[0] == '写作业':

        # frog_grade += 1

        print("\t\t表现不错,给个大红花奖励一下!")

    if judge_frog_grade:

        print("\t\t恭喜你,宠物升级啦...")

    print("* ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ *")

    input("\t\t任意键返回...")

index()

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值