def __init__(self, db): # Initialize PyGame pygame.init() self.stateMachine = StateMachine() # States self.stateMachine.addState("TitleScreen", TitleScreen(self.stateMachine, db)) self.stateMachine.addState("Settings", Settings(self.stateMachine)) self.stateMachine.addState("InGame", InGame(self.stateMachine)) # Transitions self.stateMachine.addTransition("toTitleScreen", Transition("TitleScreen")) self.stateMachine.addTransition("toSettings", Transition("Settings")) self.stateMachine.addTransition("toInGame", Transition("InGame")) # Set the initial state self.stateMachine.setState("TitleScreen") # Initialize Managers self.eventManager = EventManager(self.stateMachine) self.displayManager = DisplayManager(self.stateMachine) self.menuManager = MenuManager(self.stateMachine)
class GameEngine(object): def __init__(self, db): # Initialize PyGame pygame.init() self.stateMachine = StateMachine() # States self.stateMachine.addState("TitleScreen", TitleScreen(self.stateMachine, db)) self.stateMachine.addState("Settings", Settings(self.stateMachine)) self.stateMachine.addState("InGame", InGame(self.stateMachine)) # Transitions self.stateMachine.addTransition("toTitleScreen", Transition("TitleScreen")) self.stateMachine.addTransition("toSettings", Transition("Settings")) self.stateMachine.addTransition("toInGame", Transition("InGame")) # Set the initial state self.stateMachine.setState("TitleScreen") # Initialize Managers self.eventManager = EventManager(self.stateMachine) self.displayManager = DisplayManager(self.stateMachine) self.menuManager = MenuManager(self.stateMachine) # ( Handle Events, Update Game State, Draw Screen ) def execute(self): # Handle events self.eventManager.run() self.stateMachine.execute() self.displayManager.run()