簡體   English   中英

Pygame 游戲嘗試不起作用,我不知道為什么

[英]Pygame game attempt not working and i can't figure out why

所以我試圖讓這個游戲連續稱為 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, ( a + 100 * i, b + 100 * j), 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]))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM