pygame游戏尝试不起作用,我不知道为什么

问题描述

所以我正试图使这款游戏连续叫4,对于pygame和python我还是很陌生,所以是的... 它说它崩溃是因为近距离获取不到vpos值,但我确实将其设置为y数组...

import pygame
pygame.init()
screen = pygame.display.set_mode([620,520])
running = True
Emptygray = (220,220,220)
Bordergray = (105,105,105)
y = []
x = []
m = 0
n = 0
urgo = True
for i in range(0,30): 
    x.append(0) 
    y.append(0)
    m = 0
    n = 0
def getclosest(mousey,vpos):
    r = 0
    for i in range(0,5):
        s = abs(mousey[1] - vpos[i])
        if r < s: r = i
    return r

print(len(x))
while running:
    screen.fill((202,164,114))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    for i in range(0,6):
        for j in range(0,5):
            a = 60
            b = 60
            pygame.draw.circle(screen,Bordergray,( a + 100 * i,b + 100 * j),47)
            if n < 30: x[n] = [a + 100 * i]
            if n <= 30: n += 1
            pygame.draw.circle(screen,Emptygray,44)
            if m < 30: y[m] = [b + 100 * j]
            if m <= 30: m += 1
    if urgo:
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONUP:
                print(mousey = getclosest(pygame.mouse.get_pos()),vpos = y[0:4])
    pygame.display.flip()
    #print ("x:",x)
    #print ("y:",y)
Exception has occurred: TypeError
getclosest() missing 1 required positional argument: 'vpos'
  File "C:\Users\NOEL\Desktop\Folders\Python\Game\3.py",line 43,in <module>
    print(mousey = getclosest(pygame.mouse.get_pos()),vpos = y[0:4])

解决方法

print(mousey = getclosest(pygame.mouse.get_pos()),vpos = y[0:4])

应该是

print(mousey = getclosest(pygame.mouse.get_pos(),vpos = y[0:4]))