-2
我在python中使用面向對象的編程我寫了這段代碼,但我不知道在GameLoop()
中寫什麼來執行它! 要花1個參數及其self
如何插入自我參數?
`
import pygame
class game:
pygame_ = pygame.init()`
def __init__(self):
self.Color = {}
with open("ColorData.gmd") as f:
data = f.readlines();
for row in data:
self.Color[row.split("=")[0]] = row.split("=")[1]
for row in self.Color:
self.Color[row] = eval(self.Color[row])
self.root_x = 500
self.root_y = 500
self.root = pygame.display.set_mode((self.root_x,self.root_y))
def GameLoop(self):
FPS = 60
clock = pygame.time.Clock()
gameExit = False
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = True
self.root.fill(self.Color["RED"])
pygame.display.update()
clock.tick(FPS)
if gameExit:
pygame.quit()
exit()
GameLoop()
`
我覺得這是很清楚運算是問;關於如何/爲什麼'self'參數被自動添加用於有界的方法引用。 – fortran