当前位置: 首页 > news >正文

python推箱子游戏

'''
 ,--^----------,--------,-----,-------^--,
      `--------'     作者 yty
  `+---------------------------^----------
    `_,-------, _________________________
       XXXXXX `
      XXXXXX   `
     XXXXXX ______(
    XXXXXX
   XXXXXX
 (________(
  `------'
'''




'0'
[['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','0','0','0','0','0','0','0','0','0','0','0','0','0','1'],
['1','1','1','1','1','1','1','1','1','1','1','1','1','1','1']]

import time
one = time.time()

def find(ditu,thing):
    for i in range(0, len(ditu)):
        for j in range(0, len(ditu)):
            if ditu[i][j] == thing:
                return [i,j]

def show(ditu,a):
    a = find(ditu,'M')
    if ditu[a[0]][a[1]] == '4'  and a == 0 :
        show(ditu,a=-1)
        return -1

    for i in range(0,len(ditu)):
        for j in range(0,len(ditu)):
            if i == 0 or i == len(ditu)-1:
                print('■■',end='')
            elif ditu[i][j] == '0':
                print('  ',end='')
            elif ditu[i][j] == '1':
                print('▊▊',end='')
            elif ditu[i][j] == '4':
                print('▓▓',end='')
            elif ditu[i][j] == 'R':
                print('☹',end='')
            elif ditu[i][j] == 'M':
                print('░░',end='')
        print()
    return 0

'''
w向上移动
A向左移动
S向下移动
D向右移动
'''

def move(fx):
    # 向上移动
    if fx == 'W' :
        zb = find(ditu,'R')
        if ditu[zb[0]-1][zb[1]] == '0' :
            pepole_zb = find(ditu,'R')
            #将people坐标 向上更改
            ditu[zb[0]-1][zb[1]] = 'R'
            #将原坐标 更改
            ditu[zb[0]][zb[1]] = '0'
        elif ditu[zb[0]-1][zb[1]] == '4':
            box_zb = find(ditu,'4')
            print(ditu[box_zb[0]-1][box_zb[1]])
            if ditu[box_zb[0]-1][box_zb[1]] != '1':
                # box 向上更改
                ditu[box_zb[0] - 1][box_zb[1]] = '4'
                # 将原坐标 更改
                ditu[box_zb[0]][box_zb[1]] = '0'
                #移动人物坐标
                ditu[zb[0]][zb[1]] = '0'
                ditu[box_zb[0]][box_zb[1]] = 'R'


            # move('W',-1)
    elif fx == 'A' :
        zb = find(ditu, 'R')
        if ditu[zb[0] ][zb[1]-1] == '0':
            pepole_zb = find(ditu, 'R')
            # 将people坐标 向上更改
            ditu[zb[0]][zb[1]-1] = 'R'
            # 将原坐标 更改
            ditu[zb[0]][zb[1]] = '0'
        elif ditu[zb[0]][zb[1]-1] == '4':
            box_zb = find(ditu,'4')
            print(ditu[box_zb[0]][box_zb[1]-1])
            if ditu[box_zb[0]][box_zb[1]-1] != '1':
                # box 向上更改
                ditu[box_zb[0]][box_zb[1]-1] = '4'
                # 将原坐标 更改
                ditu[box_zb[0]][box_zb[1]] = '0'
                #移动人物坐标
                ditu[zb[0]][zb[1]] = '0'
                ditu[box_zb[0]][box_zb[1]] = 'R'
    elif fx == 'D' :
        zb = find(ditu, 'R')
        if ditu[zb[0] ][zb[1]+1] == '0':
            pepole_zb = find(ditu, 'R')
            # 将people坐标 向上更改
            ditu[zb[0]][zb[1]+1] = 'R'
            # 将原坐标 更改
            ditu[zb[0]][zb[1]] = '0'
        elif ditu[zb[0]][zb[1]+1] == '4':
            box_zb = find(ditu,'4')
            print(ditu[box_zb[0]][box_zb[1]+1])
            if ditu[box_zb[0]][box_zb[1]+1] == '0':
                # box 向上更改
                ditu[box_zb[0]][box_zb[1]+1] = '4'
                # 将原坐标 更改
                ditu[box_zb[0]][box_zb[1]] = '0'
                #移动人物坐标
                ditu[zb[0]][zb[1]] = '0'
                ditu[box_zb[0]][box_zb[1]] = 'R'
    elif fx == 'S' :
        zb = find(ditu, 'R')
        if ditu[zb[0]+1][zb[1]] == '0':
            pepole_zb = find(ditu, 'R')
            # 将people坐标 向上更改
            ditu[zb[0]+1][zb[1]] = 'R'
            # 将原坐标 更改
            ditu[zb[0]][zb[1]] = '0'
        elif ditu[zb[0]+1][zb[1]] == '4':
            box_zb = find(ditu,'4')
            print(ditu[box_zb[0]+1][box_zb[1]])
            if ditu[box_zb[0]+1][box_zb[1]] != '1':
                # box 向上更改
                ditu[box_zb[0]+1][box_zb[1]] = '4'
                # 将原坐标 更改
                ditu[box_zb[0]][box_zb[1]] = '0'
                #移动人物坐标
                ditu[zb[0]][zb[1]] = '0'
                ditu[box_zb[0]][box_zb[1]] = 'R'




