我正在进行纸牌游戏,并且有一个抽奖阶段,其编码如下:
def drawPhase():
drawHand = hand
drawDeck = deck
oppDrawHand = oppHand
oppDrawDeck = oppDeck
drawHand.append(drawDeck[0])
oppDrawHand.append(oppDrawDeck[0])
for cards in range(2):
del drawDeck[0]
del oppDrawDeck[0]
return drawHand, drawDeck, oppDrawHand, oppDrawDeck
我只将每个牌的名单附加一次,但出于某种原因,它似乎为每个玩家画了四张牌,我无法弄明白。代码的其他部分似乎与绘图卡无关,但如果问题在前面显示的功能中不明显,我可以发布游戏循环。谢谢!
编辑:这是游戏循环:
while True:
# defining image indexes
currentHandImageIndex = None
endButtonIndex = None
mouse_pos = pygame.mouse.get_pos()
#game loop variables
hand = playerHand
oppHand = oppGetHand
deck = playerDeck
oppDeck = oppGetDeck
benchHand = []
oppBench = []
postHand = []
oppPost = []
perimeterHand = []
oppPerimet = []
showHand = displayHand(hand, oppHand)
handImages = updateHandImages()
#stage variables
step = defStep
isDrawPhase = False
#text_prompt_choose_for_bench.draw_text()
endButtonPressed = False
mouseClick = False
#text drawing
if len(step) == 1:
isDrawPhase = True
text_prompt_enter_draw_phase.draw_text()
if len(step) == 2:
isBenchPhase = True
text_prompt_choose_for_bench.draw_text()
for event in pygame.event.get():
if event.type == QUIT:
terminate()
if event.type == KEYUP:
if event.key == K_ESCAPE:
terminate()
if event.type == MOUSEBUTTONUP:
mouseClick = True
for i, rect in enumerate(HAND_RECTS):
if rect.collidepoint(mouse_pos):
currentHandImageIndex = i
break
for i, rect in enumerate(END_RECT):
if rect.collidepoint(mouse_pos):
endButtonIndex = i
break
if mouseClick == True:
if endButtonIndex is not None:
endButtonPressed = True
if currentHandImageIndex is not None:
if currentHandImageIndex <= len(hand)-1:
DISPLAYSURF.blit(handImages[currentHandImageIndex], (925,200))
if isDrawPhase == True:
if endButtonPressed == True:
hand, deck = drawPhase()[0], drawPhase()[1]
oppHand, oppDeck = drawPhase()[2], drawPhase()[3]
endButtonPressed = False
isDrawPhase = False
step.append(1)
drawPlayMat()
答案 0 :(得分:0)
drawHand.append(drawDeck[0])
oppDrawHand.append(oppDrawDeck[0])
for cards in range(2):
del drawDeck[0]
del oppDrawDeck[0]
此代码会为您的牌添加一张牌,但会从您的牌组中移除两张牌,并与对手的牌和牌组相同。这似乎不对。