我不确定屏幕是否有问题,但每次运行此代码时:
import pygame
import engine
import sys
# screen config
height = 500
width = 500
dimension = 8 #dimension of an 8x8 chess board
square_size = height//dimension
FPS = 30
#pygame settings
pygame.init()
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Tapton Chess Club')
clock = pygame.time.Clock()
screen.fill(pygame.Color("white"))
board_format = engine.game_logic()
def draw_board(screen, board_format):
draw_squares(screen)
#draw squares on screen using 2d array
def draw_squares(screen):
square_colours = [pygame.Color("#e8ebef"), pygame.Color("#7d8796")]
for row in range(dimension):
for column in range(dimension):
sq_colour = square_colours[((row+column)%2)] #used to find the colour of the square
pygame.draw.rect(screen, sq_colour, pygame.rect(row*square_size, column*square_size, square_size, square_size))
#pygame event loop to register user input
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
draw_board(screen, board_format)
clock.tick(FPS)
pygame.display.flip()
我收到这些错误: picture of output in IDLE
请帮助我,我对此很陌生,我不确定我做错了什么。我最近重新整理了很多文件,但这是我能想到的唯一答案。
答案 0 :(得分:2)
因为你使用
pygame.rect(row*square_size, column*square_size, square_size, square_size)
代替
pygame.Rect(row*square_size, column*square_size, square_size, square_size)
pygame.rect
是一个模块,pygame.Rect
是一个类。