''' 如何設計使用隨機變數來賽馬,此程式表達賽馬時馬的細膩動作 by Ching-Shoei Chiang ''' import random, pygame, sys from pygame.locals import * pygame.init() FPS = 30 # frames per second setting fpsClock = pygame.time.Clock() # set up the window screen = pygame.display.set_mode((800, 150), 0, 32) pygame.display.set_caption('Animation') WHITE = (255, 255, 255) horsex = horsey = 0 notend = True i = 0 while notend: # the main game loop for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() screen.fill(WHITE) horseImg = pygame.image.load('image'+str(i)+'.jpg') i = (i+1)%15 horsex = horsex + random.randint(1,3) if horsex > 650: notend = False screen.blit(horseImg, (horsex, horsey)) pygame.display.update() fpsClock.tick(FPS)