if __name__ == '__main__':

    ditu = [
            ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'],
            ['1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '1'],
            ['1', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4', '0', '1'],
            ['1', '0', '1', '0', '0', '0', '1', '0', '1', '0', '1', '1', '0', '0', '0', '0', 'R', '0', '1'],
            ['1', '0', '0', '0', '0', '0', '1', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1'],
            ['1', '0', '1', '0', '0', '0', '1', '1', '1', '1', '1', '0', '1', '0', '0', '1', '0', '0', '1'],
            ['1', '0', '1', '0', '0', '0', '1', '0', '0', '0', '1', '0', '1', '0', '0', '1', '0', '0', '1'],
            ['1', '0', '1', '0', '0', '0', '1', '0', '0', '0', '1', '0', '1', '0', '0', '1', '0', '0', '1'],
            ['1', '0', '1', '0', '0', '0', '1', '0', '0', '0', '1', '0', '1', '1', '1', '1', '0', '0', '1'],
            ['1', '0', '1', '0', '1', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '1'],
            ['1', '0', '1', '0', '1', '0', '1', '1', '1', '1', '1', '0', '1', '0', '0', '1', '0', '1', '1'],
            ['1', '0', '1', '0', '1', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '1', '0', '1', '1'],
            ['1', '0', '1', '0', '1', '1', '1', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '1'],
            ['1', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '1'],
            ['1', '0', '1', '0', '1', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '1'],
            ['1', '0', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '0', '0', '1'],
            ['1', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1'],
            ['1', 'M', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '1'],
            ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1']
          ]
    while True:
        if show(ditu,a=0) == -1:
            tow = time.time()
            print(f'游戏结束 你一共用时 {int((tow - one)*100)/100}s')
            break
        else:
            zc = input('请输入操作 W↑  S↓  A←  D→ \n\n')
            move(zc)


文章转载自:

http://tTXA7znd.nxnrt.cn
http://7fwyECt0.nxnrt.cn
http://ZcNq4Bpa.nxnrt.cn
http://0t5ayzAr.nxnrt.cn
http://lI7WlSb6.nxnrt.cn
http://aysGT2Yj.nxnrt.cn
http://GQdi9doi.nxnrt.cn
http://XuQ6WgYs.nxnrt.cn
http://qXNwLlJ7.nxnrt.cn
http://2K8Yrsyk.nxnrt.cn
http://Lqv3d1uw.nxnrt.cn
http://GJMBGZK8.nxnrt.cn
http://ynJmKZRB.nxnrt.cn
http://UAfZWUGv.nxnrt.cn
http://4MXD4wmq.nxnrt.cn
http://tFGwC9Ne.nxnrt.cn
http://NvesPz4h.nxnrt.cn
http://tYG1MM94.nxnrt.cn
http://Gdq0RUr4.nxnrt.cn
http://OXoqVN4A.nxnrt.cn
http://MHFOgScY.nxnrt.cn
http://HNRSk5E2.nxnrt.cn
http://rPBT6gx5.nxnrt.cn
http://GwOEFiiR.nxnrt.cn
http://j26jsJAl.nxnrt.cn
http://dCkzHhrI.nxnrt.cn
http://cnjoUmS6.nxnrt.cn
http://0XWMK7OC.nxnrt.cn
http://oO3RWr81.nxnrt.cn
http://ZI3dkf9f.nxnrt.cn
http://www.dtcms.com/a/127887.html

相关文章:

  • Linux进阶命令
  • Linux 进程内存监控:Linux 内存调优之进程内存深度监控
  • 使用freebsd-update 升级FreeBSD从FreeBSD 14.1-RELEASE-p5到FreeBSD 14.2-RELEASE
  • 现代处理器的调度策略,调度优先级,亲和性是什么意思?
  • Python中for循环及其相关函数range(), zip(), enumerate()等
  • Docker部署jenkins
  • 深度解析:如何高效识别并定位问题关键词
  • C#打开文件及目录脚本
  • Ubuntu 系统深度清理:彻底卸载 Redis 服务及残留配置
  • 工程师 - 场效应管分类
  • Python使用闭包实现不修改源码添加功能详解
  • 权限的概念
  • 明明包含了头文件,为何还是显示未定义错误?
  • 鸢尾花分类的6种机器学习方法综合分析与实现
  • compose map 源码解析
  • Quartus II的IP核调用及仿真测试
  • FileInputStream 详解与记忆方法
  • Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
  • GPT模型架构与文本生成技术深度解析
  • dbt:新一代数据转换工具
  • 程序化广告行业(78/89):多因素交织下的行业剖析与展望
  • Linux-内核驱动-中断-key
  • 【Sequelize】迁移和种子
  • QT聊天项目DAY01
  • 设计模式 --- 命令模式
  • C++进阶——C++11_{ }初始化_lambda_包装器
  • Flutter常用组件实践
  • python+requests接口自动化测试框架实例教程
  • C#容器源码分析 --- Queue<T>
  • 2025届蓝桥杯JavaB组个人题解(暂时不全,没题目)