def draw(self, centerCoordinates: Coordinates): for y in range(GALAXY_ROWS): for x in range(GALAXY_COLUMNS): coordinates: Coordinates = Coordinates(x=x, y=y) quadrant: Quadrant = self._galaxy.getQuadrant( quadrantCoordinates=coordinates) if quadrant.scanned is True: if centerCoordinates == coordinates: contents: str = 'E' arcadePoint: ArcadePoint = Computer.gamePositionToScreenPoint( coordinates) arcadeX: float = arcadePoint.x + 2 arcadeY: float = arcadePoint.y + 2 else: contents = self._computer.createValueString( klingonCount=quadrant.klingonCount, commanderCount=quadrant.commanderCount, hasStarBase=quadrant.hasStarBase) arcadePoint = Computer.gamePositionToScreenPoint( coordinates) arcadeX = arcadePoint.x arcadeY = arcadePoint.y draw_text(contents, arcadeX, arcadeY, color.WHITE, 14)
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 __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 _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 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.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 testComputeCenterPointMid(self): startPoint: ArcadePoint = ArcadePoint(x=0, y=0) endPoint: ArcadePoint = ArcadePoint(x=400, y=400) midPoint: ArcadePoint = Computer.computeCenterPoint(start=startPoint, end=endPoint) self.logger.debug(f'{startPoint=} {endPoint=} {midPoint=}') expectedPoint: ArcadePoint = ArcadePoint(x=200, y=200) self.assertEqual(expectedPoint, midPoint, 'Mid Center point does not match')
def testComputeCenterPointLong(self): startPoint: ArcadePoint = ArcadePoint(x=10, y=10) endPoint: ArcadePoint = ArcadePoint(x=SCREEN_HEIGHT-10, y=QUADRANT_GRID_WIDTH-10) midPoint: ArcadePoint = Computer.computeCenterPoint(start=startPoint, end=endPoint) self.logger.debug(f'{startPoint=} {endPoint=} {midPoint=}') expectedPoint: ArcadePoint = ArcadePoint(x=415, y=320) self.assertEqual(expectedPoint, midPoint, 'Long Center point does not match')
def init(self, *args, **kwds): self.logger: Logger = getLogger(__name__) self._gameSettings: GameSettings = GameSettings() self._gameState: GameState = GameState() self._intelligence: Intelligence = Intelligence() self._computer: Computer = Computer() self._devices: Devices = Devices() # self._eventEngine: EventEngine = EventEngine() self._accumulatedDelta: float = 0.0 self._gameClock: float = 0.0 self.logger.info(f'GameEngine initialized')
def __init__(self, filename: str, torpedoId: EnemyTorpedoId, speed: float = 3, scale: float = 1.0): GamePiece.__init__(self, filename=filename, speed=speed, scale=scale) SmoothMotion.__init__(self) self._baseEnemyTorpedoLogger: Logger = getLogger(__name__) self._id: EnemyTorpedoId = torpedoId self._firedBy: EnemyId = cast(EnemyId, None) self._firedFromPosition: Coordinates = cast(Coordinates, None) self._followers: SpriteList = cast(SpriteList, None) self._computer: Computer = Computer()
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 init(self, *args, **kwds): """ Accepts the following keyword arguments: * view The arcade view for the long range scan * graphicCenterX The background center X position * graphicCenterY The background center Y position Args: *args: **kwds: """ self.logger: Logger = getLogger(__name__) self._intelligence: Intelligence = Intelligence() self._computer: Computer = Computer() self._galaxy: Galaxy = Galaxy() self.view: View = cast(View, None) self.graphicCenterX: float = 0 self.graphicCenterY: float = 0 self._setKeywordParameters(**kwds)
def init(self, *args, **kwds): self.logger: Logger = getLogger(__name__) self._computer: Computer = Computer() self._galaxy: Galaxy = Galaxy()
class TestShooting(View): """ Main application class. """ MADE_UP_PRETTY_MAIN_NAME: str = "Test Shooter" PALETTE_KLINGON_ID: str = 'paletteKlingon' PALETTE_COMMANDER_ID: str = 'paletteCommander' PALETTE_SUPER_COMMANDER_ID: str = 'paletteSuperCommander' def __init__(self): super().__init__() self.logger: Logger = getLogger(TestShooting.MADE_UP_PRETTY_MAIN_NAME) set_background_color(color.WHITE) self.background: Texture = cast(Texture, None) self._enterprise: Enterprise = cast(Enterprise, None) self._galaxy: Galaxy = cast(Galaxy, None) self._quadrant: Quadrant = cast(Quadrant, None) self._quadrantMediator: QuadrantMediator = cast(QuadrantMediator, None) self._statusConsole: StatusConsole = cast(StatusConsole, None) self._messageConsole: MessageConsole = cast(MessageConsole, None) self._gameState: GameState = cast(GameState, None) self._gameSettings: GameSettings = cast(GameSettings, None) self._gameEngine: GameEngine = cast(GameEngine, None) self._intelligence: Intelligence = cast(Intelligence, None) self._computer: Computer = cast(Computer, None) self._sprites: SpriteList = SpriteList() self._staticSprites: SpriteList = SpriteList() self._selectedGamePiece: GamePiece = cast(GamePiece, None) 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 on_draw(self): """ Render the screen. """ 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) self._quadrantMediator.draw(quadrant=self._quadrant) self._statusConsole.draw() self._messageConsole.draw() self._staticSprites.draw() def on_update(self, delta_time): """ All the logic to move, and the game logic goes here. Normally, you'll call update() on the sprite lists that need it. """ self._quadrantMediator.update(quadrant=self._quadrant) self._enterpriseMediator.update(quadrant=self._quadrant) def on_key_release(self, releasedKey: int, key_modifiers: int): """ Called whenever the user lets off a previously pressed key. """ if releasedKey == arcadeKey.Q: import os # noinspection PyUnresolvedReferences # noinspection PyProtectedMember os._exit(0) elif releasedKey == arcadeKey.A: self.setup() elif releasedKey == arcadeKey.K: self._fireKlingonTorpedo() elif releasedKey == arcadeKey.C: self._fireCommanderTorpedo() elif releasedKey == arcadeKey.S: self._fireSuperCommanderTorpedo() elif releasedKey == arcadeKey.P: self._firePhasers() def on_mouse_release(self, x: float, y: float, button: int, keyModifiers: int): """ Called when the user presses a mouse button. """ self.logger.info(f'{button=} {keyModifiers=}') if button == MOUSE_BUTTON_LEFT and keyModifiers == arcadeKey.MOD_CTRL: # Try klingons first clickedEnemies: List[Sprite] = get_sprites_at_point( point=(x, y), sprite_list=self._quadrantMediator.klingonList) # The Commanders if len(clickedEnemies) == 0: clickedEnemies = get_sprites_at_point( point=(x, y), sprite_list=self._quadrantMediator.commanderList) # Must be Super Commanders if len(clickedEnemies) == 0: clickedEnemies = get_sprites_at_point( point=(x, y), sprite_list=self._quadrantMediator.superCommanderList) for enemy in clickedEnemies: print(f'Delete {enemy}') enemy.remove_from_sprite_lists() elif button == MOUSE_BUTTON_LEFT: if self._selectedGamePiece is None: clickedPaletteSprites: List[Sprite] = get_sprites_at_point( point=(x, y), sprite_list=self._staticSprites) for paletteSprite in clickedPaletteSprites: paletteSprite.color = color.BLACK self._selectedGamePiece = paletteSprite else: # A palette sprite is selected self._placeSpriteOnBoard(x=x, y=y) self.logger.info(f'Clear selected Sprite') self._selectedGamePiece.color = color.WHITE self._selectedGamePiece = cast(GamePiece, None) arcadePoint: ArcadePoint = ArcadePoint(x=x, y=y) self._quadrantMediator.handleMousePress(quadrant=self._quadrant, arcadePoint=arcadePoint, button=button, keyModifiers=keyModifiers) def _placeSpriteOnBoard(self, x: float, y: float): enemy: BaseEnemy = cast(BaseEnemy, self._selectedGamePiece) if enemy.id == TestShooting.PALETTE_KLINGON_ID: klingon: Klingon = self._quadrant.addKlingon() added: bool = self._addEnemyToTestGrid(enemy=klingon, x=x, y=y) if added is True: self._quadrantMediator.klingonList.append(klingon) elif enemy.id == TestShooting.PALETTE_COMMANDER_ID: commander: Commander = self._quadrant.addCommander() added = self._addEnemyToTestGrid(enemy=commander, x=x, y=y) if added is True: self._quadrantMediator.commanderList.append(commander) elif enemy.id == TestShooting.PALETTE_SUPER_COMMANDER_ID: superCommander: SuperCommander = self._quadrant.addSuperCommander() added = self._addEnemyToTestGrid(enemy=superCommander, x=x, y=y) if added is True: self._quadrantMediator.superCommanderList.append( superCommander) def _fireKlingonTorpedo(self): """ We are testing so we'll access protected methods """ # noinspection PyProtectedMember ktm: KlingonTorpedoMediator = self._quadrantMediator._ktm self.__fireEnemyTorpedo( torpedoMediator=ktm, enemySprites=self._quadrantMediator.klingonList, rotationAngle=Klingon.ROTATION_ANGLE) def _fireCommanderTorpedo(self): """ We are testing so we'll access protected methods """ # noinspection PyProtectedMember ctm: CommanderTorpedoMediator = self._quadrantMediator._ctm self.__fireEnemyTorpedo( torpedoMediator=ctm, enemySprites=self._quadrantMediator.commanderList, rotationAngle=Commander.ROTATION_ANGLE) def _fireSuperCommanderTorpedo(self): """ We are testing so we'll access protected methods """ # noinspection PyProtectedMember stm: SuperCommanderTorpedoMediator = self._quadrantMediator._stm self.__fireEnemyTorpedo( torpedoMediator=stm, enemySprites=self._quadrantMediator.superCommanderList, rotationAngle=SuperCommander.ROTATION_ANGLE) def _firePhasers(self): # noinspection PyProtectedMember epm: EnterprisePhaserMediator = self._quadrantMediator._epm epm.firePhasers(quadrant=self._quadrant) # noinspection PyUnusedLocal def _noOp(self, warpSpeed: float, destinationCoordinates: Coordinates): self.logger.warning(f'******** How did we warp? *************') def __fireEnemyTorpedo(self, torpedoMediator: BaseTorpedoMediator, enemySprites: SpriteList, rotationAngle: int = 0): for sprite in enemySprites: enemy: Enemy = cast(Enemy, sprite) # noinspection PyProtectedMember torpedoMediator._pointAtEnterprise(enemy=enemy, enterprise=self._enterprise, rotationAngle=rotationAngle) # noinspection PyProtectedMember torpedoMediator._fireTorpedo(enemy=enemy, enterprise=self._enterprise) def _makeEnemySpriteLists(self): """ Place enemies in the appropriate sprite lists """ self.__makeKlingonSpriteList() self.__makeCommanderSpriteList() self.__makeSuperCommanderSpriteList() def _makeGamePiecePalette(self): """ These are the static icons that can be dragged on screen """ bogusCoordinates: Coordinates = Coordinates(-1, -1) paletteKlingon: Klingon = Klingon(coordinates=bogusCoordinates) paletteKlingon.id = TestShooting.PALETTE_KLINGON_ID paletteKlingon.center_x = 32 paletteKlingon.center_y = 150 paletteCommander: Commander = Commander(coordinates=bogusCoordinates, moveInterval=-1) paletteCommander.id = TestShooting.PALETTE_COMMANDER_ID paletteCommander.center_x = paletteKlingon.center_x + 64 paletteCommander.center_y = 150 paletteSuperCommander: SuperCommander = SuperCommander( coordinates=bogusCoordinates, moveInterval=-1) paletteSuperCommander.id = TestShooting.PALETTE_SUPER_COMMANDER_ID paletteSuperCommander.center_x = paletteCommander.center_x + 64 paletteSuperCommander.center_y = 150 self._staticSprites.append(paletteKlingon) self._staticSprites.append(paletteCommander) self._staticSprites.append(paletteSuperCommander) def _addEnemyToTestGrid( self, enemy: BaseEnemy, x: float, y: float, ) -> bool: added: bool = True gameCoordinates: Coordinates = self._computer.computeCoordinates(x=x, y=y) if gameCoordinates.valid() is True: # Recompute a 'centered' arcade point arcadePoint: ArcadePoint = GamePiece.gamePositionToScreenPosition( gameCoordinates) enemy.gameCoordinates = gameCoordinates enemy.center_x = arcadePoint.x enemy.center_y = arcadePoint.y else: added = False return added def __makeCommanderSpriteList(self): if self._quadrant.commanderCount > 0: self._gameState.shipCondition = ShipCondition.Red commanderSprites: SpriteList = SpriteList() for commander in self._quadrant.commanders: commanderSprites.append(commander) self._quadrantMediator.commanderList = commanderSprites else: self._quadrantMediator.commanderList = SpriteList() def __makeSuperCommanderSpriteList(self): if self._quadrant.superCommanderCount > 0: self._gameState.shipCondition = ShipCondition.Red superCommanderSprites: SpriteList = SpriteList() for superCommander in self._quadrant.superCommanders: superCommanderSprites.append(superCommander) self._quadrantMediator.superCommanderList = superCommanderSprites else: self._quadrantMediator.superCommanderList = SpriteList() def __makeKlingonSpriteList(self): if self._quadrant.klingonCount > 0: self._gameState.shipCondition = ShipCondition.Red klingonSprites: SpriteList = SpriteList() for klingon in self._quadrant.klingons: klingonSprites.append(klingon) self._quadrantMediator.klingonList = klingonSprites else: self._quadrantMediator.klingonList = SpriteList() def __doEnemyDebugActions(self): if self._gameSettings.debugAddKlingons is True: numKlingons: int = self._gameSettings.debugKlingonCount for x in range(numKlingons): self._quadrant.addKlingon() self._gameState.remainingKlingons += numKlingons if self._gameSettings.debugAddCommanders is True: nCommanders: int = self._gameSettings.debugCommanderCount for x in range(nCommanders): self._quadrant.addCommander() self._gameState.remainingCommanders += nCommanders if self._gameSettings.debugAddSuperCommanders: nSuperCommanders: int = self._gameSettings.debugSuperCommanderCount for x in range(nSuperCommanders): self._quadrant.addSuperCommander() self._gameState.remainingSuperCommanders += nSuperCommanders
def __init__(self): self._baseMediatorLogger: Logger = getLogger(__name__) self._computer: Computer = Computer()
def testGalaxyArcadePosition_20_594(self): expectedArcade: ArcadePoint = ArcadePoint(x=20, y=594) actualArcade: ArcadePoint = Computer.gamePositionToScreenPoint(gameCoordinates=Coordinates(x=0, y=3)) self.assertEqual(expectedArcade, actualArcade, 'Computer is broken')
def testGalaxyArcadePosition_276_530(self): expectedArcade: ArcadePoint = ArcadePoint(x=276, y=530) actualArcade: ArcadePoint = Computer.gamePositionToScreenPoint(gameCoordinates=Coordinates(x=4, y=4)) self.assertEqual(expectedArcade, actualArcade, 'Computer is broken')
def setUp(self): self.logger: Logger = TestComputer.clsLogger self.smarty: Computer = Computer()
def testGalaxyArcadePosition_84_786(self): expectedArcade: ArcadePoint = ArcadePoint(x=84, y=786) actualArcade: ArcadePoint = Computer.gamePositionToScreenPoint(gameCoordinates=Coordinates(x=1, y=0)) self.assertEqual(expectedArcade, actualArcade, 'Computer is broken')
def testGalaxyArcadePosition_596_201(self): expectedArcade: ArcadePoint = ArcadePoint(x=596, y=210) actualArcade: ArcadePoint = Computer.gamePositionToScreenPoint(gameCoordinates=Coordinates(x=9, y=9)) self.assertEqual(expectedArcade, actualArcade, 'Computer is broken')