用户:
121115查看:0 回复:0 评论:0 创建时间:2023-11-10T21:24:24
【作品展示】

【作品介绍】
这次是有开场界面的。
【作品源代码】
import pygame
WIDTH = 750
HEIGHT = 750
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
row_map = [0]*15
for i in range(15):
row_map[i] = [0]*15
player = 1
winner = 0
running = True
show_init = True
def draw_init():
screen.fill("#EE9A49")
font = pygame.font.Font("font.ttf", 70)
text_surface = font.render("按下鼠标开始", True, "#000000")
text_position = (170,200)
screen.blit(text_surface, text_position)
while show_init:
draw_init()
for event in pygame.event.get():
if event.type == pygame.QUIT:
show_init = False
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
show_init = False
if show_init == True:
pygame.display.update()
def check(row,col):
score = 1
for i in range(4):
if row_map[row][col+i] == row_map[row][col+i+1]:
score += 1
else:
break
for i in range(4):
if row_map[row][col-i] == row_map[row][col-i-1]:
score += 1
else:
break
if score == 5:
return True
score = 1
for i in range(4):
if row_map[row+i][col] == row_map[row+i+1][col]:
score += 1
else:
break
for i in range(4):
if row_map[row-i][col] == row_map[row-i-1][col]:
score += 1
else:
break
if score == 5:
return True
score = 1
for i in range(4):
if row_map[row+i][col+i] == row_map[row+i+1][col+i+1]:
score += 1
else:
break
for i in range(4):
if row_map[row-i][col-i] == row_map[row-i-1][col-i-1]:
score += 1
else:
break
if score == 5:
return True
score = 1
for i in range(4):
if row_map[row+i][col-i] == row_map[row+i+1][col-i-1]:
score += 1
else:
break
for i in range(4):
if row_map[row-i][col+i] == row_map[row-i-1][col+i+1]:
score += 1
else:
break
if score == 5:
return True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
x, y = pygame.mouse.get_pos()
col = round((x - 25)/50)
row = round((y - 25)/50)
if row_map[row][col] == 0:
row_map[row][col] = player
if (check(row,col)):
winner = player
else:
if player == 1:
player = 2
else:
player = 1
else:
print("这里有子")
screen.fill("#EE9A49")
for x in range(15):
pygame.draw.line(screen, "#000000", [25+50*x, 25], [25+50*x, 725], 2)
for x in range(15):
pygame.draw.line(screen, "#000000", [25, 25+50*x], [725, 25+50*x], 2)
pygame.draw.circle(screen, "#000000", [25 + 50*7, 25 + 50*7],8)
x, y = pygame.mouse.get_pos()
x = round((x - 25)/50)*50 + 25
y = round((y - 25)/50)*50 + 25
pygame.draw.rect(screen,"#FFFFFF",[x - 25,y - 25,50,50],2)
for row in range(15):
for col in range(15):
if row_map[row][col] == 1:
pygame.draw.circle(screen,"#000000",[col*50+25,row*50+25],25)
if row_map[row][col] == 2:
pygame.draw.circle(screen, "#FFFFFF", [col*50+25, row*50+25], 25)
pygame.display.update()
if(winner!=0):
if winner == 1:
text = '黑子赢了!3秒关闭'
color = (0,0,0)
else:
text = '白子赢了!3秒关闭'
color = (255, 255, 255)
font = pygame.font.Font("font.ttf",70)
text_surface = font.render(text,True,color)
text_position = (100,100)
screen.blit(text_surface,text_position)
pygame.display.update()
pygame.time.wait(3000)
running = False
pygame.quit()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn