0
這段代碼應該打印多米諾骨牌[4,2],但它只填充表面白色並且不打印任何東西。 我沒有得到一個錯誤,我找不到我做錯了什麼。爲什麼pygame中的這個函數不起作用
import os
import string
import random
import pygame, sys
from pygame.locals import *
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
def main():
global DISPLAYSURF
pygame.init()
DISPLAYSURF = pygame.display.set_mode((1300, 600), 0, 32)
pygame.display.set_caption('domino test')
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
DISPLAYSURF.fill(WHITE)
printpiece([4,2],(400,200))
pygame.display.update()
def printpiece(piece, position):
def printdots(number, centre):
def printdot(dot, centre):
if dot == "AA":
pygame.draw.circle(DISPLAYSURF, BLACK, (centre[0]-15, centre[1]-15), 3, 3)
elif dot == "AB":
pygame.draw.circle(DISPLAYSURF, BLACK, (centre[0]-15, centre[1]), 3, 3)
elif dot == "AC":
pygame.draw.circle(DISPLAYSURF, BLACK, (centre[0]-15, centre[1]+15), 3, 3)
elif dot == "BB":
pygame.draw.circle(DISPLAYSURF, BLACK, (centre[0], centre[1]), 3, 3)
elif dot == "CA":
pygame.draw.circle(DISPLAYSURF, BLACK, (centre[0]+15, centre[1]-15), 3, 3)
elif dot == "CB":
pygame.draw.circle(DISPLAYSURF, BLACK, (centre[0]+15, centre[1]), 3, 3)
elif dot == "CC":
pygame.draw.circle(DISPLAYSURF, BLACK, (centre[0]+15, centre[1]+15), 3, 3)
if number == 1:
printdot("BB", centre)
elif number == 2:
printdot("AC", centre)
printdot("CA", centre)
elif number == 3:
printdot("AC", centre)
printdot("BB", centre)
printdot("CA", centre)
elif number == 4:
printdot("AA", centre)
printdot("CA", centre)
printdot("AC", centre)
printdot("CC", centre)
elif number == 5:
printdot("AA", centre)
printdot("CA", centre)
printdot("BB", centre)
printdot("AC", centre)
printdot("CC", centre)
elif number == 6:
printdot("AA", centre)
printdot("AB", centre)
printdot("AC", centre)
printdot("CA", centre)
printdot("CB", centre)
printdot("CC", centre)
pygame.draw.rect(DISPLAYSURF, BLACK, (position[0]-5, position[1]-5, 110, 60))
pygame.draw.rect(DISPLAYSURF, WHITE, (position[0], position[1], 100, 50))
pygame.draw.line(DISPLAYSURF, BLACK, (position[0]+50, position[1]), (position[0]+50, position[1]+50), 2)
printdots(piece[0], (position[0]+25, position[1]+25))
printdots(piece[1], (position[0]+75, position[1]+25))
if __name__ == '__main__':
main()
謝謝你,我好高興我能夠繼續現在的工作計劃,我定了這個bug! – zom4