def _setupGame(cls): """ Assumes the game setting location has been set Since the game mechanics are run by singletons set them up once at the start of this test class. Then each instance test will just use the pre-initialized singletons The initializaton code copied from PyTrekView TODO: perhaps should go in a utility class so it is always current """ TestBase.resetSingletons() TestFutureEventHandlers.clsGameSettings = GameSettings( ) # Be able to read the preferences file TestFutureEventHandlers.clsGameState = GameState( ) # Set up the game parameters which uses the above TestFutureEventHandlers.clsGameEngine = GameEngine( ) # Then the engine needs to be initialized TestFutureEventHandlers.clsIntelligence = Intelligence() TestFutureEventHandlers.clsComputer = Computer() TestFutureEventHandlers.clsGalaxy = Galaxy() TestFutureEventHandlers.clsEventEngine = EventEngine( LogMessageConsole()) TestFutureEventHandlers.clsQuadrantMediator = QuadrantMediator() TestFutureEventHandlers.clsGalaxyMediator = GalaxyMediator( ) # This essentially finishes initializing most of the game
def __init__(self): super().__init__() self.logger: Logger = getLogger(__name__) self._gameSettings: GameSettings = GameSettings() self._gameState: GameState = GameState() self._gameEngine: GameEngine = GameEngine() self._intelligence: Intelligence = Intelligence() self._computer: Computer = Computer() self._galaxy: Galaxy = Galaxy() self._devices: Devices = Devices() self._messageConsole: SchedulerTestMessageConsole = SchedulerTestMessageConsole( ) self._eventEngine: EventEngine = EventEngine(self._messageConsole) self._quadrantMediator: QuadrantMediator = QuadrantMediator() self._quadrant: Quadrant = self._galaxy.currentQuadrant self._gameState.currentQuadrantCoordinates = self._galaxy.currentQuadrant.coordinates enterprise: Enterprise = self._gameState.enterprise self._quadrantMediator.enterQuadrant(quadrant=self._quadrant, enterprise=enterprise) self._createInitialEvents()
def init(self, *args, **kwds): self.logger: Logger = getLogger(__name__) self._gameEngine: GameEngine = GameEngine() self._gameState: GameState = GameState() self._gameSettings: GameSettings = GameSettings() self._computer: Computer = Computer() self._intelligence: Intelligence = Intelligence() self._ktm: KlingonTorpedoMediator = KlingonTorpedoMediator() self._ctm: CommanderTorpedoMediator = CommanderTorpedoMediator() self._ptm: EnterpriseTorpedoMediator = EnterpriseTorpedoMediator() self._stm: SuperCommanderTorpedoMediator = SuperCommanderTorpedoMediator( ) self._km: KlingonMediator = KlingonMediator() self._cm: CommanderMediator = CommanderMediator() self._scm: SuperCommanderMediator = SuperCommanderMediator() self._epm: EnterprisePhaserMediator = EnterprisePhaserMediator() self._messageConsole: MessageConsole = MessageConsole() self._soundMachine: SoundMachine = SoundMachine() self._playerList: SpriteList = SpriteList() self._klingonList: SpriteList = SpriteList() self._commanderList: SpriteList = SpriteList() self._superCommanderList: SpriteList = SpriteList()
def _setupGame(cls): """ Assumes the game setting location has been set Since the game mechanics are run by singletons set them up once at the start of this test class. Then each instance test will just use the pre-initialized singletons The initializaton code copied from PyTrekView TODO: perhaps should go in a utility class so it is always current """ TestBase.resetSingletons() TestEventEngine.clsLogMessageConsole = LogMessageConsole() TestEventEngine.clsGameSettings = GameSettings( ) # Be able to read the preferences file TestEventEngine.clsIntelligence = Intelligence() TestEventEngine.clsGameState = GameState( ) # Set up the game parameters which uses the above TestEventEngine.clsGameState.currentQuadrantCoordinates = TestEventEngine.clsIntelligence.generateQuadrantCoordinates( ) TestEventEngine.clsGameEngine = GameEngine( ) # Then the engine needs to be initialized TestEventEngine.clsEventEngine = EventEngine( TestEventEngine.clsLogMessageConsole) TestEventEngine.clsDevices = Devices() TestEventEngine.clsGalaxy = Galaxy()
def __init__(self, coordinates: Coordinates): """ Initialize a quadrant """ from pytrek.engine.GameEngine import GameEngine # Avoid recursion self.logger: Logger = getLogger(__name__) self._coordinates: Coordinates = coordinates self._sectors: QuadrantGrid = QuadrantGrid([]) self._intelligence: Intelligence = Intelligence() self._gameEngine: GameEngine = GameEngine() self._gameSettings: GameSettings = GameSettings() self._klingonCount: int = 0 self._commanderCount: int = 0 self._superCommanderCount: int = 0 self._hasStarBase: bool = False self._hasPlanet: bool = False self._hasSuperNova: bool = False self._scanned: bool = False self._klingons: Enemies = Enemies([]) self._commanders: Enemies = Enemies([]) self._superCommanders: Enemies = Enemies([]) self._planet: Planet = cast(Planet, None) self._starBase: StarBase = cast(StarBase, None) self._enterprise: Enterprise = cast(Enterprise, None) self._enterpriseCoordinates: Coordinates = cast(Coordinates, None) self._starBaseCoordinates: Coordinates = cast(Coordinates, None) self._createQuadrant()
def init(self, *args, **kwds): self.logger: Logger = getLogger(__name__) self._computer: Computer = Computer() self._gameState: GameState = GameState() self._gameEngine: GameEngine = GameEngine() self._galaxy: Galaxy = Galaxy()
def setUp(self): self.logger: Logger = TestGameEngine.clsLogger self._gameSettings: GameSettings = GameSettings() self._gameEngine: GameEngine = GameEngine() self._gameState: GameState = GameState() self._computer: Computer = Computer() self._devices: Devices = Devices()
def setup(self): SettingsCommon.determineSettingsLocation() # self._backgroundSprite: QuadrantBackground = QuadrantBackground() fqFileName: str = LocateResources.getResourcesPath(resourcePackageName=LocateResources.IMAGE_RESOURCES_PACKAGE_NAME, bareFileName='QuadrantBackground.png') self.background = load_texture(fqFileName) # Create the 'physics engine' # self.physicsEngine = PhysicsEngineSimple(self._enterprise, self._hardSpriteList) # These singletons are initialized for the first time self._gameSettings = GameSettings() # Be able to read the preferences file self._gameState = GameState() # Set up the game parameters which uses the above self._gameEngine = GameEngine() # Then the engine needs to be initialized self._intelligence = Intelligence() self._computer = Computer() self._galaxy = Galaxy() # This essentially finishes initializing most of the game self._messageConsole: MessageConsole = MessageConsole() self._eventEngine: EventEngine = EventEngine(self._messageConsole) self._statusConsole: StatusConsole = StatusConsole(gameView=self) # UI elements self._soundMachine: SoundMachine = SoundMachine() self._enterprise: Enterprise = self._gameState.enterprise # Important mediators self._enterpriseMediator: EnterpriseMediator = EnterpriseMediator(view=self, warpTravelCallback=self._enterpriseHasWarped) self._quadrantMediator: QuadrantMediator = QuadrantMediator() self._galaxyMediator: GalaxyMediator = GalaxyMediator() self._quadrant: Quadrant = self._galaxy.currentQuadrant self._gameState.currentQuadrantCoordinates = self._galaxy.currentQuadrant.coordinates # And finally the rest of the UI elements self._quadrantMediator.enterQuadrant(quadrant=self._quadrant, enterprise=self._enterprise) self.logger.info(f'{self._enterprise=}') self.logger.info(f'{self._quadrant=}') self.logger.info(f'Setup Complete')
def setUp(self): self.logger: Logger = TestIntelligence.clsLogger self._gameEngine: GameEngine = GameEngine() self._gameSettings: GameSettings = GameSettings() self._gameState: GameState = GameState() self.smarty: Intelligence = Intelligence() self._savePlayerType: PlayerType = self._gameSettings.playerType self._saveGameType: GameType = self._gameSettings.gameType self._powerTestPlayerType: PlayerType = cast(PlayerType, None)
def __init__(self): self._missesMediatorLogger: Logger = getLogger(__name__) super().__init__() self._gameState: GameState = GameState() self._gameEngine: GameEngine = GameEngine() self._intelligence: Intelligence = Intelligence() self._gameSettings: GameSettings = GameSettings() self._messageConsole: MessageConsole = MessageConsole()
def __init__(self): super().__init__() self.logger: Logger = getLogger(__name__) self._gameSettings: GameSettings = GameSettings() self._gameEngine: GameEngine = GameEngine() self._gameState: GameState = GameState() self._messageConsole: MessageConsole = MessageConsole() self._soundMachine: SoundMachine = SoundMachine() self._phaserBolts: SpriteList = SpriteList() self._phaserFireTextures: TextureList = self._loadFirePhaserTextures()
def setup(self): """ Set up the game here. Call this function to restart the game. """ fqFileName: str = LocateResources.getResourcesPath( resourcePackageName=LocateResources.IMAGE_RESOURCES_PACKAGE_NAME, bareFileName='QuadrantBackground.png') self.background = load_texture(fqFileName) self._gameSettings = GameSettings() self._gameState = GameState() self._gameEngine = GameEngine() self._intelligence = Intelligence() self._computer = Computer() self._galaxy = Galaxy() self._quadrantMediator = QuadrantMediator() self._enterprise: Enterprise = self._gameState.enterprise self._quadrant: Quadrant = self._galaxy.currentQuadrant self._quadrant.klingonCount = 0 self._quadrant.commanderCount = 0 self._quadrant.superCommanderCount = 0 currentSectorCoordinates: Coordinates = self._intelligence.generateSectorCoordinates( ) self._gameState.currentQuadrantCoordinates = self._galaxy.currentQuadrant.coordinates self._gameState.currentSectorCoordinates = currentSectorCoordinates self._quadrantMediator.enterQuadrant(quadrant=self._quadrant, enterprise=self._enterprise) self._enterpriseMediator: EnterpriseMediator = EnterpriseMediator( view=self, warpTravelCallback=self._noOp) self._statusConsole = StatusConsole(gameView=self) self._messageConsole = MessageConsole() self._makeEnemySpriteLists() self._makeGamePiecePalette() self.logger.info(f'Setup Complete')
def init(self, *args, **kwds): """""" self._gameEngine: GameEngine = GameEngine() self._intelligence: Intelligence = Intelligence() self._gameState: GameState = GameState() self._gameSettings: GameSettings = GameSettings() self.logger: Logger = getLogger(__name__) self._currentQuadrant: Quadrant = cast(Quadrant, None) self.quadrants: GalaxyGrid = GalaxyGrid([]) # 2D array aka python list self._createGalaxy() self._addEnemies() self._placeStarBasesInGalaxy() self._placePlanetsInGalaxy() self._setInitialQuadrant() self.logger.info(f'Galaxy singleton initialized')
class PyTrekView(View): """ Main application class. NOTE: Go ahead and delete the methods you don't need. If you do need a method, delete the 'pass' and replace it with your own code. Don't leave 'pass' in this program. """ MADE_UP_PRETTY_MAIN_NAME: str = "PyTrekView" def __init__(self): LocateResources.setupSystemLogging() super().__init__() self.logger: Logger = getLogger(PyTrekView.MADE_UP_PRETTY_MAIN_NAME) self.background: Texture = cast(Texture, None) self._enterprise: Enterprise = cast(Enterprise, None) # If you have sprite lists, you should create them here and set them to None # self.physicsEngine: PhysicsEngineSimple = cast(PhysicsEngineSimple, None) self._intelligence: Intelligence = cast(Intelligence, None) self._computer: Computer = cast(Computer, None) self._gameEngine: GameEngine = cast(GameEngine, None) self._gameState: GameState = cast(GameState, None) self._gameSettings: GameSettings = cast(GameSettings, None) self._galaxy: Galaxy = cast(Galaxy, None) self._quadrant: Quadrant = cast(Quadrant, None) self._quadrantMediator: QuadrantMediator = cast(QuadrantMediator, None) self._galaxyMediator: GalaxyMediator = cast(GalaxyMediator, None) self._enterpriseMediator: EnterpriseMediator = cast(EnterpriseMediator, None) self._statusConsole: StatusConsole = cast(StatusConsole, None) self._messageConsole: MessageConsole = cast(MessageConsole, None) self._eventEngine: EventEngine = cast(EventEngine, None) # # I am cheating here because I know arcade use PIL under the covers # fqFileName: str = LocateResources.getResourcesPath(resourcePackageName=LocateResources.FONT_RESOURCES_PACKAGE_NAME, bareFileName=FIXED_WIDTH_FONT_FILENAME) ImageFont.truetype(fqFileName) def setup(self): SettingsCommon.determineSettingsLocation() # self._backgroundSprite: QuadrantBackground = QuadrantBackground() fqFileName: str = LocateResources.getResourcesPath(resourcePackageName=LocateResources.IMAGE_RESOURCES_PACKAGE_NAME, bareFileName='QuadrantBackground.png') self.background = load_texture(fqFileName) # Create the 'physics engine' # self.physicsEngine = PhysicsEngineSimple(self._enterprise, self._hardSpriteList) # These singletons are initialized for the first time self._gameSettings = GameSettings() # Be able to read the preferences file self._gameState = GameState() # Set up the game parameters which uses the above self._gameEngine = GameEngine() # Then the engine needs to be initialized self._intelligence = Intelligence() self._computer = Computer() self._galaxy = Galaxy() # This essentially finishes initializing most of the game self._messageConsole: MessageConsole = MessageConsole() self._eventEngine: EventEngine = EventEngine(self._messageConsole) self._statusConsole: StatusConsole = StatusConsole(gameView=self) # UI elements self._soundMachine: SoundMachine = SoundMachine() self._enterprise: Enterprise = self._gameState.enterprise # Important mediators self._enterpriseMediator: EnterpriseMediator = EnterpriseMediator(view=self, warpTravelCallback=self._enterpriseHasWarped) self._quadrantMediator: QuadrantMediator = QuadrantMediator() self._galaxyMediator: GalaxyMediator = GalaxyMediator() self._quadrant: Quadrant = self._galaxy.currentQuadrant self._gameState.currentQuadrantCoordinates = self._galaxy.currentQuadrant.coordinates # And finally the rest of the UI elements self._quadrantMediator.enterQuadrant(quadrant=self._quadrant, enterprise=self._enterprise) self.logger.info(f'{self._enterprise=}') self.logger.info(f'{self._quadrant=}') self.logger.info(f'Setup Complete') def on_draw(self): """ Render the screen. """ # This command should happen before we start drawing. It will clear # the screen to the background color, and erase what we drew last frame. start_render() # Draw the background texture draw_lrwh_rectangle_textured(bottom_left_x=1, bottom_left_y=CONSOLE_HEIGHT, width=SCREEN_WIDTH, height=QUADRANT_GRID_HEIGHT, texture=self.background) # Call draw() on all our sprite lists self._quadrantMediator.draw(quadrant=self._quadrant) self._statusConsole.draw() self._messageConsole.draw() def on_update(self, delta_time: float): """ All the logic to move, and the game logic goes here. Normally, you'll call update() on the sprite lists that need it. Args: delta_time: Time interval since the last time the function was called. """ # self.physicsEngine.update() self._quadrantMediator.update(quadrant=self._quadrant) self._enterpriseMediator.update(quadrant=self._quadrant) self._gameEngine.updateRealTimeClock(deltaTime=delta_time) def on_key_press(self, pressedKey: int, key_modifiers: int): """ Called whenever a key on the keyboard is pressed. For a full list of keys, see: https://arcade.academy/arcade.key.html """ if pressedKey == arcadeKey.Q: import os # noinspection PyUnresolvedReferences # noinspection PyProtectedMember os._exit(0) elif pressedKey == arcadeKey.G: galaxyView: GalaxyView = GalaxyView(viewCompleteCallback=self._switchViewBack) self.window.show_view(galaxyView) self._gameEngine.resetOperationTime() elif pressedKey == arcadeKey.L: longRangeSensorView: LongRangeSensorScanView = LongRangeSensorScanView(viewCompleteCallback=self._switchViewBack) self.window.show_view(longRangeSensorView) self._gameEngine.resetOperationTime() elif pressedKey == arcadeKey.T: self._quadrantMediator.fireEnterpriseTorpedoes(self._quadrant) self._gameEngine.resetOperationTime() elif pressedKey == arcadeKey.P: self._quadrantMediator.firePhasers(self._quadrant) self._gameEngine.resetOperationTime() elif pressedKey == arcadeKey.D: self._quadrantMediator.dock(self._quadrant) self._gameEngine.resetOperationTime() elif pressedKey == arcadeKey.W: self._enterpriseMediator.warp() elif pressedKey == arcadeKey.H or pressedKey == arcadeKey.QUESTION: print('Asked for help!') self._displayHelp() def on_mouse_motion(self, x: float, y: float, delta_x: float, delta_y: float): """ Called whenever the mouse moves. """ pass # print(f'Mouse ({x},{y})') def on_mouse_press(self, x: float, y: float, button: int, key_modifiers: int): """ Called when the user presses a mouse button. """ if button == MOUSE_BUTTON_LEFT: arcadePoint: ArcadePoint = ArcadePoint(x=x, y=y) if x < QUADRANT_GRID_WIDTH and y >= CONSOLE_HEIGHT: self._enterpriseMediator.impulse(quadrant=self._quadrant, arcadePoint=arcadePoint) def on_mouse_release(self, x, y, button, key_modifiers): """ Called when a user releases a mouse button. """ pass def _enterpriseHasWarped(self, warpSpeed: float, destinationCoordinates: Coordinates): currentCoordinates: Coordinates = self._quadrant.coordinates self._galaxyMediator.doWarp(currentCoordinates=currentCoordinates, destinationCoordinates=destinationCoordinates, warpSpeed=warpSpeed) self._quadrant = self._galaxy.getQuadrant(quadrantCoordinates=destinationCoordinates) self._quadrantMediator.enterQuadrant(quadrant=self._quadrant, enterprise=self._enterprise) self._messageConsole.displayMessage(f"Warped to: {destinationCoordinates} at warp: {warpSpeed}") def _displayHelp(self): helpView: HelpView = HelpView(completeCallback=self._switchViewBack) self.window.show_view(helpView) def _switchViewBack(self): self.window.show_view(self)