本文共 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("恭喜你已经脱出迷宫。")
转载地址:http://ddyzo.baihongyu.com/