我正在尝试使用 pygame 实现菱形破折号游戏。更具体地说,当您在一行或一列中用鼠标单击 3 个相同颜色的方块时,这些方块必须被删除,并且新的方块必须随机占据它们的位置。我的程序可以找到一个正方形的特定坐标,但我在努力如何删除这些特定的正方形。
你能帮我吗?谢谢你。
import random, time, pygame, sys, copy
from pygame.locals import *
black = ( 0, 0, 0)
white = ( 255, 255, 255)
green = ( 0, 255, 0)
red = ( 255, 0, 0)
size = [700, 485]
screen=pygame.display.set_mode(size)
# This sets the width and height of each grid location
width = 64
height = 64
# This sets the margin between each cell
margin = 5
# Create a 2 dimensional array. A two dimesional
# array is simply a list of lists.
grid = []
for row in range(7):
# Add an empty array that will hold each cell
# in this row
grid.append([])
for column in range(80):
grid[row].append(0) # Append a cell
imgnum = 7
imglist = []
for i in range(1, imgnum+1):
dimge = pygame.image.load('imge%s.png' % i)
imglist.append(dimge)
grid[1][5] = 1
pygame.init()
pygame.display.set_caption("dimond dash")
done = False
for row in range(7):
for column in range(8):
screen.blit(random.choice(imglist), [(margin+width)*column+margin,
(margin+height)*row+margin,
width,
height])
while done == False:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
elif event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
column = pos[0] // (width + margin)
row = pos[1] // (height + margin)
grid[row][column] = 1
print("Click ", pos, "Grid coordinates: ", row, column)
pygame.display.flip()
pygame.quit()