Ejemplo n.º 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()
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()
Ejemplo n.º 5
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
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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()
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
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()
Ejemplo n.º 11
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')
Ejemplo n.º 12
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')
Ejemplo n.º 13
0
    def init(self):

        self.logger:  Logger       = getLogger(__name__)
        gameSettings: GameSettings = GameSettings()
        intelligence: Intelligence = Intelligence()
        playerType:   PlayerType   = gameSettings.playerType
        gameType:     GameType     = gameSettings.gameType

        self._playerType: PlayerType  = playerType
        self._gameType:     GameType  = gameType
        self._energy:       float     = gameSettings.initialEnergyLevel
        self._shieldEnergy: float     = gameSettings.initialShieldEnergy
        self._torpedoCount: int       = gameSettings.initialTorpedoCount
        self._starDate:     float     = intelligence.generateInitialStarDate()
        self._inTime:       float     = intelligence.generateInitialGameTime()
        self._opTime:       float     = 0.0

        self._remainingGameTime:   float = intelligence.generateInitialGameTime()
        self._remainingKlingons:   int   = intelligence.generateInitialKlingonCount(gameType=gameType, playerType=playerType)
        self._remainingCommanders: int   = intelligence.generateInitialCommanderCount(playerType=playerType, generatedKlingons=self._remainingKlingons)

        self._starBaseCount: int = intelligence.generateInitialStarBaseCount()
        self._planetCount:   int = intelligence.generateInitialPlanetCount()

        # Adjust total Klingon counts by # of commanders
        self._remainingKlingons = self._remainingKlingons - self._remainingCommanders

        # Novice and Fair players do not get Super Commanders
        if playerType != PlayerType.Novice and playerType != PlayerType.Fair:
            self._remainingSuperCommanders = intelligence.generateInitialSuperCommanderCount(playerType=playerType, numberOfKlingons=self._remainingKlingons)
            # Adjust total Klingons by # of super commanders
            self._remainingKlingons = self._remainingKlingons - self._remainingSuperCommanders
        else:
            self._remainingSuperCommanders = 0

        self._shipCondition:             ShipCondition  = ShipCondition.Green
        self.currentQuadrantCoordinates: Coordinates    = cast(Coordinates, None)
        self.currentSectorCoordinates:   Coordinates    = cast(Coordinates, None)

        self._enterprise: Enterprise = Enterprise()

        self.gameActive:    bool = True

        self.logger.info(f'Game State singleton initialized')
Ejemplo n.º 14
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')
Ejemplo n.º 15
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')
Ejemplo n.º 16
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
Ejemplo n.º 17
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'))
Ejemplo n.º 18
0
 def init(self):
     """
     """
     self.logger: Logger = getLogger(__name__)
     self._gameSettings: GameSettings = GameSettings()
     self._devices: Devices = Devices()
Ejemplo n.º 19
0
    def init(self, *args, **kwds):

        self.logger: Logger = getLogger(__name__)

        self._gameSettings: GameSettings = GameSettings()

        self._unableToComply: Sound = self.loadSound(
            bareFileName=SoundType.UnableToComply.value)
        self._docked: Sound = self.loadSound(
            bareFileName=SoundType.Docked.value)
        self._phaserFired: Sound = self.loadSound(
            bareFileName=SoundType.PhaserFired.value)
        self._pleaseRepeatRequest: Sound = self.loadSound(
            bareFileName=SoundType.PleaseRepeatRequest.value)
        self._impulse: Sound = self.loadSound(
            bareFileName=SoundType.Impulse.value)
        self._enterpriseBlocked: Sound = self.loadSound(
            bareFileName=SoundType.EnterpriseBlocked.value)
        self._photonTorpedoFired: Sound = self.loadSound(
            bareFileName=SoundType.PhotonTorpedoFired.value)
        self._photonTorpedoExploded: Sound = self.loadSound(
            bareFileName=SoundType.PhotonTorpedoExploded.value)
        self._photonTorpedoMisfire: Sound = self.loadSound(
            bareFileName=SoundType.PhotonTorpedoMisfire.value)
        self._photonTorpedoMiss: Sound = self.loadSound(
            bareFileName=SoundType.PhotonTorpedoMiss.value)
        self._inaccurate: Sound = self.loadSound(
            bareFileName=SoundType.Inaccurate.value)
        self._klingonMove: Sound = self.loadSound(
            bareFileName=SoundType.KlingonMove.value)
        self._klingonTorpedo: Sound = self.loadSound(
            bareFileName=SoundType.KlingonTorpedo.value)
        self._klingonCannotFire: Sound = self.loadSound(
            bareFileName=SoundType.KlingonCannotFire.value)
        self._commanderMove: Sound = self.loadSound(
            bareFileName=SoundType.CommanderMove.value)
        self._commanderTorpedo: Sound = self.loadSound(
            bareFileName=SoundType.CommanderTorpedo.value)
        self._commanderCannotFire: Sound = self.loadSound(
            bareFileName=SoundType.CommanderCannotFire.value)
        self._superCommanderMove: Sound = self.loadSound(
            bareFileName=SoundType.SuperCommanderMove.value)
        self._superCommanderTorpedo: Sound = self.loadSound(
            bareFileName=SoundType.SuperCommanderTorpedo.value)
        self._superCommanderCannotFire: Sound = self.loadSound(
            bareFileName=SoundType.SuperCommanderCannotFire.value)

        self._warp: Sound = self.loadSound(bareFileName=SoundType.Warp.value)
        self._shieldHit: Sound = self.loadSound(
            bareFileName=SoundType.ShieldHit.value)

        self._sounds: SoundDictionary = SoundDictionary({
            SoundType.UnableToComply:
            self._unableToComply,
            SoundType.Docked:
            self._docked,
            SoundType.PhaserFired:
            self._phaserFired,
            SoundType.PleaseRepeatRequest:
            self._pleaseRepeatRequest,
            SoundType.Impulse:
            self._impulse,
            SoundType.EnterpriseBlocked:
            self._enterpriseBlocked,
            SoundType.PhotonTorpedoFired:
            self._photonTorpedoFired,
            SoundType.PhotonTorpedoExploded:
            self._photonTorpedoExploded,
            SoundType.PhotonTorpedoMisfire:
            self._photonTorpedoMisfire,
            SoundType.PhotonTorpedoMiss:
            self._photonTorpedoMiss,
            SoundType.Inaccurate:
            self._inaccurate,
            SoundType.KlingonMove:
            self._klingonMove,
            SoundType.KlingonTorpedo:
            self._klingonTorpedo,
            SoundType.KlingonCannotFire:
            self._klingonCannotFire,
            SoundType.CommanderMove:
            self._commanderMove,
            SoundType.CommanderTorpedo:
            self._commanderTorpedo,
            SoundType.CommanderCannotFire:
            self._commanderCannotFire,
            SoundType.SuperCommanderMove:
            self._superCommanderMove,
            SoundType.SuperCommanderTorpedo:
            self._superCommanderTorpedo,
            SoundType.SuperCommanderCannotFire:
            self._superCommanderCannotFire,
            SoundType.Warp:
            self._warp,
            SoundType.ShieldHit:
            self._shieldHit
        })