2016-02-23 80 views
0

我們可以在幾行代碼中繪製很多東西嗎?我想盡快完成這項工作,但我做不到。在PyGame中繪製很多東西

這是代碼:

def village_pointlist_creator(village_number, timer=0): 
    global pointlist 
    pointlist = [] 
    while (village_number + 1) != timer: 
     k = random.randrange(50, 551, 100) 
     p = random.randrange(50, 551, 100) 
     # we should check the points here. 
     pointlist.append((k, p)) 
     timer += 1 
    return pointlist 

def village_display(pointlist): 
    pygame.draw.circle(window, black, (pointlist[0][0], pointlist[0][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[1][0], pointlist[1][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[2][0], pointlist[2][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[3][0], pointlist[3][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[4][0], pointlist[4][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[5][0], pointlist[5][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[6][0], pointlist[6][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[7][0], pointlist[7][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[8][0], pointlist[8][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[9][0], pointlist[9][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[10][0], pointlist[10][1]), 25) 
    pygame.draw.circle(window, black, (pointlist[11][0], pointlist[11][1]), 25) 

所以,我想第二部分短。

回答

2

您可以嘗試使用for循環複製pygame.draw.circle()代碼,然後用for循環變量替換更改的參數。

def village_display(pointlist): 
    for i in range(12): 
     pygame.draw.circle(window, black, (pointlist[i][0], pointlist[i][1]), 25) 

我不知道這是你想要的,但它會工作!