所以基本上我是和四个玩家一起玩纸牌游戏。每个玩家有9张牌。卡对象存储在p1Images
,p2Images
,p3Images
,p4Images
中。
我只看到自己的卡片(player1
)。因此,当我单击其中一张卡片时,它将被放置在屏幕中央。我的问题是,在绘制所有图像时,在主循环中有时不起作用,因为例如,我玩p1Images[7]
时,绘制从索引0开始,因此索引7将在以后绘制,导致player2
,3
,4
卡位于p1Images[7]
卡下。因此,当我按空格键时,似乎什么也没发生,因为p1Images[7]
将卡片隐藏在其下。我该怎么解决?
def placeCard(player):
card = player.hand[0]
player.play(0)
card.positionX = cardPlaceX+5
card.positionY = cardPlaceY+10
while True:
...
for e in pygame.event.get():
if e.type == QUIT:
pygame.quit()
sys.exit()
if e.type == MOUSEBUTTONDOWN:
mx,my = pygame.mouse.get_pos()
for i in range(0,9):
if(mx>=p1Images[i].startposX and mx<=p1Images[i].startposX+80 and my>= p1Images[i].startposY and my<=p1Images[i].startposY+200):
p1Images[i].positionX = cardPlaceX + 5
p1Images[i].positionY = cardPlaceY + 10
placedCardNumber = 1
if e.type == KEYDOWN:
if (e.key == K_SPACE and placedCardNumber == 1):
placeCard(player2)
if (e.key == K_SPACE and placedCardNumber == 2):
placeCard(player3)
if (e.key == K_SPACE and placedCardNumber == 3):
placeCard(player4)
placedCardNumber += 1
if(placedCardNumber == 4):
placedCardNumber = 0
for i in range(0,9):
drawingCard = pygame.image.load(p1Images[i].path)
DISPLAYSURF.blit(drawingCard, (p2Images[i].positionX, cardImages[i].positionY))
drawingCard2 = pygame.image.load(p2Images[i].path)
DISPLAYSURF.blit(drawingCard2, (p2Images[i].positionX, p2Images[i].positionY))
drawingCard3 = pygame.image.load(p3Images[i].path)
DISPLAYSURF.blit(drawingCard3, (p3Images[i].positionX, p3Images[i].positionY))
drawingCard4 = pygame.image.load(p4Images[i].path)
DISPLAYSURF.blit(drawingCard4, (p4Images[i].positionX, p4Images[i].positionY))