我们可以在几个代码行中绘制很多东西吗?我想尽快完成这项工作,但我不能。
这是代码:
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)
所以,我希望第二部分缩短。
答案 0 :(得分: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)
我不知道这是否是你想要的,但它会起作用!