Пример #1
0
        public static void DisplayLives(int numLives)
        {
            ClearLives();

            Debug.Assert(numLives >= 0 && numLives <= 3);
            SpriteBatch pSpriteBatch = SpriteBatchManager.Find(SpriteBatch.Name.Texts);

            Debug.Assert(pSpriteBatch != null);

            LivesManager pMan = PrivGetInstance();

            if (numLives > 0)
            {
                pSpriteBatch.Attach(pMan.pShip1);
            }
            if (numLives > 1)
            {
                pSpriteBatch.Attach(pMan.pShip2);
            }
            if (numLives > 2)
            {
                pSpriteBatch.Attach(pMan.pShip3);
            }

            pMan.numLives = numLives;

            Font pLives = FontManager.Find(Font.Name.Lives);

            pLives.UpdateMessage(numLives.ToString());
        }
Пример #2
0
        // Should be called at some point after enter a new state
        public override void Initialize(GameManager pGameManager)
        {
            //Debug.WriteLine("Initializing the GamePlay State in {0}", pGameManager.gameMode);

            Font pCredits      = FontManager.Find(Font.Name.Credits);
            Font pScoreHeader1 = FontManager.Find(Font.Name.ScoreHeader1);
            Font pScoreHeader2 = FontManager.Find(Font.Name.ScoreHeader2);

            pScoreHeader1.UpdateMessage("*SCORE<1>*");
            pScoreHeader2.UpdateMessage(" SCORE<2> ");
            LivesManager.DisplayLives(3);

            //---------------------------------------------------------------------------------------------------------
            // Create the player ship and missile
            //---------------------------------------------------------------------------------------------------------
            ShipManager.Create();

            pGameManager.SetActivePlayer(PlayerArtifact.Name.PlayerOne);
            pGameManager.pActiveGameModeStrategy.InitializeLevel(pGameManager);
            pGameManager.poPlayer1.RestoreManagerStates(pGameManager.pGame.GetTime());

            //---------------------------------------------------------------------------------------------------------
            // Add Keyboard Input Observers
            //---------------------------------------------------------------------------------------------------------
            InputSubject pInputSubject = InputManager.GetArrowLeftSubject();

            pInputSubject.Attach(new MoveLeftObserver());

            pInputSubject = InputManager.GetArrowRightSubject();
            pInputSubject.Attach(new MoveRightObserver());

            pInputSubject = InputManager.GetSpaceSubject();
            pInputSubject.Attach(new ShootObserver());
        }
Пример #3
0
        private static LivesManager PrivGetInstance()
        {
            if (pInstance == null)
            {
                pInstance = new LivesManager();
            }
            Debug.Assert(pInstance != null);

            return(pInstance);
        }
Пример #4
0
        public override void EndPlayerTurn(GameManager pGameManager)
        {
            //Debug.WriteLine("RESETTING SHIP!");
            ShipManager.ResetShip();

            SoundManager.StopAllSounds();

            Font pScoreHeader1 = FontManager.Find(Font.Name.ScoreHeader1);
            Font pScoreHeader2 = FontManager.Find(Font.Name.ScoreHeader2);

            pGameManager.pActivePlayer.lives--;
            //Debug.WriteLine("Number of lives remaining is {0}", pGameManager.pActivePlayer.lives);

            if (pGameManager.pActivePlayer.name == PlayerArtifact.Name.PlayerOne && pGameManager.poPlayer2.lives > 0)
            {
                pScoreHeader1.UpdateMessage(" SCORE<1> ");
                pScoreHeader2.UpdateMessage("*SCORE<2>*");
                LivesManager.DisplayLives(pGameManager.poPlayer2.lives);

                //Debug.WriteLine("SWAPPING TO PLAYER 2!");

                //Debug.WriteLine("Storing P1 Managers to Manager Mementos");
                pGameManager.poPlayer1.ArchiveManagerStates(pGameManager.pGame.GetTime());

                //Debug.WriteLine("Restoring P2 Managers from Manager Mementos");
                pGameManager.poPlayer2.RestoreManagerStates(pGameManager.pGame.GetTime());

                pGameManager.SetActivePlayer(PlayerArtifact.Name.PlayerTwo);
            }
            else if (pGameManager.pActivePlayer.name == PlayerArtifact.Name.PlayerTwo && pGameManager.poPlayer1.lives > 0)
            {
                pScoreHeader1.UpdateMessage("*SCORE<1>*");
                pScoreHeader2.UpdateMessage(" SCORE<2> ");
                LivesManager.DisplayLives(pGameManager.poPlayer1.lives);

                //Debug.WriteLine("SWAPPING TO PLAYER 1!");

                //Debug.WriteLine("Storing P2 Managers to Manager Mementos");
                pGameManager.poPlayer2.ArchiveManagerStates(pGameManager.pGame.GetTime());

                //Debug.WriteLine("Restoring P1 Managers from Manager Mementos");
                pGameManager.poPlayer1.RestoreManagerStates(pGameManager.pGame.GetTime());

                pGameManager.SetActivePlayer(PlayerArtifact.Name.PlayerOne);
            }
            else
            {
                LivesManager.DisplayLives(pGameManager.poPlayer1.lives);
                Debug.WriteLine("GAME OVER. YOU LOSE!");
                GameManager.CleanUp();
            }
        }
Пример #5
0
 public override void EndPlayerTurn(GameManager pGameManager)
 {
     Debug.Assert(pGameManager.pActivePlayer.name == PlayerArtifact.Name.PlayerOne);
     pGameManager.pActivePlayer.lives--;
     //Debug.WriteLine("Number of lives remaining is {0}", pGameManager.pActivePlayer.lives);
     LivesManager.DisplayLives(pGameManager.poPlayer1.lives);
     if (pGameManager.pActivePlayer.lives > 0)
     {
         //Debug.WriteLine("RESETTING SHIP!");
         ShipManager.ResetShip();
     }
     else
     {
         SoundManager.StopAllSounds();
         //Debug.WriteLine("GAME OVER. YOU LOSE!");
         GameManager.CleanUp();
     }
 }
Пример #6
0
        private static void ClearLives()
        {
            LivesManager pMan = PrivGetInstance();

            if (pMan.numLives > 0)
            {
                SpriteBatchManager.Remove(pMan.pShip1.GetSBNode());
            }
            if (pMan.numLives > 1)
            {
                SpriteBatchManager.Remove(pMan.pShip2.GetSBNode());
            }
            if (pMan.numLives > 2)
            {
                SpriteBatchManager.Remove(pMan.pShip3.GetSBNode());
            }

            pMan.numLives = 0;
        }