在上一期我们用Python实现了一个逃脱游戏的游戏,这一期我们继续使用Python实现一个简单的饥饿的毛毛虫游戏,让我们开始今天的旅程吧~

饥饿的毛毛虫游戏在Python免费源代码

介绍

这 饥饿的毛毛虫游戏在python 是一个以 python 程序设计语言。该项目包含演示实际游戏玩法的基本功能。此应用程序包含各种形状和彩色背景。该项目将使正在学习IT相关课程的学生受益。这 饥饿的毛毛虫游戏 提供初学者可以轻松理解的简单代码。这 饥饿的毛毛虫游戏在蟒蛇 提供有关如何编程的基本示例 python 编程。

这 饥饿的毛毛虫游戏在Python免费源代码 可以免费下载,只需阅读下面的内容以获取更多信息。此应用程序适用于 仅教育目的.

饥饿的毛毛虫游戏在Python免费源代码 基本信息

  • 使用的语言: python
  • 使用的编码工具: 内置 Python IDLE
  • 类型: 桌面应用程序
  • 使用的数据库: 没有

关于饥饿的毛毛虫游戏

这 饥饿的毛毛虫游戏 仅使用构建 python 程序设计语言。此应用程序是一种用户友好的系统,可以轻松满足您的需求。该应用程序提供了一个可供玩家玩的简单功能。玩家可以使用键盘绑定(左箭头键向左移动,右箭头键向右移动,向上箭头键向上移动,向下箭头键向下移动)玩游戏。游戏玩法非常简单,玩家必须用绿叶喂饥饿的毛毛虫。绿色在不同的位置生成,你必须让它获得分数。毛毛虫每次吃一片叶子,它的长度就会增加,而且时间越长,移动就越困难。

饥饿的毛毛虫游戏在Python免费源代码 特征

  • 基本图形用户界面
    • 该项目包含显示应用程序实际图像的基本 GUI。
  • 基本功能
    • 该项目包含使应用程序按预期工作的基本功能。
  • 用户友好的界面
    • 该项目是在一个简单的用户友好的界面Web应用程序中设计的,以便您轻松修改。

示例应用程序屏幕截图:

饥饿的毛毛虫游戏在Python免费源代码安装指南

  1. 首先,您需要下载并安装Python IDLE,这里是链接“https://www.python/downloads/”。
  2. 下载此站点中的源代码。
  3. 找到并解压缩 zip 文件。
  4. 打开解压缩的文件夹
  5. 找到 .py 文件。
  6. 然后通过python IDLE或任何支持python语言的IDE打开文件。
  7. 运行 .py 文件以启动程序。

仅此而已, 饥饿的毛毛虫游戏 使用 创建的内容 python 语言。我希望这个项目可以帮助您找到所需的内容。欲了解更多信息 项目和教程 请访问本网站。享受编码!

这 饥饿的毛毛虫游戏在Python免费源代码 已准备好下载,只需单击下面的下载按钮。

源码

def outside_window():
    left_wall = -t.window_width()/2
    right_wall = t.window_width()/2
    top_wall = t.window_height()/2
    bottom_wall = -t.window_height()/2
    (x,y) = caterpillar.pos()
    outside = x < left_wall or  x > right_wall or  y < bottom_wall or y > top_wall
    return outside

def game_over():
    caterpillar.color('yellow')
    leaf.color('yellow')
    t.penup()
    t.hideturtle()
    t.write('GAME OVER!',align='center' , font=('Aerial',30,'normal'))

def display_score(current_score):
    score_turtle.clear()
    score_turtle.penup()
    x = (t.window_width() / 2)-50
    y = (t.window_height() / 2)-50
    score_turtle.setpos(x,y)
    score_turtle.write(str(current_score) , align = 'right',font=('Arial',40,'bold'))

def place_leaf():
    leaf.hideturtle()
    leaf.setx(rd.randint(-200,200))
    leaf.sety(rd.randint(-200,200))
    leaf.showturtle()

def start_game():
    global game_started
    if game_started:
        return
    game_started = True

    score = 0
    text_turtle.clear()

    caterpillar_speed = 2
    caterpillar_length = 3
    caterpillar.shapesize(1,caterpillar_length,1)
    caterpillar.showturtle()
    display_score(score)
    place_leaf()

    while True:
        caterpillar.forward(caterpillar_speed)
        if caterpillar.distance(leaf)<20:
            place_leaf()
            caterpillar_length = caterpillar_length + 1
            caterpillar.shapesize(1,caterpillar_length,1)
            caterpillar_speed = caterpillar_speed + 1
            score = score + 10
            display_score(score)
        if outside_window():
            game_over()
            break

def move_up():
    if caterpillar.heading() == 0 or caterpillar.heading() == 180:
        caterpillar.setheading(90)

def move_down():
    if caterpillar.heading() == 0 or caterpillar.heading() == 180:
        caterpillar.setheading(270)

def move_left():
    if caterpillar.heading() == 90 or caterpillar.heading() == 270:
        caterpillar.setheading(180)

def move_right():
    if caterpillar.heading() == 90 or caterpillar.heading() == 270:
        caterpillar.setheading(0)

下载

饥饿的毛毛虫

更多推荐

python趣味编程-饥饿的毛毛虫游戏