+ =:' int'不支持的操作数类型和' NoneType'

时间:2015-06-18 18:26:32

标签: python python-2.7 nonetype

def moveWall (paddleWall, paddleWallDirY):
    paddleWall.y+=paddleWallDirY
    return paddleWall

def main():
    pygame.init()
    global DISPLAYSURF
    ##Font information
    global BASICFONT, BASICFONTSIZE
    BASICFONTSIZE = 20
    BASICFONT = pygame.font.Font('freesansbold.ttf', BASICFONTSIZE)

    FPSCLOCK = pygame.time.Clock()
    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT)) 
    pygame.display.set_caption('Pong')

    #Initiate variable and set starting positions
    #any future changes made within rectangles
    WallX = WINDOWWIDTH/2 - LINETHICKNESS/2
    WallY = (WINDOWHEIGHT)/2 - LINETHICKNESS/2
    ballX = WINDOWWIDTH/2 - LINETHICKNESS/2
    ballY = WINDOWHEIGHT/2 - LINETHICKNESS/2
    playerOnePosition = (WINDOWHEIGHT - PADDLESIZE) /2
    playerTwoPosition = (WINDOWHEIGHT - PADDLESIZE) /2
    score = 0

    #Keeps track of ball direction
    ballDirX = -1 ## -1 = left 1 = right
    ballDirY = -1 ## -1 = up 1 = down
    paddleWallDirX = 0
    paddleWallDirY = 1

    #Creates Rectangles for ball and paddles.
    paddle1 = pygame.Rect(PADDLEOFFSET,playerOnePosition, LINETHICKNESS,PADDLESIZE)
    paddle2 = pygame.Rect(WINDOWWIDTH - PADDLEOFFSET - LINETHICKNESS, playerTwoPosition, LINETHICKNESS,PADDLESIZE)
    paddle3 = pygame.Rect(PADDLEOFFSET,playerOnePosition, LINETHICKNESS,PADDLESIZE)
    paddleWall = pygame.Rect(WallX, WallY, LINETHICKNESS, 100)  
    ball = pygame.Rect(ballX, ballY, LINETHICKNESS, LINETHICKNESS)

    #Draws the starting position of the Arena
    drawArena()
    drawPaddle(paddle1)
    drawPaddle(paddle2)
    drawPaddle(paddle3)
    drawPaddle(paddleWall)
    drawBall(ball)

    pygame.mouse.set_visible(0) # make cursor invisible

    while True: #main game loop
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            # mouse movement commands
            elif event.type == MOUSEMOTION:
                mousex, mousey = event.pos
                paddle1.y = mousey
                paddle3.y = mousey - 100

        drawArena()
        drawPaddle(paddle1)
        drawPaddle(paddle2)
        drawPaddle(paddle3)
        drawPaddle(paddleWall)
        drawBall(ball)

        paddleWall = moveWall(paddleWall, paddleWallDirY)
        ball = moveBall(ball, ballDirX, ballDirY)
        ballDirX, ballDirY = checkEdgeCollision(ball, ballDirX, ballDirY)
        paddleWallDirY = checkEdgeCollisionWall(paddleWall, paddleWallDirY)
        score = checkPointScored(paddle1, paddle3, ball, score, ballDirX)
        ballDirX = ballDirX * checkHitBall(ball, paddle1, paddle2, paddle3, paddleWall, ballDirX)
        paddle2 = artificialIntelligence (ball, ballDirX, paddle2)

我无法解决这个问题,我确实在主方法中给了paddleWallDirY值1

1 个答案:

答案 0 :(得分:0)

你的第二个参数是None:

moveWall(pw, None)

或间接:

x = None
...
moveWall(pw, x)

请注意,None值可能是函数调用的结果,例如。