
Lv.1
整个世界美好的时光,就像一串串代码,只要知道它的形成,就能制作美丽的程序
签名:我现在正在做好玩,有趣的游戏,但是在这之前,网络不要崩溃哦
在 【MC指令者】制作联机 中回复
是这样吗,https://shequ.codemao.cn/work/66348396?entry=copy_work_url
2020-11-07T12:53:40 点赞:0
在 【Python作品分享】疯狂贪吃蛇 中回复
importpygame,sys#导入模块 frompygame.localsimport* fromrandomimport*#随机模块 pygame.init()#初始化 screen=pygame.display.set_mode((400,400))#设置窗口 x,y=200,200#贪吃蛇的坐标 up=1#判断哪个方向可以移动 down=0 left=0 right=0 l=1#每个蛇头和蛇身的编号 d=5#蛇头和蛇身的长度 t=0#坐标限制 l=0#贪吃蛇长度限制 whileTrue:#制造死循环 foreventinpygame.event.get(): ifevent.type==pygame.QUIT:#是否按到关闭按钮 pygame.quit() sys.exit() 喵55,255,255))#将背景设为白色 ift==0: x1,y1=randrange(100,200),randrange(100,200)#随机坐标 t+=1 pygame.draw.rect(screen,[0,0,255],[x1,y1,30,30],0)#画食物 ifx>x1andx<x1+30andy>y1andy<y1+30:#判断是否可以吃到食物 ifl==1: d+=1 l=0 t=0 l+1 pressed_keys=pygame.key.get_pressed()#监测键盘按键 ifup==1:#移动贪吃蛇 y-=5 forainrange(d): pygame.draw.rect(screen,[255,193,193],[x,y+30*l,30,30],0) l+=1 l=1 ifdown==1: y+=5 forainrange(d): pygame.draw.rect(screen,[255,193,193],[x,y-30*l,30,30],0) l+=1 l=1 ifleft==1: x-=5 forainrange(d): pygame.draw.rect(screen,[255,193,193],[x+30*l,y,30,30],0) l+=1 l=1 ifright==1: x+=5 forainrange(d): pygame.draw.rect(screen,[255,193,193],[x+-30*l,y,30,30],0) l+=1 l=1 ifpressed_keys[K_LEFT]:#设置方向,一次只能移动一个方向 left=1 up=0 right=0 down=0 ifpressed_keys[K_RIGHT]: left=0 up=0 right=1 down=0 ifpressed_keys[K_UP]: up=1 left=0 right=0 down=0 ifpressed_keys[K_DOWN]: up=0 left=0 right=0 down=1 pygame.time.delay(100)#暂停100毫秒 pygame.display.flip()#刷新
2021-03-06T13:43:39 点赞:1
在 【推箱子】 中回复
#导入模块
from pygame import *
from sys import *
#初始化
init()
font.init()
#显示窗口
screen=display.set_mode((400,400))
#显示标题
display.set_caption("推箱子")
#设置地图坐标
x=0
y=0
#背景颜色
screen.fill((255,255,255))
#设置地图
map1=[]
#循环变量
i=0
#调整地图
for a in range(8):
for a in range(8):
map1.append(0)
for a in range(8):
map1[i]=10
i+=1
i=len(map1)-1
for a in range(8):
map1[i]=10
i-=1
i=8
for a in range(6):
map1[i]=10
i+=8
i=15
for a in range(6):
map1[i]=10
i+=8
map1[0]=0
map1[1]=0
map1[9]=10
map1[10]=10
map1[63]=0
map1[62]=0
map1[54]=10
map1[53]=10
map1[13]=4
map1[44]=5
map1[12]=6
map1[43]=7
map1[49]=1
i=0
k=49#人的编号
d=44#箱子1的编号
o=13#箱子2的编号
while True:#喵循环
for a in event.get():
if a.type==QUIT:
#退出窗口
quit()
exit()
#移动人,箱子
elif a.type == KEYDOWN: #键被按下
if a.key == K_LEFT:
if map1[k-1]==5 and map1[d-1]!=10 and map1[d-8]!=4:
map1[k]=0
k-=1
map1[d]=1
d-=1
map1[d]=5
if map1[k-1]==4 and map1[o-1]!=10 and map1[d-8]!=5:
map1[k]=0
k-=1
map1[o]=1
o-=1
map1[o]=4
if map1[k-1]!=10 and map1[k-1]!=5 and map1[k-1]!=4:
map1[k]=0
k-=1
map1[k]=1
elif a.key == K_RIGHT:
if map1[k+1]==5 and map1[d+1]!=10 and map1[d-8]!=4:
map1[k]=0
k+=1
map1[d]=1
d+=1
map1[d]=5
if map1[k+1]==4 and map1[o+1]!=10 and map1[d-8]!=5:
map1[k]=0
k+=1
map1[o]=1
o+=1
map1[o]=4
if map1[k+1]!=10 and map1[k+1]!=5 and map1[k-8]!=5:
map1[k]=0
k+=1
map1[k]=1
elif a.key == K_UP:
#判断上面是否有箱子,箱子上面是否是墙
#因为图层问题,界面上多显示出一个箱子
if map1[k-8]==5 and map1[d-8]!=10 and map1[d-8]!=4:
map1[k]=0
k-=8
map1[d]=1
d-=8
map1[d]=5
if map1[k-8]==4 and map1[o-8]!=10 and map1[d-8]!=5:
map1[k]=0
k-=8
map1[o]=1
o-=8
map1[o]=4
if map1[k-8]!=10 and map1[k-8]!=5 and map1[k-8]!=4 :
map1[k]=0
k-=8
map1[k]=1
elif a.key == K_DOWN:
if map1[k+8]==5 and map1[d+8]!=10 and map1[d-8]!=4:
map1[k]=0
k+=8
map1[d]=1
d+=8
map1[d]=5
if map1[k+8]==4 and map1[o+8]!=10 and map1[d-8]!=5:
map1[k]=0
k+=8
map1[o]=1
o+=8
map1[o]=4
if map1[k+8]!=10 and map1[k+8]!=5 and map1[k-8]!=5:
map1[k]=0
k+=8
map1[k]=1
#显示地图
for a in range(8):
for a in range(8):
if map1[i]==10:
draw.rect(screen,(196,74,86),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==5:
draw.rect(screen,(219,182,125),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==4:
draw.rect(screen,(219,182,125),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==1:
draw.circle(screen,(55,162,212),(x+20,y+20),20,0)
draw.circle(screen,(0,0,0),(x+20,y+20),20,5)
if map1[i]==6:
draw.rect(screen,(0,212,101),(x,y,30,30),0)
draw.rect(screen,(0,0,0),(x,y,30,30),5)
if map1[i]==7:
draw.rect(screen,(0,212,101),(x,y,30,30),0)
draw.rect(screen,(0,0,0),(x,y,30,30),5)
if map1[i]==0:
draw.rect(screen,(255,255,255),(x,y,50,50),0)
if map1[12]==0:
draw.rect(screen,(0,212,101),(200,60,30,30),0)
draw.rect(screen,(0,0,0),(200,60,30,30),5)
if map1[43]==0:
draw.rect(screen,(0,212,101),(200-30,300-30,30,30),0)
draw.rect(screen,(0,0,0),(200-30,300-30,30,30),5)
i+=1
x+=50
x=0
y+=50
if (map1[12]==4 and map1[43]==4) or (map1[12]==5 and map1[43]==5) or (map1[12]==5 and map1[43]==4) or (map1[12]==4 and map1[43]==5):
font1=font.SysFont('方正喵宋简体',50)
font2=font1.render('恭喜你,闯关成功!',1,(0,0,0))
screen.blit(font2,(0,200))
i=0
x=0
y=0
#刷新
display.flip()
2021-03-07T15:40:21 点赞:0
在 【我要上首页】超级2的推箱子 中回复
#导入模块
from pygame import *
from sys import *
#初始化
init()
font.init()
#显示窗口
screen=display.set_mode((400,400))
#显示标题
display.set_caption("推箱子")
#设置地图坐标
x=0
y=0
#背景颜色
screen.fill((255,255,255))
#设置地图
map1=[]
#循环变量
i=0
#调整地图
for a in range(8):
for a in range(8):
map1.append(0)
for a in range(8):
map1[i]=10
i+=1
i=len(map1)-1
for a in range(8):
map1[i]=10
i-=1
i=8
for a in range(6):
map1[i]=10
i+=8
i=15
for a in range(6):
map1[i]=10
i+=8
map1[0]=0
map1[1]=0
map1[9]=10
map1[10]=10
map1[63]=0
map1[62]=0
map1[54]=10
map1[53]=10
map1[13]=4
map1[44]=5
map1[12]=6
map1[43]=7
map1[49]=1
i=0
k=49#人的编号
d=44#箱子1的编号
o=13#箱子2的编号
while True:#喵循环
for a in event.get():
if a.type==QUIT:
#退出窗口
quit()
exit()
#移动人,箱子
elif a.type == KEYDOWN: #键被按下
if a.key == K_LEFT:
if map1[k-1]==5 and map1[d-1]!=10 and map1[d-8]!=4:
map1[k]=0
k-=1
map1[d]=1
d-=1
map1[d]=5
if map1[k-1]==4 and map1[o-1]!=10 and map1[d-8]!=5:
map1[k]=0
k-=1
map1[o]=1
o-=1
map1[o]=4
if map1[k-1]!=10 and map1[k-1]!=5 and map1[k-1]!=4:
map1[k]=0
k-=1
map1[k]=1
elif a.key == K_RIGHT:
if map1[k+1]==5 and map1[d+1]!=10 and map1[d-8]!=4:
map1[k]=0
k+=1
map1[d]=1
d+=1
map1[d]=5
if map1[k+1]==4 and map1[o+1]!=10 and map1[d-8]!=5:
map1[k]=0
k+=1
map1[o]=1
o+=1
map1[o]=4
if map1[k+1]!=10 and map1[k+1]!=5 and map1[k-8]!=5:
map1[k]=0
k+=1
map1[k]=1
elif a.key == K_UP:
#判断上面是否有箱子,箱子上面是否是墙
#因为图层问题,界面上多显示出一个箱子
if map1[k-8]==5 and map1[d-8]!=10 and map1[d-8]!=4:
map1[k]=0
k-=8
map1[d]=1
d-=8
map1[d]=5
if map1[k-8]==4 and map1[o-8]!=10 and map1[d-8]!=5:
map1[k]=0
k-=8
map1[o]=1
o-=8
map1[o]=4
if map1[k-8]!=10 and map1[k-8]!=5 and map1[k-8]!=4 :
map1[k]=0
k-=8
map1[k]=1
elif a.key == K_DOWN:
if map1[k+8]==5 and map1[d+8]!=10 and map1[d-8]!=4:
map1[k]=0
k+=8
map1[d]=1
d+=8
map1[d]=5
if map1[k+8]==4 and map1[o+8]!=10 and map1[d-8]!=5:
map1[k]=0
k+=8
map1[o]=1
o+=8
map1[o]=4
if map1[k+8]!=10 and map1[k+8]!=5 and map1[k-8]!=5:
map1[k]=0
k+=8
map1[k]=1
#显示地图
for a in range(8):
for a in range(8):
if map1[i]==10:
draw.rect(screen,(196,74,86),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==5:
draw.rect(screen,(219,182,125),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==4:
draw.rect(screen,(219,182,125),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==1:
draw.circle(screen,(55,162,212),(x+20,y+20),20,0)
draw.circle(screen,(0,0,0),(x+20,y+20),20,5)
if map1[i]==6:
draw.rect(screen,(0,212,101),(x,y,30,30),0)
draw.rect(screen,(0,0,0),(x,y,30,30),5)
if map1[i]==7:
draw.rect(screen,(0,212,101),(x,y,30,30),0)
draw.rect(screen,(0,0,0),(x,y,30,30),5)
if map1[i]==0:
draw.rect(screen,(255,255,255),(x,y,50,50),0)
if map1[12]==0:
draw.rect(screen,(0,212,101),(200,60,30,30),0)
draw.rect(screen,(0,0,0),(200,60,30,30),5)
if map1[43]==0:
draw.rect(screen,(0,212,101),(200-30,300-30,30,30),0)
draw.rect(screen,(0,0,0),(200-30,300-30,30,30),5)
i+=1
x+=50
x=0
y+=50
if (map1[12]==4 and map1[43]==4) or (map1[12]==5 and map1[43]==5) or (map1[12]==5 and map1[43]==4) or (map1[12]==4 and map1[43]==5):
font1=font.SysFont('方正喵宋简体',50)
font2=font1.render('恭喜你,闯关成功!',1,(0,0,0))
screen.blit(font2,(0,200))
i=0
x=0
y=0
#刷新
display.flip()
2021-03-07T15:40:55 点赞:0
在 【求助】怎么做推箱子游戏? 中回复
#导入模块
from pygame import *
from sys import *
#初始化
init()
font.init()
#显示窗口
screen=display.set_mode((400,400))
#显示标题
display.set_caption("推箱子")
#设置地图坐标
x=0
y=0
#背景颜色
screen.fill((255,255,255))
#设置地图
map1=[]
#循环变量
i=0
#调整地图
for a in range(8):
for a in range(8):
map1.append(0)
for a in range(8):
map1[i]=10
i+=1
i=len(map1)-1
for a in range(8):
map1[i]=10
i-=1
i=8
for a in range(6):
map1[i]=10
i+=8
i=15
for a in range(6):
map1[i]=10
i+=8
map1[0]=0
map1[1]=0
map1[9]=10
map1[10]=10
map1[63]=0
map1[62]=0
map1[54]=10
map1[53]=10
map1[13]=4
map1[44]=5
map1[12]=6
map1[43]=7
map1[49]=1
i=0
k=49#人的编号
d=44#箱子1的编号
o=13#箱子2的编号
while True:#喵循环
for a in event.get():
if a.type==QUIT:
#退出窗口
quit()
exit()
#移动人,箱子
elif a.type == KEYDOWN: #键被按下
if a.key == K_LEFT:
if map1[k-1]==5 and map1[d-1]!=10 and map1[d-8]!=4:
map1[k]=0
k-=1
map1[d]=1
d-=1
map1[d]=5
if map1[k-1]==4 and map1[o-1]!=10 and map1[d-8]!=5:
map1[k]=0
k-=1
map1[o]=1
o-=1
map1[o]=4
if map1[k-1]!=10 and map1[k-1]!=5 and map1[k-1]!=4:
map1[k]=0
k-=1
map1[k]=1
elif a.key == K_RIGHT:
if map1[k+1]==5 and map1[d+1]!=10 and map1[d-8]!=4:
map1[k]=0
k+=1
map1[d]=1
d+=1
map1[d]=5
if map1[k+1]==4 and map1[o+1]!=10 and map1[d-8]!=5:
map1[k]=0
k+=1
map1[o]=1
o+=1
map1[o]=4
if map1[k+1]!=10 and map1[k+1]!=5 and map1[k-8]!=5:
map1[k]=0
k+=1
map1[k]=1
elif a.key == K_UP:
#判断上面是否有箱子,箱子上面是否是墙
#因为图层问题,界面上多显示出一个箱子
if map1[k-8]==5 and map1[d-8]!=10 and map1[d-8]!=4:
map1[k]=0
k-=8
map1[d]=1
d-=8
map1[d]=5
if map1[k-8]==4 and map1[o-8]!=10 and map1[d-8]!=5:
map1[k]=0
k-=8
map1[o]=1
o-=8
map1[o]=4
if map1[k-8]!=10 and map1[k-8]!=5 and map1[k-8]!=4 :
map1[k]=0
k-=8
map1[k]=1
elif a.key == K_DOWN:
if map1[k+8]==5 and map1[d+8]!=10 and map1[d-8]!=4:
map1[k]=0
k+=8
map1[d]=1
d+=8
map1[d]=5
if map1[k+8]==4 and map1[o+8]!=10 and map1[d-8]!=5:
map1[k]=0
k+=8
map1[o]=1
o+=8
map1[o]=4
if map1[k+8]!=10 and map1[k+8]!=5 and map1[k-8]!=5:
map1[k]=0
k+=8
map1[k]=1
#显示地图
for a in range(8):
for a in range(8):
if map1[i]==10:
draw.rect(screen,(196,74,86),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==5:
draw.rect(screen,(219,182,125),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==4:
draw.rect(screen,(219,182,125),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==1:
draw.circle(screen,(55,162,212),(x+20,y+20),20,0)
draw.circle(screen,(0,0,0),(x+20,y+20),20,5)
if map1[i]==6:
draw.rect(screen,(0,212,101),(x,y,30,30),0)
draw.rect(screen,(0,0,0),(x,y,30,30),5)
if map1[i]==7:
draw.rect(screen,(0,212,101),(x,y,30,30),0)
draw.rect(screen,(0,0,0),(x,y,30,30),5)
if map1[i]==0:
draw.rect(screen,(255,255,255),(x,y,50,50),0)
if map1[12]==0:
draw.rect(screen,(0,212,101),(200,60,30,30),0)
draw.rect(screen,(0,0,0),(200,60,30,30),5)
if map1[43]==0:
draw.rect(screen,(0,212,101),(200-30,300-30,30,30),0)
draw.rect(screen,(0,0,0),(200-30,300-30,30,30),5)
i+=1
x+=50
x=0
y+=50
if (map1[12]==4 and map1[43]==4) or (map1[12]==5 and map1[43]==5) or (map1[12]==5 and map1[43]==4) or (map1[12]==4 and map1[43]==5):
font1=font.SysFont('方正喵宋简体',50)
font2=font1.render('恭喜你,闯关成功!',1,(0,0,0))
screen.blit(font2,(0,200))
i=0
x=0
y=0
#刷新
display.flip()
2021-03-07T15:41:13 点赞:0
在 制作推箱子 中回复
链接:pan.喵/s/16Lvy-WJ2x_qRYC6P5HBp-w
提取码:code
复制这段内容后打开百度网盘手机App,操作更方便哦
2021-03-07T21:04:43 点赞:1
在 造个五子棋记得帮忙! 中回复
import pygame,sys#导入模块
pygame.init()#游戏初始化
pygame.mixer.init()
pygame.font.init()#汉字初始化
screen = pygame.display.set_mode((650,450))#创建游戏窗口
pygame.display.set_caption("五子棋")#设置游戏窗口的标题
pos=[]#记录棋盘上每一个点的坐标
x=10#记录点的x坐标
y=10#记录点的y坐标
p=[]#记录点的地图位置
n=0#判断棋子的颜色
color=[]#记录棋子的颜色
map1=[]#判断哪些项有点
i=0#判断胜负查看每一个点的循环变量
for a in range(16):#表示棋盘的行的点
for a in range(16):#表示棋盘列的点
pos.append((x,y))#将点的位置用元祖的方式记录到列表
map1.append(0)#添加元素0代表点,1代表白棋,2代表黑棋
x+=30#记录下一个点
x=10#记录下一行的第一个
y+=30#记录下一行
pygame.mixer.music.load("5a41_37f5_ac53_b2f6f7c0ea87d23a393503caa67a2c5f.mp3")
while True:#游戏循环
if pygame.mixer.music.get_busy()==False:
pygame.mixer.music.play()
x=10#重设x坐标
y=10#重设y坐标
screen.fill((139,69,19))#设置为棋盘的颜色
for event in pygame.event.get():#遍历所有按键
if event.type == pygame.QUIT:#如果按下关闭键
pygame.quit()#关闭窗口
sys.exit()#关闭程序
if event.type==pygame.MOUSEBUTTONDOWN:#判断是否点击鼠标
for b in range(len(pos)):#遍历所有的点的位置
#设置一个虚拟的圆,判断是否鼠标点击每个圆中
if pos[b][0]-15<pygame.mouse.get_pos()[0] and pos[b][0]+15>pygame.mouse.get_pos()[0]:
if pos[b][1]-15<pygame.mouse.get_pos()[1] and pos[b][1]+15>pygame.mouse.get_pos()[1]:
if n==0:
n+=1
p.append(b)#添加点的项
if b!=p[-1]:
n+=1
p.append(b)#添加点的项
if n%2==0:#判断奇偶数
color.append((255,255,255))#将棋子颜色添加到列表
map1[b]=1
else:
color.append((0,0,0))
map1[b]=2
break
for a in range(14):#表示棋盘行的点
for a in range(15):#表示棋盘列的点
pygame.draw.rect(screen,(0,0,0),(x,y,30,30),1)#绘制矩形
x+=30#绘制下一个圆
x=10#绘制下一行的第一个的圆
y+=30#绘制下一行的圆
pygame.draw.circle(screen,(255,0,0),(pygame.mouse.get_pos()[0]+5,pygame.mouse.get_pos()[1]+5),15,1)
i+=1
#绘制一个跟随鼠标的圆
for c in range(len(p)):#判断有多少个点,将这些点都绘制出来
pygame.draw.circle(screen,color[c],pos[p[c]],15,0)#绘制圆形
screen.blit(pygame.font.SysFont("simhei",25).render("棋子数量: "+str(n),0,(255,255,0)),(466,10))
if i==250:#看循环是否结束
i=0#重新检测
#判断横
if map1[i]==1 and map1[i+1]==1 and map1[i+2]==1 and map1[i+3]==1 and map1[i+4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+1]==2 and map1[i+2]==2 and map1[i+3]==2 and map1[i+4]==2:
print("黑棋赢")
break
#判断竖
if map1[i]==1 and map1[i+16]==1 and map1[i+32]==1 and map1[i+48]==1 and map1[i+喵]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16]==2 and map1[i+32]==2 and map1[i+48]==2 and map1[i+喵]==2:
print("黑棋赢")
break
#判断反斜
if map1[i]==1 and map1[i+16+1]==1 and map1[i+32+2]==1 and map1[i+48+3]==1 and map1[i+喵+4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16+1]==2 and map1[i+32+2]==2 and map1[i+48+3]==2 and map1[i+喵+4]==2:
print("黑棋赢")
break
#判断斜
if map1[i]==1 and map1[i+16-1]==1 and map1[i+32-2]==1 and map1[i+48-3]==1 and map1[i+喵-4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16-1]==2 and map1[i+32-2]==2 and map1[i+48-3]==2 and map1[i+喵-4]==2:
print("黑棋赢")
break
#显示棋子数量,因为一共256个交叉点,所以空三格
pygame.display.flip()#刷新游戏2021-06-13T14:48:22 点赞:0
在 python五子棋游戏代码 中回复
import pygame,sys#导入模块
pygame.init()#游戏初始化
pygame.mixer.init()
pygame.font.init()#汉字初始化
screen = pygame.display.set_mode((650,450))#创建游戏窗口
pygame.display.set_caption("五子棋")#设置游戏窗口的标题
pos=[]#记录棋盘上每一个点的坐标
x=10#记录点的x坐标
y=10#记录点的y坐标
p=[]#记录点的地图位置
n=0#判断棋子的颜色
color=[]#记录棋子的颜色
map1=[]#判断哪些项有点
i=0#判断胜负查看每一个点的循环变量
for a in range(16):#表示棋盘的行的点
for a in range(16):#表示棋盘列的点
pos.append((x,y))#将点的位置用元祖的方式记录到列表
map1.append(0)#添加元素0代表点,1代表白棋,2代表黑棋
x+=30#记录下一个点
x=10#记录下一行的第一个
y+=30#记录下一行
pygame.mixer.music.load("5a41_37f5_ac53_b2f6f7c0ea87d23a393503caa67a2c5f.mp3")
while True:#游戏循环
if pygame.mixer.music.get_busy()==False:
pygame.mixer.music.play()
x=10#重设x坐标
y=10#重设y坐标
screen.fill((139,69,19))#设置为棋盘的颜色
for event in pygame.event.get():#遍历所有按键
if event.type == pygame.QUIT:#如果按下关闭键
pygame.quit()#关闭窗口
sys.exit()#关闭程序
if event.type==pygame.MOUSEBUTTONDOWN:#判断是否点击鼠标
for b in range(len(pos)):#遍历所有的点的位置
#设置一个虚拟的圆,判断是否鼠标点击每个圆中
if pos[b][0]-15<pygame.mouse.get_pos()[0] and pos[b][0]+15>pygame.mouse.get_pos()[0]:
if pos[b][1]-15<pygame.mouse.get_pos()[1] and pos[b][1]+15>pygame.mouse.get_pos()[1]:
if n==0:
n+=1
p.append(b)#添加点的项
if b!=p[-1]:
n+=1
p.append(b)#添加点的项
if n%2==0:#判断奇偶数
color.append((255,255,255))#将棋子颜色添加到列表
map1[b]=1
else:
color.append((0,0,0))
map1[b]=2
break
for a in range(14):#表示棋盘行的点
for a in range(15):#表示棋盘列的点
pygame.draw.rect(screen,(0,0,0),(x,y,30,30),1)#绘制矩形
x+=30#绘制下一个圆
x=10#绘制下一行的第一个的圆
y+=30#绘制下一行的圆
pygame.draw.circle(screen,(255,0,0),(pygame.mouse.get_pos()[0]+5,pygame.mouse.get_pos()[1]+5),15,1)
i+=1
#绘制一个跟随鼠标的圆
for c in range(len(p)):#判断有多少个点,将这些点都绘制出来
pygame.draw.circle(screen,color[c],pos[p[c]],15,0)#绘制圆形
screen.blit(pygame.font.SysFont("simhei",25).render("棋子数量: "+str(n),0,(255,255,0)),(466,10))
if i==250:#看循环是否结束
i=0#重新检测
#判断横
if map1[i]==1 and map1[i+1]==1 and map1[i+2]==1 and map1[i+3]==1 and map1[i+4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+1]==2 and map1[i+2]==2 and map1[i+3]==2 and map1[i+4]==2:
print("黑棋赢")
break
#判断竖
if map1[i]==1 and map1[i+16]==1 and map1[i+32]==1 and map1[i+48]==1 and map1[i+喵]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16]==2 and map1[i+32]==2 and map1[i+48]==2 and map1[i+喵]==2:
print("黑棋赢")
break
#判断反斜
if map1[i]==1 and map1[i+16+1]==1 and map1[i+32+2]==1 and map1[i+48+3]==1 and map1[i+喵+4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16+1]==2 and map1[i+32+2]==2 and map1[i+48+3]==2 and map1[i+喵+4]==2:
print("黑棋赢")
break
#判断斜
if map1[i]==1 and map1[i+16-1]==1 and map1[i+32-2]==1 and map1[i+48-3]==1 and map1[i+喵-4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16-1]==2 and map1[i+32-2]==2 and map1[i+48-3]==2 and map1[i+喵-4]==2:
print("黑棋赢")
break
#显示棋子数量,因为一共256个交叉点,所以空三格
pygame.display.flip()#刷新游戏2021-06-13T14:48:55 点赞:0
在 双人五子棋 中回复
import pygame,sys#导入模块
pygame.init()#游戏初始化
pygame.mixer.init()
pygame.font.init()#汉字初始化
screen = pygame.display.set_mode((650,450))#创建游戏窗口
pygame.display.set_caption("五子棋")#设置游戏窗口的标题
pos=[]#记录棋盘上每一个点的坐标
x=10#记录点的x坐标
y=10#记录点的y坐标
p=[]#记录点的地图位置
n=0#判断棋子的颜色
color=[]#记录棋子的颜色
map1=[]#判断哪些项有点
i=0#判断胜负查看每一个点的循环变量
for a in range(16):#表示棋盘的行的点
for a in range(16):#表示棋盘列的点
pos.append((x,y))#将点的位置用元祖的方式记录到列表
map1.append(0)#添加元素0代表点,1代表白棋,2代表黑棋
x+=30#记录下一个点
x=10#记录下一行的第一个
y+=30#记录下一行
pygame.mixer.music.load("5a41_37f5_ac53_b2f6f7c0ea87d23a393503caa67a2c5f.mp3")
while True:#游戏循环
if pygame.mixer.music.get_busy()==False:
pygame.mixer.music.play()
x=10#重设x坐标
y=10#重设y坐标
screen.fill((139,69,19))#设置为棋盘的颜色
for event in pygame.event.get():#遍历所有按键
if event.type == pygame.QUIT:#如果按下关闭键
pygame.quit()#关闭窗口
sys.exit()#关闭程序
if event.type==pygame.MOUSEBUTTONDOWN:#判断是否点击鼠标
for b in range(len(pos)):#遍历所有的点的位置
#设置一个虚拟的圆,判断是否鼠标点击每个圆中
if pos[b][0]-15<pygame.mouse.get_pos()[0] and pos[b][0]+15>pygame.mouse.get_pos()[0]:
if pos[b][1]-15<pygame.mouse.get_pos()[1] and pos[b][1]+15>pygame.mouse.get_pos()[1]:
if n==0:
n+=1
p.append(b)#添加点的项
if b!=p[-1]:
n+=1
p.append(b)#添加点的项
if n%2==0:#判断奇偶数
color.append((255,255,255))#将棋子颜色添加到列表
map1[b]=1
else:
color.append((0,0,0))
map1[b]=2
break
for a in range(14):#表示棋盘行的点
for a in range(15):#表示棋盘列的点
pygame.draw.rect(screen,(0,0,0),(x,y,30,30),1)#绘制矩形
x+=30#绘制下一个圆
x=10#绘制下一行的第一个的圆
y+=30#绘制下一行的圆
pygame.draw.circle(screen,(255,0,0),(pygame.mouse.get_pos()[0]+5,pygame.mouse.get_pos()[1]+5),15,1)
i+=1
#绘制一个跟随鼠标的圆
for c in range(len(p)):#判断有多少个点,将这些点都绘制出来
pygame.draw.circle(screen,color[c],pos[p[c]],15,0)#绘制圆形
screen.blit(pygame.font.SysFont("simhei",25).render("棋子数量: "+str(n),0,(255,255,0)),(466,10))
if i==250:#看循环是否结束
i=0#重新检测
#判断横
if map1[i]==1 and map1[i+1]==1 and map1[i+2]==1 and map1[i+3]==1 and map1[i+4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+1]==2 and map1[i+2]==2 and map1[i+3]==2 and map1[i+4]==2:
print("黑棋赢")
break
#判断竖
if map1[i]==1 and map1[i+16]==1 and map1[i+32]==1 and map1[i+48]==1 and map1[i+喵]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16]==2 and map1[i+32]==2 and map1[i+48]==2 and map1[i+喵]==2:
print("黑棋赢")
break
#判断反斜
if map1[i]==1 and map1[i+16+1]==1 and map1[i+32+2]==1 and map1[i+48+3]==1 and map1[i+喵+4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16+1]==2 and map1[i+32+2]==2 and map1[i+48+3]==2 and map1[i+喵+4]==2:
print("黑棋赢")
break
#判断斜
if map1[i]==1 and map1[i+16-1]==1 and map1[i+32-2]==1 and map1[i+48-3]==1 and map1[i+喵-4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16-1]==2 and map1[i+32-2]==2 and map1[i+48-3]==2 and map1[i+喵-4]==2:
print("黑棋赢")
break
#显示棋子数量,因为一共256个交叉点,所以空三格
pygame.display.flip()#刷新游戏2021-06-13T14:49:32 点赞:0
在 滑稽五子棋 中回复
import pygame,sys#导入模块
pygame.init()#游戏初始化
pygame.mixer.init()
pygame.font.init()#汉字初始化
screen = pygame.display.set_mode((650,450))#创建游戏窗口
pygame.display.set_caption("五子棋")#设置游戏窗口的标题
pos=[]#记录棋盘上每一个点的坐标
x=10#记录点的x坐标
y=10#记录点的y坐标
p=[]#记录点的地图位置
n=0#判断棋子的颜色
color=[]#记录棋子的颜色
map1=[]#判断哪些项有点
i=0#判断胜负查看每一个点的循环变量
for a in range(16):#表示棋盘的行的点
for a in range(16):#表示棋盘列的点
pos.append((x,y))#将点的位置用元祖的方式记录到列表
map1.append(0)#添加元素0代表点,1代表白棋,2代表黑棋
x+=30#记录下一个点
x=10#记录下一行的第一个
y+=30#记录下一行
pygame.mixer.music.load("5a41_37f5_ac53_b2f6f7c0ea87d23a393503caa67a2c5f.mp3")
while True:#游戏循环
if pygame.mixer.music.get_busy()==False:
pygame.mixer.music.play()
x=10#重设x坐标
y=10#重设y坐标
screen.fill((139,69,19))#设置为棋盘的颜色
for event in pygame.event.get():#遍历所有按键
if event.type == pygame.QUIT:#如果按下关闭键
pygame.quit()#关闭窗口
sys.exit()#关闭程序
if event.type==pygame.MOUSEBUTTONDOWN:#判断是否点击鼠标
for b in range(len(pos)):#遍历所有的点的位置
#设置一个虚拟的圆,判断是否鼠标点击每个圆中
if pos[b][0]-15<pygame.mouse.get_pos()[0] and pos[b][0]+15>pygame.mouse.get_pos()[0]:
if pos[b][1]-15<pygame.mouse.get_pos()[1] and pos[b][1]+15>pygame.mouse.get_pos()[1]:
if n==0:
n+=1
p.append(b)#添加点的项
if b!=p[-1]:
n+=1
p.append(b)#添加点的项
if n%2==0:#判断奇偶数
color.append((255,255,255))#将棋子颜色添加到列表
map1[b]=1
else:
color.append((0,0,0))
map1[b]=2
break
for a in range(14):#表示棋盘行的点
for a in range(15):#表示棋盘列的点
pygame.draw.rect(screen,(0,0,0),(x,y,30,30),1)#绘制矩形
x+=30#绘制下一个圆
x=10#绘制下一行的第一个的圆
y+=30#绘制下一行的圆
pygame.draw.circle(screen,(255,0,0),(pygame.mouse.get_pos()[0]+5,pygame.mouse.get_pos()[1]+5),15,1)
i+=1
#绘制一个跟随鼠标的圆
for c in range(len(p)):#判断有多少个点,将这些点都绘制出来
pygame.draw.circle(screen,color[c],pos[p[c]],15,0)#绘制圆形
screen.blit(pygame.font.SysFont("simhei",25).render("棋子数量: "+str(n),0,(255,255,0)),(466,10))
if i==250:#看循环是否结束
i=0#重新检测
#判断横
if map1[i]==1 and map1[i+1]==1 and map1[i+2]==1 and map1[i+3]==1 and map1[i+4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+1]==2 and map1[i+2]==2 and map1[i+3]==2 and map1[i+4]==2:
print("黑棋赢")
break
#判断竖
if map1[i]==1 and map1[i+16]==1 and map1[i+32]==1 and map1[i+48]==1 and map1[i+喵]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16]==2 and map1[i+32]==2 and map1[i+48]==2 and map1[i+喵]==2:
print("黑棋赢")
break
#判断反斜
if map1[i]==1 and map1[i+16+1]==1 and map1[i+32+2]==1 and map1[i+48+3]==1 and map1[i+喵+4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16+1]==2 and map1[i+32+2]==2 and map1[i+48+3]==2 and map1[i+喵+4]==2:
print("黑棋赢")
break
#判断斜
if map1[i]==1 and map1[i+16-1]==1 and map1[i+32-2]==1 and map1[i+48-3]==1 and map1[i+喵-4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16-1]==2 and map1[i+32-2]==2 and map1[i+48-3]==2 and map1[i+喵-4]==2:
print("黑棋赢")
break
#显示棋子数量,因为一共256个交叉点,所以空三格
pygame.display.flip()#刷新游戏2021-06-13T14:51:22 点赞:0
在 灵异事件——招人 中回复
import pygame,sys#导入模块
pygame.init()#游戏初始化
pygame.mixer.init()
pygame.font.init()#汉字初始化
screen = pygame.display.set_mode((650,450))#创建游戏窗口
pygame.display.set_caption("五子棋")#设置游戏窗口的标题
pos=[]#记录棋盘上每一个点的坐标
x=10#记录点的x坐标
y=10#记录点的y坐标
p=[]#记录点的地图位置
n=0#判断棋子的颜色
color=[]#记录棋子的颜色
map1=[]#判断哪些项有点
i=0#判断胜负查看每一个点的循环变量
for a in range(16):#表示棋盘的行的点
for a in range(16):#表示棋盘列的点
pos.append((x,y))#将点的位置用元祖的方式记录到列表
map1.append(0)#添加元素0代表点,1代表白棋,2代表黑棋
x+=30#记录下一个点
x=10#记录下一行的第一个
y+=30#记录下一行
pygame.mixer.music.load("5a41_37f5_ac53_b2f6f7c0ea87d23a393503caa67a2c5f.mp3")
while True:#游戏循环
if pygame.mixer.music.get_busy()==False:
pygame.mixer.music.play()
x=10#重设x坐标
y=10#重设y坐标
screen.fill((139,69,19))#设置为棋盘的颜色
for event in pygame.event.get():#遍历所有按键
if event.type == pygame.QUIT:#如果按下关闭键
pygame.quit()#关闭窗口
sys.exit()#关闭程序
if event.type==pygame.MOUSEBUTTONDOWN:#判断是否点击鼠标
for b in range(len(pos)):#遍历所有的点的位置
#设置一个虚拟的圆,判断是否鼠标点击每个圆中
if pos[b][0]-15<pygame.mouse.get_pos()[0] and pos[b][0]+15>pygame.mouse.get_pos()[0]:
if pos[b][1]-15<pygame.mouse.get_pos()[1] and pos[b][1]+15>pygame.mouse.get_pos()[1]:
if n==0:
n+=1
p.append(b)#添加点的项
if b!=p[-1]:
n+=1
p.append(b)#添加点的项
if n%2==0:#判断奇偶数
color.append((255,255,255))#将棋子颜色添加到列表
map1[b]=1
else:
color.append((0,0,0))
map1[b]=2
break
for a in range(14):#表示棋盘行的点
for a in range(15):#表示棋盘列的点
pygame.draw.rect(screen,(0,0,0),(x,y,30,30),1)#绘制矩形
x+=30#绘制下一个圆
x=10#绘制下一行的第一个的圆
y+=30#绘制下一行的圆
pygame.draw.circle(screen,(255,0,0),(pygame.mouse.get_pos()[0]+5,pygame.mouse.get_pos()[1]+5),15,1)
i+=1
#绘制一个跟随鼠标的圆
for c in range(len(p)):#判断有多少个点,将这些点都绘制出来
pygame.draw.circle(screen,color[c],pos[p[c]],15,0)#绘制圆形
screen.blit(pygame.font.SysFont("simhei",25).render("棋子数量: "+str(n),0,(255,255,0)),(466,10))
if i==250:#看循环是否结束
i=0#重新检测
#判断横
if map1[i]==1 and map1[i+1]==1 and map1[i+2]==1 and map1[i+3]==1 and map1[i+4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+1]==2 and map1[i+2]==2 and map1[i+3]==2 and map1[i+4]==2:
print("黑棋赢")
break
#判断竖
if map1[i]==1 and map1[i+16]==1 and map1[i+32]==1 and map1[i+48]==1 and map1[i+64]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16]==2 and map1[i+32]==2 and map1[i+48]==2 and map1[i+64]==2:
print("黑棋赢")
break
#判断反斜
if map1[i]==1 and map1[i+16+1]==1 and map1[i+32+2]==1 and map1[i+48+3]==1 and map1[i+64+4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16+1]==2 and map1[i+32+2]==2 and map1[i+48+3]==2 and map1[i+64+4]==2:
print("黑棋赢")
break
#判断斜
if map1[i]==1 and map1[i+16-1]==1 and map1[i+32-2]==1 and map1[i+48-3]==1 and map1[i+64-4]==1:
print("白棋赢")
break
if map1[i]==2 and map1[i+16-1]==2 and map1[i+32-2]==2 and map1[i+48-3]==2 and map1[i+64-4]==2:
print("黑棋赢")
break
#显示棋子数量,因为一共256个交叉点,所以空三格
pygame.display.flip()#刷新游戏2021-06-13T14:52:55 点赞:0
在 【Python作品分享】推箱子-变量准备【教程贴】 中回复
#导入模块
from pygame import *
from sys import *
#初始化
init()
font.init()
#显示窗口
screen=display.set_mode((400,400))
#显示标题
display.set_caption("推箱子")
#设置地图坐标
x=0
y=0
#背景颜色
screen.fill((255,255,255))
#设置地图
map1=[]
#循环变量
i=0
#调整地图
for a in range(8):
for a in range(8):
map1.append(0)
for a in range(8):
map1[i]=10
i+=1
i=len(map1)-1
for a in range(8):
map1[i]=10
i-=1
i=8
for a in range(6):
map1[i]=10
i+=8
i=15
for a in range(6):
map1[i]=10
i+=8
map1[0]=0
map1[1]=0
map1[9]=10
map1[10]=10
map1[63]=0
map1[62]=0
map1[54]=10
map1[53]=10
map1[13]=4
map1[44]=5
map1[12]=6
map1[43]=7
map1[49]=1
i=0
k=49#人的编号
d=44#箱子1的编号
o=13#箱子2的编号
while True:#喵循环
for a in event.get():
if a.type==QUIT:
#退出窗口
quit()
exit()
#移动人,箱子
elif a.type == KEYDOWN: #键被按下
if a.key == K_LEFT:
if map1[k-1]==5 and map1[d-1]!=10 and map1[d-8]!=4:
map1[k]=0
k-=1
map1[d]=1
d-=1
map1[d]=5
if map1[k-1]==4 and map1[o-1]!=10 and map1[d-8]!=5:
map1[k]=0
k-=1
map1[o]=1
o-=1
map1[o]=4
if map1[k-1]!=10 and map1[k-1]!=5 and map1[k-1]!=4:
map1[k]=0
k-=1
map1[k]=1
elif a.key == K_RIGHT:
if map1[k+1]==5 and map1[d+1]!=10 and map1[d-8]!=4:
map1[k]=0
k+=1
map1[d]=1
d+=1
map1[d]=5
if map1[k+1]==4 and map1[o+1]!=10 and map1[d-8]!=5:
map1[k]=0
k+=1
map1[o]=1
o+=1
map1[o]=4
if map1[k+1]!=10 and map1[k+1]!=5 and map1[k-8]!=5:
map1[k]=0
k+=1
map1[k]=1
elif a.key == K_UP:
#判断上面是否有箱子,箱子上面是否是墙
#因为图层问题,界面上多显示出一个箱子
if map1[k-8]==5 and map1[d-8]!=10 and map1[d-8]!=4:
map1[k]=0
k-=8
map1[d]=1
d-=8
map1[d]=5
if map1[k-8]==4 and map1[o-8]!=10 and map1[d-8]!=5:
map1[k]=0
k-=8
map1[o]=1
o-=8
map1[o]=4
if map1[k-8]!=10 and map1[k-8]!=5 and map1[k-8]!=4 :
map1[k]=0
k-=8
map1[k]=1
elif a.key == K_DOWN:
if map1[k+8]==5 and map1[d+8]!=10 and map1[d-8]!=4:
map1[k]=0
k+=8
map1[d]=1
d+=8
map1[d]=5
if map1[k+8]==4 and map1[o+8]!=10 and map1[d-8]!=5:
map1[k]=0
k+=8
map1[o]=1
o+=8
map1[o]=4
if map1[k+8]!=10 and map1[k+8]!=5 and map1[k-8]!=5:
map1[k]=0
k+=8
map1[k]=1
#显示地图
for a in range(8):
for a in range(8):
if map1[i]==10:
draw.rect(screen,(196,74,86),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==5:
draw.rect(screen,(219,182,125),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==4:
draw.rect(screen,(219,182,125),(x,y,50,50),0)
draw.rect(screen,(0,0,0),(x,y,50,50),5)
if map1[i]==1:
draw.circle(screen,(55,162,212),(x+20,y+20),20,0)
draw.circle(screen,(0,0,0),(x+20,y+20),20,5)
if map1[i]==6:
draw.rect(screen,(0,212,101),(x,y,30,30),0)
draw.rect(screen,(0,0,0),(x,y,30,30),5)
if map1[i]==7:
draw.rect(screen,(0,212,101),(x,y,30,30),0)
draw.rect(screen,(0,0,0),(x,y,30,30),5)
if map1[i]==0:
draw.rect(screen,(255,255,255),(x,y,50,50),0)
if map1[12]==0:
draw.rect(screen,(0,212,101),(200,60,30,30),0)
draw.rect(screen,(0,0,0),(200,60,30,30),5)
if map1[43]==0:
draw.rect(screen,(0,212,101),(200-30,300-30,30,30),0)
draw.rect(screen,(0,0,0),(200-30,300-30,30,30),5)
i+=1
x+=50
x=0
y+=50
if (map1[12]==4 and map1[43]==4) or (map1[12]==5 and map1[43]==5) or (map1[12]==5 and map1[43]==4) or (map1[12]==4 and map1[43]==5):
font1=font.SysFont('方正喵宋简体',50)
font2=font1.render('恭喜你,闯关成功!',1,(0,0,0))
screen.blit(font2,(0,200))
i=0
x=0
y=0
#刷新
display.flip()2021-06-17T18:08:55 点赞:0
在 【Python作品分享】变量Hello 中回复
a=0放入循环中:
每次新的一次循环中a=0
0+1=1
所以运行结果为hello
如果是
if a==2:
print("hello world")
那么就不可能输出hello world
2021-07-14T12:45:42 点赞:0
在 【Python作品分享】变量Hello 中回复
#开始进入Python的世界
for __count in range(6):
a = 0
a += 1
print(a)
if (a == 1):
print('Hello')
if (a == 2):
print('Hello2')
if (a == 3):
print('Hello3')
if (a == 4):
print('Hello4')
if (a == 5):
print('Hello5')
if (a == 6):
print('Hello6')
2021-07-14T12:47:51 点赞:0
在 【Python作品分享】变量Hello 中回复
运行 结果:
1 Hello 1 Hello 1 Hello 1 Hello 1 Hello 1 Hello
2021-07-14T12:48:14 点赞:0