我昨天问了一个关于这个程序的问题,但我遇到了另一个问题。代码仍然运行并认为它以像素为单位着色,但是当到达页面底部时它应该停止,它没有。
这是代码:
import pygame,sys, random, time
y = 0
x = 0
keepgoing = True
pygame.init()
screen = pygame.display.set_mode((500,500))
pixel = raw_input('Please enter a NUMBER that goes into 500. ')
end = 500-(int(pixel))
int(pixel)
screen.fill((255,255,255))
while keepgoing:
print x,y
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
pygame.draw.rect(screen, (r,g,b),(x,y,int(pixel),int(pixel)))
if x >= end:
x = 0
y += int(pixel)
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
pygame.draw.rect(screen, (r,g,b),(x,y,int(pixel),int(pixel)))
if x == end and y == end:
print 'done'
keepgoing == False
break
x += (int(pixel))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit();
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit();
如果你在 python IDLE 中运行代码,你会明白我的意思。