Python推箱子V1.00

先拿资源:

百度网盘

链接:https://pan.baidu.com/s/1BK6UWMtaDkGGmZYim0APyg
提取码:

再来看效果:

Python推箱子V1.00

Python推箱子V1.00

Python推箱子V1.00

Python推箱子V1.00

最后看代码:

import pygame
import sys
import time
"""
空地:0
墙壁:1
障碍:2
目的地:3
箱子:4
玩家:5
玩家到达目的地:8
箱子到达目的地: 7
"""
"""
列表[i][j]: i-行(竖),j-列(横)
贴图[i][j]: i-x轴(横) , j-y轴(竖)
"""
游戏状态检测
result_flag = 0
定义游戏地图
init_game_list = []
箱子完成个数
xz = 0
页面检测
ym = 1  # 1.游戏页面 -1.说明页面

class Game(object):
    def __init_game_map_list__(self):
        global init_game_list, result_flag
        list1 = [1, 1, 1, 1, 1, 1, 1, 1]
        list2 = [1, 0, 0, 2, 0, 0, 0, 1]
        list3 = [1, 0, 0, 2, 0, 7, 0, 1]
        list4 = [1, 0, 0, 2, 0, 3, 2, 1]
        list5 = [1, 2, 0, 4, 0, 0, 0, 1]
        list6 = [1, 0, 4, 0, 0, 3, 0, 1]
        list7 = [1, 5, 0, 2, 2, 0, 0, 1]
        list8 = [1, 1, 1, 1, 1, 1, 1, 1]
        init_game_list = [list1, list2, list3, list4, list5, list6, list7, list8]

    def __event_hander__(self):
        global init_game_list, result_flag, xz, ym
        # test 是妥协的产物,for(for())嵌套无法退出导致down键循环运行(理论上right键也应该有这种问题,但是没有),test阻止循环
        test = 1
        for event in pygame.event.get():
            if event.type == pygame.QUIT:  # 关闭程序
                pygame.quit()
                sys.exit()
            if xz == 3:  # 判断胜利
                result_flag = 1
                print("游戏获胜")
            if event.type == pygame.MOUSEBUTTONDOWN:  # 判断重新开始
                x, y = pygame.mouse.get_pos()
                if x >= 300 and x = 710 and y = 0 and x = 700 and y

素材及其源码来源:

图片素材均为自制
源码没有原始借鉴,纯属原创。
作者之前创作过C语言版的推箱子,有三个关卡,可以选择关卡或者通关自动跳转下一关。

https://mp.csdn.net/editor/html/109370567

代码相对来说还算简洁,但是有两处妥协。
属于使用一些变量来解决一些莫名其妙的问题。

未来会做一些算法精进和新版本。

作品优点:
1.有便捷的说明书,不影响使用又美观。
2.素材丰富。
3.有便捷的重新开始功能

作品缺点:
1.关卡少,只有一关。
2.没有 “返回一步” 的功能。
3.没有良好的交互菜单。

Original: https://blog.csdn.net/may10/article/details/114602796
Author: 文件传渝助手
Title: Python推箱子V1.00

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/783533/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球