示例#1
0
    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()
示例#2
0
    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()
示例#3
0
    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()
示例#4
0
    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, *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()
示例#7
0
    def __init__(self, messageConsole: AbstractMessageConsole):

        self.logger: Logger = getLogger(__name__)

        self._intelligence: Intelligence = Intelligence()
        self._gameState: GameState = GameState()
        self._galaxy: Galaxy = Galaxy()

        self._messageConsole: AbstractMessageConsole = messageConsole
        self._futureEventHandlers: FutureEventHandlers = FutureEventHandlers(
            self._messageConsole)
示例#8
0
    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()
示例#9
0
    def setUpClass(cls):
        TestBase.setUpLogging()
        TestGalaxy.clsLogger = getLogger(__name__)
        SettingsCommon.determineSettingsLocation()

        TestBase.resetSingletons()

        TestGalaxy.clsGameSettings = GameSettings()
        TestGalaxy.clsGameSettings.debugCollectKlingonQuadrantCoordinates = True

        TestGalaxy.clsGameState = GameState()
        TestGalaxy.clsGalaxy = Galaxy()
    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)
示例#11
0
    def __init__(self, messageConsole: AbstractMessageConsole):

        self.logger: Logger = getLogger(__name__)
        self._gameState: GameState = GameState()
        self._galaxy: Galaxy = Galaxy()
        self._intelligence: Intelligence = Intelligence()
        self._galaxyMediator: GalaxyMediator = GalaxyMediator()
        self._quadrantMediator: QuadrantMediator = QuadrantMediator()

        self._messageConsole: AbstractMessageConsole = messageConsole

        self.logger.debug(f'FutureEventHandlers.__init__ - {self._gameState=}')
示例#12
0
    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()
示例#13
0
    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')
示例#14
0
    def __init__(self, viewCompleteCallback: Callable):

        super().__init__()

        self._viewCompleteCallback: Callable = viewCompleteCallback
        fqFileName: str = LocateResources.getResourcesPath(resourcePackageName=LocateResources.IMAGE_RESOURCES_PACKAGE_NAME,
                                                           bareFileName='GalaxyScanBackground.png')

        self.texture = load_texture(fqFileName)

        # Reset the viewport, necessary if we have a scrolling game, and we need
        # to reset the viewport back to the start, so we can see what we draw.
        # set_viewport(0, QUADRANT_GRID_WIDTH - 1, 0, QUADRANT_GRID_HEIGHT - 1)
        self._gameState: GameState          = GameState()
        self._mediator:  GalaxyViewMediator = GalaxyViewMediator()
示例#15
0
    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')
示例#16
0
    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')
示例#17
0
    def testJsonSerialization(self):

        pass
        gState: GameState = GameState()
        gState.playerType = PlayerType.Emeritus
        gState.gameType = GameType.Medium
        gState.starDate = 40501.0

        gState.remainingGameTime = 42.42424242

        gState.currentQuadrantCoordinates = Coordinates(4, 4)
        gState.currentSectorCoordinates = Coordinates(9, 9)

        jsonGState: str = jsonpickle.encode(gState, indent=4)
        self.assertIsNotNone(jsonGState, "Pickling failed")

        self.logger.info(f'json game stats: {jsonGState}')

        file: TextIO = open(TestGameState.TEST_PICKLE_FILENAME, 'w')
        file.write(jsonGState)
        file.close()

        jsonFile: TextIO = open(TestGameState.TEST_PICKLE_FILENAME, 'r')
        jsonStr: str = jsonFile.read()
        self.assertIsNotNone(jsonStr)
        jsonFile.close()

        thawedGameState: GameState = jsonpickle.decode(jsonStr)
        self.assertIsNotNone(thawedGameState, "Did that thaw?")

        self.assertEqual(gState.playerType, thawedGameState.playerType,
                         "Player type did not thaw")
        self.assertEqual(gState.gameType, thawedGameState.gameType,
                         "Game type did not thaw")
        self.assertEqual(gState.starDate, thawedGameState.starDate,
                         "Star date did not thaw")
        self.assertEqual(gState.remainingGameTime,
                         thawedGameState.remainingGameTime,
                         "Remaining game time did not thaw")

        osRemove(TestGameState.TEST_PICKLE_FILENAME)
示例#18
0
    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')
示例#19
0
    def init(self, *args, **kwargs):
        """

        Args:
            *args:  Arg 0 is the message console
            **kwargs:

        Returns:

        """

        self.logger: Logger = getLogger(__name__)

        self._intelligence: Intelligence = Intelligence()
        self._gameState: GameState = GameState()
        self._gameSettings: GameSettings = GameSettings()
        self._devices: Devices = Devices()

        self._eventMap: EventMap = cast(EventMap, None)
        self._setupEventMap()

        self._messageConsole: MessageConsole = args[0]
        self._eventCreator: EventCreator = EventCreator(self._messageConsole)

        self.logger.debug(
            f"{self._gameState.inTime=} eventMap: {self.__repr__()}")

        # TODO Put in debug option that allows selectively scheduling these
        self._scheduleRecurringEvents(
            eventType=FutureEventType.COMMANDER_ATTACKS_BASE)
        self._scheduleRecurringEvents(eventType=FutureEventType.TRACTOR_BEAM)
        self._scheduleRecurringEvents(eventType=FutureEventType.SUPER_NOVA)

        # I do not know what a Number is tell mypy so
        schedule(function_pointer=self._doEventChecking,
                 interval=EventEngine.EVENT_CHECK_INTERVAL)  # type: ignore
示例#20
0
    def __init__(self, gameView: View):

        self.logger: Logger = getLogger(__name__)

        self._gameView: View = gameView

        self._gameSettings: GameSettings = GameSettings()
        self._gameState: GameState = GameState()
        self._eventEngine: EventEngine = EventEngine(LogMessageConsole())

        self._statusProperties: PropertyNames = PropertyNames([])

        self._statusProperties.append(PropertyName('shipCondition'))
        self._statusProperties.append(PropertyName('starDate'))
        self._statusProperties.append(
            PropertyName('currentQuadrantCoordinates'))
        self._statusProperties.append(PropertyName('currentSectorCoordinates'))
        self._statusProperties.append(PropertyName('energy'))
        self._statusProperties.append(PropertyName('shieldEnergy'))
        self._statusProperties.append(PropertyName('remainingGameTime'))
        self._statusProperties.append(PropertyName('remainingKlingons'))
        self._statusProperties.append(PropertyName('remainingCommanders'))
        self._statusProperties.append(PropertyName('remainingSuperCommanders'))
        self._statusProperties.append(PropertyName('torpedoCount'))