在已经创建的正方形上绘制一个圆圈 - pygame

时间:2018-03-04 20:46:19

标签: python pygame geometry

我目前正试图在游戏中制作一个棋盘游戏,但这需要在棋盘上的正方形中获得棋子,但是当我运行时,只有棋盘会出现,但没有一块。在这个程序中,我只做了一块黑色的碎片,它只是一个普通的黑色圆圈。我想知道是否有人知道如何在已经绘制的方块上绘制圆圈。

def drawPlayer1Circle(row):
    if (row<=2):
        return True
    else:
        return False
def drawPlayer2Circle(row):
    if (row>=5) and (row%2!=0 and column%2==0) and (row%2!=0 and column%2!=0):
        return True
    else:
        return False

def drawCircle():

    pygame.draw.circle(screen,BLACK,[((MARGIN + WIDTH) * column + MARGIN)+xDistanceFromEdge,
        (MARGIN + HEIGHT) * row + MARGIN,
        WIDTH/2,
            HEIGHT/2],WIDTH/2)
def drawBoard(BLACK,WHITE):# Draw the grid
    for row in range(8):
        for column in range(8):
            if row%2==0 and column%2==0:
                color = BLACK
            if row%2!=0 and column%2==0:
                color = WHITE
                if drawPlayer1Circle(row)==True:
                    drawCircle()
            if row%2==0 and column%2!=0:
                color=WHITE
            if row%2!=0 and column%2!=0:
                color= BLACK
                if drawPlayer1Circle(row)==True:
                    drawCircle()
            pygame.draw.rect(screen,
                             color,
                             [((MARGIN + WIDTH) * column + MARGIN)+xDistanceFromEdge,
                              (MARGIN + HEIGHT) * row + MARGIN,
                              WIDTH,
                              HEIGHT]) 

1 个答案:

答案 0 :(得分:0)

看起来你正在画板前画圆圈,所以棋盘被画在顶部。此外,您应该将rowcolumn传递给函数drawCircle,并且不必要地重复此部分代码:

        if row%2==0 and column%2==0:
            color = BLACK
        if row%2!=0 and column%2==0:
            color = WHITE
            if drawPlayer1Circle(row)==True:
                drawCircle()