栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

一个小游戏(.py)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

一个小游戏(.py)

制作一个.py小游戏 1.前言

制作方灰块工作室(别名:Lanpasby)(学而思学员:布布)
官方:https://code.xueersi.com/space/31023943?to=work

2.下载python

我这里使用的是3.7.4版本(64位)
下载网址https://www.python.org/

3.代码

引入easygui

import easygui

了解部分函数

import easygui
easygui.msgbox("Hello")
easygui.buttonbox("Hello",["Hi"])
easygui.choicebox("Hello",["Hi"])

具体代码展示

import easygui
import random
# 由灰块工作室制作
name = ["BuBu", "XiaoMing", "HuiKuai"]
background_Instruction = {"1": "bag", "2": "Food",
                          "3": "medicament", "4": "explore"}
food_Now, medicament_Now, Life_value, Satiety, healthy = 0, 0, 100, 100, 100
bag, food, medicament, explore = background_Instruction["1"], background_Instruction[                                                                     
    "2"], background_Instruction["3"], background_Instruction["4"]
bag_Now = food_Now, medicament_Now
the_medicament = 0
the_food = 0

"""
variable
"""

# enterbox
if __name__ == "__main__":
    name_Now = easygui.buttonbox("Which Name Do You Choose", "Name", [
        name[0], name[1], name[2]])
    y_n = easygui.buttonbox(
        "Whether to enter the novice tutorial", name_Now, ["Yes", "No"])
    if y_n == "Yes":
        easygui.msgbox("Ok!nHello," + name_Now)
        easygui.msgbox("You have 0 potions and 0 food")
        easygui.msgbox("Don`t be sad, I can help you")
        easygui.msgbox("Here you are foodnFood + 3")
        food_Now += 3
        easygui.msgbox("Start the game!")
    else:
        easygui.msgbox("Ok")
    while True:
        background_instruction = easygui.choicebox(
            "What do you doing?nSatiety:" + str(Satiety) + "n" + "Healthy:" + str(
                healthy) + "nLife_value: " + str(Life_value), name_Now, [bag, food, medicament, explore, "close game"])
        if background_instruction == bag:
            easygui.msgbox("Food:" + str(food_Now) + "n" +
                           "medicament:" + str(medicament_Now))
        if background_instruction == food:
            if food_Now >= 1:
                if Satiety >= 95:
                    food_Now -= 1
                    if healthy >= 70:
                        Satiety += 5
                        if Life_value >= 87:
                            Life_value += random.randint(7, 13)
                        easygui.msgbox("Satiety + 5")
                    elif 40 <= healthy <= 69:
                        Satiety += 3
                        if Life_value >= 87:
                            Life_value += random.randint(5, 10)
                        easygui.msgbox(
                            "Because the healthy < 70.So satiety + 3")
                    else:
                        Satiety += 2
                        if Life_value >= 87:
                            Life_value += random.randint(4, 9)
                        easygui.msgbox("Because you are ill.So satiety + 2")
            else:
                easygui.msgbox("You have no food")
        if background_instruction == medicament:
            if medicament_Now != 0:
                if healthy >= 70:
                    if Satiety >= 70:
                        healthy += 30
                        easygui.msgbox("healthy + 30")
                    elif 50 <= Satiety <= 69:
                        healthy += 25
                        easygui.msgbox("healthy + 25")
                    else:
                        healthy += 15
                        easygui.msgbox("healthy + 15,because the Satiety < 50")
            else:
                easygui.msgbox("You have no medicament")
        if background_instruction == explore:
            if healthy > 50:
                the_food = random.randint(2, 5)
                the_medicament_background_instruction = random.randint(0, 2)
                if the_medicament_background_instruction == 2:
                    the_medicament = random.randint(0, 1)
                else:
                    the_medicament = 0
                healthy -= random.randint(1, 10)
                Satiety -= random.randint(5, 8)
                Life_value -= random.randint(5, 12)
                food_Now += the_food
                medicament_Now += the_medicament
                easygui.msgbox(
                    "You get " + str(the_food) + " food(s) and " + str(the_medicament) + " medicament(s)")
            elif healthy < 50:
                easygui.msgbox("You are ill!")

        """
        over
        """
        if background_instruction == "close game":
            break
        if healthy <= 0 or Satiety <= 0 or Life_value <= 0:
            easygui.msgbox("Over.The healthy < 0")
            break

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/740583.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号