首页 > 编程语言 >Python100个案例源码(基础应用,网络爬虫,数据分析与图表,文件、系统、图形与多媒体,办公自动化,web开发,游戏开发,微信小程序,综合应用)

Python100个案例源码(基础应用,网络爬虫,数据分析与图表,文件、系统、图形与多媒体,办公自动化,web开发,游戏开发,微信小程序,综合应用)

时间:2024-10-28 11:17:12浏览次数:6  
标签:web map 微信 list 源码 31m print 033 0m

Python100个案例源码

点我下载此资源

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
部分示例

模拟迷宫地图的二维列表

map_list=[
[" “,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“],
[”=>“,“Y”,” “,” “,”@“,”@“,” “,” “,” “,” “,” “,” “,”@“,” “,” “,” “,”@“,”@“,” “,” “,” “,”@“,” “,”@“,” “,”@“,” “,”@“,” “,”@“,”@“],
[” “,”@“,” “,” “,”@“,”@“,”@“,” “,”@“,” “,”@“,” “,”@“,”@“,”@“,” “,” “,” “,” “,”@“,” “,”@“,” “,”@“,”@“,”@“,” “,”@“,”@“,”@“,”@“],
[” “,”@“,” “,”@“,” “,” “,” “,”@“,”@“,” “,”@“,” “,” “,” “,”@“,”@“,”@“,”@“,”@“,”@“,” “,”@“,” “,”@“,”@“,”@“,” “,” “,” “,”@“,”@“],
[” “,”@“,” “,” “,” “,”@“,” “,”@“,”@“,” “,” “,”@“,”@“,”@“,” “,”@“,”@“,” “,”@“,” “,” “,”@“,” “,” “,”@“,”@“,” “,”@“,”@“,”@“,”@“],
[” “,”@“,”@“,”@“,”@“,”@“,” “,”@“,” “,”@“,”@“,” “,” “,”@“,” “,”@“,”@“,”@“,”@“,”@“,” “,”@“,”@“,” “,” “,” “,” “,”@“,”@“,”@“,”@“],
[” “,”@“,” “,” “,” “,”@“,” “,”@“,”@“,”@“,”@“,”@“,” “,”@“,” “,” “,” “,”@“,”@“,”@“,” “,”@“,” “,”@“,” “,”@“,” “,” “,” “,” “,”@“],
[” “,”@“,” “,”@“,” “,”@“,” “,”@“,”@“,” “,”@“,”@“,”@“,” “,” “,”@“,”@“,” “,” “,” “,” “,”@“,”@“,”@“,” “,”@“,” “,”@“,”@“,”@“,”@“],
[” “,”@“,” “,”@“,” “,” “,” “,”@“,”@“,” “,” “,” “,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,” “,”@“,”@“,”@“,” “,” “,” “,”@“],
[” “,”@“,” “,”@“,”@“,”@“,”@“,”@“,”@“,” “,”@“,” “,”@“,”@“,”@“,”@“,”@“,” “,” “,” “,” “,” “,” “,” “,” “,” “,” “,” “,”@“,” “,”@“],
[” “,”@“,” “,” “,” “,” “,” “,” “,” “,” “,”@“,” “,”@“,” “,” “,” “,” “,” “,”@“,”@“,”@“,”@“,”@“,” “,”@“,”@“,”@“,” “,”@“,” “,” “,”=>“],
[” “,”@“,” “,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,” “,”@“,”@“,”@“,”@“,”@“,” “,”@“,”@“,”@“,”@“,”@“,” “,”@“,”@“,”@“,” “,”@“,”@“,”@“],
[” “,”@“,” “,” “,” “,” “,” “,”@“,” “,”@“,”@“,” “,”@“,”@“,”@“,”@“,”@“,” “,”@“,”@“,”@“,” “,” “,” “,” “,” “,” “,” “,”@“,”@“,”@“],
[” “,”@“,”@“,”@“,”@“,”@“,” “,”@“,” “,”@“,”@“,” “,”@“,” “,” “,” “,” “,” “,” “,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,” “,”@“,” “,”@“],
[” “,”@“,” “,” “,” “,” “,” “,”@“,” “,”@“,”@“,” “,”@“,”@“,” “,”@“,”@“,”@“,” “,” “,” “,” “,” “,” “,” “,” “,”@“,” “,” “,” “,”@“],
[” “,”@“,” “,”@“,” “,”@“,”@“,”@“,” “,” “,” “,” “,” “,” “,” “,”@“,”@“,”@“,”@“,”@“,”@“,” “,”@“,”@“,”@“,”@“,”@“,”@“,”@“,” “,”@“],
[” “,”@“,” “,” “,” “,” “,” “,” “,” “,”@“,”@“,” “,”@“,”@“,” “,” “,” “,” “,” “,” “,”@“,” “,” “,” “,” “,” “,” “,” “,” “,” “,”@“],
[” “,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@“,”@"]]

更新地图

def up_map():
# 打印小标题并指定打印区域的文字以及背景颜色
print(“\033[1;30;42m ----------小迷宫-----------”)
for i,values in enumerate(map_list): # 遍历二维列表中的18个子列表
for j in range(len(values)): # 遍历子列表中的元素
# 打印每个子列表中的所有元素,并且不换行打印
print(map_list[i][j], end=“”)
print(“”) # 每打印一个子列表所有元素,换行一次
print(“\033[0m”,end=“”) # 背景色结束位置

if name == ‘main’:
x = 1 # 横向坐标默认值
y = 1 # 纵向坐标默认值
step_number = 0 # 记录行走步数的变量
up_map() # 更新模拟地图
while True:
# 判断当小人走到迷宫出口时,打印胜利文字,跳出循环
if x == 30 and y == 10:
print(“\033[31m恭喜您!走出了迷宫!\033[0m”)
print(“\033[31m共计行走了”,step_number,“步!\033[0m”)
break
print(“\033[31m请输入行走的方向(输入exit将退出游戏!)\033[0m”)
# 获取输入的行走方向w为上、s为下、a为左、d为右
direction = input(“\033[31mw为上、s为下、a为左、d为右:\033[0m”)
# 当用户输入w,控制人物向上走
if (direction == “w”):
if map_list[y - 1][x] != “@”:
map_list[y][x] = " "
y -= 1
map_list[y][x] = “Y”
step_number += 1 # 修改小人移动步数
else:
print(‘\033[31m碰到墙壁!\033[0m’)
up_map() # 更新地图
# 当用户输入s,控制人物向下走
elif (direction == “s”):
if map_list[y+1][x] != “@”: # 判断行走位置不是墙时,@(表示墙)
map_list[y][x] = " " # 将小人原来的位置设置为空
y += 1 # 修改Y坐标位置
map_list[y][x] = “Y” # 将移动后的位置设置为Y(表示小人)
step_number+=1 # 修改小人移动步数
else:
print(‘\033[31m碰到墙壁!\033[0m’) # 当用户输入的位置是墙时,做出提示
up_map() # 更新地图
# 当用户输入a,控制人物向左走
elif (direction == “a”):
if map_list[y][x - 1] != “@”:
map_list[y][x] = " "
x -= 1
map_list[y][x] = “Y”
step_number += 1 # 修改小人移动步数
else:
print(‘\033[31m碰到墙壁!\033[0m’)
up_map() # 更新地图
# 当用户输入d,控制人物向右走
elif (direction == “d”):
if map_list[y][x + 1] != “@”:
map_list[y][x] = " "
x += 1
map_list[y][x] = “Y”
step_number += 1 # 修改小人移动步数
else:
print(‘\033[31m碰到墙壁!\033[0m’)
up_map() #更新地图
# 当用户输入退出命令,跳出循环
elif (direction == “exit”):
print(“游戏退出。”)
break

标签:web,map,微信,list,源码,31m,print,033,0m
From: https://blog.csdn.net/weixin_43474701/article/details/143288717

相关文章