博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python语言迷宫游戏_python代码实现一个迷宫小游戏
阅读量:6454 次
发布时间:2019-06-23

本文共 3566 字,大约阅读时间需要 11 分钟。

import os

map_list=

[["#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#"],

["#","O"," "," "," "," "," "," "," "," "," ","#"," "," "," ","#","#"," "," "," ","#"," ","#","#","#"," ","#","#","#","#"],

["#"," ","#","#","#","#","#","#"," ","#"," ","#"," ","#"," "," "," "," ","#"," ","#"," ","#","#","#"," ","#","#","#","#"],

["#"," ","#"," "," "," ","#","#"," ","#"," "," "," ","#"," ","#","#","#","#"," ","#"," ","#","#","#"," "," "," ","#","#"],

["#"," "," "," ","#"," ","#","#"," "," ","#","#","#"," "," "," "," ","#"," "," ","#"," "," ","#","#"," ","#","#","#","#"],

["#","#","#","#","#"," ","#"," "," "," "," "," ","#"," ","#","#","#","#","#"," ","#","#"," "," "," "," ","#","#","#","#"],

["#"," "," "," ","#"," ","#","#","#","#","#"," ","#"," "," "," ","#"," "," "," ","#"," ","#"," ","#"," "," "," "," ","#"],

["#"," ","#"," ","#"," "," "," "," ","#","#"," ","#"," ","#","#","#","#"," ","#","#"," ","#"," ","#"," ","#","#","#","#"],

["#"," ","#"," ","#"," ","#","#"," "," "," "," "," "," ","#","#"," "," "," "," "," "," ","#"," ","#"," ","#","#","#","#"],

["#"," ","#"," ","#"," ","#","#","#","#","#","#","#"," ","#","#"," ","#","#","#","#","#","#"," ","#"," "," "," ","#","#"],

["#"," ","#"," "," "," ","#","#"," "," "," ","#","#","#","#","#","#","#","#","#","#","#"," ","#","#","#"," "," "," ","#"],

["#"," ","#","#","#","#","#","#"," ","#"," ","#","#","#","#","#"," "," ","#"," "," "," "," "," "," "," "," ","#"," ","#"],

["#"," "," "," "," "," "," "," "," ","#"," ","#"," "," "," "," "," ","#","#","#","#","#"," ","#","#","#"," ","#"," "," "],

["#"," ","#","#","#","#","#","#","#","#"," ","#","#","#","#","#"," ","#","#","#","#","#"," ","#","#","#"," ","#","#","#"],

["#"," "," "," "," "," ","#"," ","#","#"," ","#","#","#","#","#"," ","#","#","#"," "," "," "," "," "," "," ","#","#","#"],

["#","#","#","#","#"," ","#"," ","#","#"," ","#"," "," "," "," "," "," ","#","#","#","#","#","#","#","#"," ","#"," ","#"],

["#"," "," "," "," "," ","#"," ","#","#"," ","#","#"," ","#","#","#"," "," "," "," "," "," "," "," ","#"," "," "," ","#"],

["#"," ","#"," ","#","#","#"," "," "," "," "," "," "," ","#","#","#","#","#","#"," ","#","#","#","#","#","#","#"," ","#"],

["#"," ","#"," "," "," "," ","#","#","#"," ","#","#"," "," "," "," "," "," ","#"," "," "," "," "," "," "," "," "," ","#"],

["#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#"]]

for i in range(20):

for j in range(30):

print(map_list[i][j], end="")

print("")

x = 1

y = 1

p = 12

q = 29

while x != p or y != q:

ch = input("请输入行走的方向(quit:是退出):")

#行走s方向

if (ch == "s"):

if map_list[x+1][y] != "#":

map_list[x][y] = " "

x += 1

map_list[x][y] = "O"

os.system("clear")

for i in range(20):

for j in range(30):

print(map_list[i][j], end="")

print("")

continue

#行走d方向

elif (ch == "d"):

if map_list[x][y+1] != "#":

map_list[x][y] = " "

y += 1

map_list[x][y] = "O"

os.system("clear")

for i in range(20):

for j in range(30):

print(map_list[i][j], end="")

print("")

continue

#行走w方向

elif (ch == "w"):

if map_list[x-1][y] != "#":

map_list[x][y] = " "

x -= 1

map_list[x][y] = "O"

os.system("clear")

for i in range(20):

for j in range(30):

print(map_list[i][j], end="")

print("")

continue

#行走a方向

elif (ch == "a"):

if map_list[x][y-1] != "#":

map_list[x][y] = " "

y -= 1

map_list[x][y] = "O"

os.system("clear")

for i in range(20):

for j in range(30):

print(map_list[i][j], end="")

print("")

continue

elif (ch == "quit"):

print("游戏退出。")

break

if x == p and y == q:

print("恭喜你已经脱出迷宫。")

005e44f46e1fd5e1ac05c3c980ed0420.png

转载地址:http://ddyzo.baihongyu.com/

你可能感兴趣的文章
Python 嵌套列表解析
查看>>
[GXOI/GZOI2019]旧词——树链剖分+线段树
查看>>
android 补间动画的实现
查看>>
2017年广东省ACM省赛(GDCPC-2017)总结
查看>>
第十届蓝桥杯B组C++题目详解和题型总结
查看>>
树的存储结构2 - 数据结构和算法42
查看>>
简单理解函数回调——同步回调与异步回调
查看>>
Android 多个Activity 跳转及传参
查看>>
anroid 广播
查看>>
AJAX POST&跨域 解决方案 - CORS
查看>>
关于最小生成树中的kruskal算法中判断两个点是否在同一个连通分量的方法总结...
查看>>
【译】Linux系统和性能监控(4)
查看>>
开篇,博客的申请理由
查看>>
点滴积累【C#】---C#实现上传word以流形式保存到数据库和读取数据库中的word文件。...
查看>>
Ubuntu常用笔记
查看>>
Token和session 详解
查看>>
JMeter IP欺骗压测
查看>>
Serializers 序列化组件
查看>>
最简单的RPC框架实现
查看>>
Servlet 技术全总结 (已完成,不定期增加内容)
查看>>