Exemplo n.º 1
0
        public void TestSwitchOnlyChangesActiveState()
        {
            var obscured = new TestGameState();
            var active   = new TestGameState();

            using (var manager = new GameStateManager()) {
                manager.Push(obscured);
                manager.Push(active);

                Assert.AreEqual(0, obscured.OnLeavingCallCount);
                Assert.AreEqual(0, active.OnLeavingCallCount);

                manager.Switch(new TestGameState());

                Assert.AreEqual(0, obscured.OnLeavingCallCount);
                Assert.AreEqual(1, active.OnLeavingCallCount);
            }
        }
Exemplo n.º 2
0
        public void TestPushUnenterableState()
        {
            var test = new TestGameState();

            using (var manager = new GameStateManager()) {
                manager.Push(test);
                Assert.AreSame(test, manager.ActiveState);

                Assert.Throws <InvalidOperationException>(
                    delegate() { manager.Push(new UnenterableGameState()); }
                    );

                Assert.AreSame(test, manager.ActiveState);

                // Make sure the test state is still running. Whether pause was
                // called zero times or more, we only care that it's running after
                // the push has failed
                Assert.AreEqual(test.OnResumeCallCount, test.OnPauseCallCount);
            }
        }
Exemplo n.º 3
0
        public void TestPauseOnPush()
        {
            GameStateManager manager = new GameStateManager(new GameServiceContainer());
            TestGameState    test    = new TestGameState(manager);

            manager.Switch(test);

            Assert.AreEqual(0, test.OnPauseCallCount);
            manager.Push(new TestGameState(manager));
            Assert.AreEqual(1, test.OnPauseCallCount);
        }
Exemplo n.º 4
0
        public void TestSwitchToUnenterableState()
        {
            GameStateManager manager = new GameStateManager(new GameServiceContainer());
            TestGameState    test    = new TestGameState(manager);

            manager.Push(new TestGameState(manager));
            manager.Push(test);

            Assert.Throws <InvalidOperationException>(
                delegate() { manager.Switch(new UnenterableGameState(manager)); }
                );

            // Make sure the test state is still running. Whether pause was
            // called zero times or more, we only care that it's running after
            // the push has failed
            Assert.AreEqual(test.OnResumeCallCount, test.OnPauseCallCount);
            // Make sure the state is entered (meaning entered has been called
            // one more time than leave)
            Assert.AreEqual(test.OnLeavingCallCount + 1, test.OnEnteredCallCount);
        }
Exemplo n.º 5
0
        public void TestActiveState()
        {
            var test = new TestGameState();

            using (var manager = new GameStateManager()) {
                Assert.IsNull(manager.ActiveState);

                manager.Push(test);

                Assert.AreSame(test, manager.ActiveState);
            }
        }
Exemplo n.º 6
0
        public void TestLeaveOnDisposal()
        {
            var test = new TestGameState();

            Assert.AreEqual(0, test.OnLeavingCallCount);

            using (var manager = new GameStateManager()) {
                manager.Push(test);
            }

            Assert.AreEqual(1, test.OnLeavingCallCount);
        }
Exemplo n.º 7
0
        public void TestActiveState()
        {
            GameStateManager manager = new GameStateManager(new GameServiceContainer());

            Assert.IsNull(manager.ActiveState);

            TestGameState test = new TestGameState(manager);

            manager.Push(test);

            Assert.AreSame(test, manager.ActiveState);
        }
Exemplo n.º 8
0
        public void TestReeantrantPush()
        {
            using (var manager = new GameStateManager()) {
                var reentrant = new ReentrantGameState(manager);
                manager.Push(reentrant);

                // The reentrant game state pushes another game state onto the stack in its
                // OnEntered() notification. If this causes the stack to be built in the wrong
                // order, the ReentrantGameState would become the new active game state instead
                // of the sub-game-state it pushed onto the stack.
                Assert.AreNotSame(reentrant, manager.ActiveState);
            }
        }
Exemplo n.º 9
0
        public void TestEnterLeave()
        {
            GameStateManager manager   = new GameStateManager(new GameServiceContainer());
            TestGameState    gameState = new TestGameState(manager);

            Assert.AreEqual(0, gameState.OnEnteredCallCount);
            manager.Push(gameState);
            Assert.AreEqual(1, gameState.OnEnteredCallCount);

            Assert.AreEqual(0, gameState.OnLeavingCallCount);
            manager.Pop();
            Assert.AreEqual(1, gameState.OnLeavingCallCount);
        }
Exemplo n.º 10
0
        public void TestPushModality(GameStateModality modality)
        {
            var alwaysObscured      = new TestGameState();
            var potentiallyObscured = new TestGameState();
            var active = new TestGameState();

            using (var manager = new GameStateManager()) {
                manager.Push(alwaysObscured);
                manager.Push(potentiallyObscured);
                manager.Push(active, modality);

                Assert.AreEqual(0, alwaysObscured.UpdateCallCount);
                Assert.AreEqual(0, alwaysObscured.DrawCallCount);
                Assert.AreEqual(0, potentiallyObscured.UpdateCallCount);
                Assert.AreEqual(0, potentiallyObscured.DrawCallCount);
                Assert.AreEqual(0, active.UpdateCallCount);
                Assert.AreEqual(0, active.DrawCallCount);

                manager.Update(new GameTime());
                manager.Draw(new GameTime());

                Assert.AreEqual(0, alwaysObscured.UpdateCallCount);
                Assert.AreEqual(0, alwaysObscured.DrawCallCount);
                if (modality == GameStateModality.Exclusive)
                {
                    Assert.AreEqual(0, potentiallyObscured.UpdateCallCount);
                    Assert.AreEqual(0, potentiallyObscured.DrawCallCount);
                }
                else
                {
                    Assert.AreEqual(1, potentiallyObscured.UpdateCallCount);
                    Assert.AreEqual(1, potentiallyObscured.DrawCallCount);
                }
                Assert.AreEqual(1, active.UpdateCallCount);
                Assert.AreEqual(1, active.DrawCallCount);
            }
        }
Exemplo n.º 11
0
        public void TestDisposalInSwitch(bool disposalEnabled)
        {
            var test = new TestGameState();

            using (var manager = new GameStateManager()) {
                manager.DisposeDroppedStates = disposalEnabled;
                manager.Push(test);

                Assert.AreEqual(0, test.DisposeCallCount);
                Assert.AreSame(test, manager.Switch(new TestGameState()));
                if (disposalEnabled)
                {
                    Assert.AreEqual(1, test.DisposeCallCount);
                }
                else
                {
                    Assert.AreEqual(0, test.DisposeCallCount);
                }
            }
        }
Exemplo n.º 12
0
        public void TestDisposeActiveStatesOnDisposal(bool disposalEnabled)
        {
            var test = new TestGameState();

            Assert.AreEqual(0, test.DisposeCallCount);
            using (var manager = new GameStateManager()) {
                manager.DisposeDroppedStates = disposalEnabled;
                manager.Push(test);
            }

            // The manager should only dispose the state if disposal was enabled
            if (disposalEnabled)
            {
                Assert.AreEqual(1, test.DisposeCallCount);
            }
            else
            {
                Assert.AreEqual(0, test.DisposeCallCount);
            }
        }
Exemplo n.º 13
0
    public void TestPauseOnPush() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState test = new TestGameState(manager);

      manager.Switch(test);

      Assert.AreEqual(0, test.OnPauseCallCount);
      manager.Push(new TestGameState(manager));
      Assert.AreEqual(1, test.OnPauseCallCount);
    }
Exemplo n.º 14
0
    public void TestSwitchOnlyChangesActiveState() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState test1 = new TestGameState(manager);
      TestGameState test2 = new TestGameState(manager);

      manager.Push(test1);
      manager.Push(test2);

      Assert.AreEqual(0, test1.OnLeavingCallCount);
      Assert.AreEqual(0, test2.OnLeavingCallCount);

      manager.Switch(new TestGameState(manager));

      Assert.AreEqual(0, test1.OnLeavingCallCount);
      Assert.AreEqual(1, test2.OnLeavingCallCount);
    }
Exemplo n.º 15
0
    public void TestPauseResume() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState gameState = new TestGameState(manager);
      manager.Push(gameState);

      Assert.AreEqual(0, gameState.OnPauseCallCount);
      manager.Push(new TestGameState(manager));
      Assert.AreEqual(1, gameState.OnPauseCallCount);

      Assert.AreEqual(0, gameState.OnResumeCallCount);
      manager.Pop();
      Assert.AreEqual(1, gameState.OnResumeCallCount);
    }
Exemplo n.º 16
0
    public void TestSwitchToUnenterableState() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState test = new TestGameState(manager);

      manager.Push(new TestGameState(manager));
      manager.Push(test);

      Assert.Throws<InvalidOperationException>(
        delegate() { manager.Switch(new UnenterableGameState(manager)); }
      );

      // Make sure the test state is still running. Whether pause was
      // called zero times or more, we only care that it's running after
      // the push has failed
      Assert.AreEqual(test.OnResumeCallCount, test.OnPauseCallCount);
      // Make sure the state is entered (meaning entered has been called
      // one more time than leave)
      Assert.AreEqual(test.OnLeavingCallCount + 1, test.OnEnteredCallCount);
    }
Exemplo n.º 17
0
 /// <summary>Called when the game state has been entered</summary>
 protected override void OnEntered()
 {
     GameStateManager.Push(new TestGameState(GameStateManager));
 }
Exemplo n.º 18
0
    public void TestReeantrantPush() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      ReentrantGameState test = new ReentrantGameState(manager);
      
      manager.Push(test);

      // The reentrant game state pushes another game state onto the stack in its
      // OnEntered() notification. If this causes the stack to be built in the wrong
      // order, the ReentrantGameState would become the new active game state instead
      // of the sub-game-state it pushed onto the stack.
      Assert.AreNotSame(test, manager.ActiveState);
    }
Exemplo n.º 19
0
    public void TestActiveState() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());

      Assert.IsNull(manager.ActiveState);
      
      TestGameState test = new TestGameState(manager);
      manager.Push(test);

      Assert.AreSame(test, manager.ActiveState);
    }
Exemplo n.º 20
0
    public void TestPopToUnresumableState() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState test = new TestGameState(manager);

      manager.Push(new UnresumableGameState(manager));
      manager.Push(test);

      Assert.Throws<InvalidOperationException>(
        delegate() { manager.Pop(); }
      );

      Assert.AreEqual(test.OnPauseCallCount, test.OnResumeCallCount);
      Assert.AreEqual(test.OnLeavingCallCount + 1, test.OnEnteredCallCount);
    }
Exemplo n.º 21
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            viewport = GraphicsDevice.Viewport;
            Screen defaultScreen = new Screen(viewport.Width, viewport.Height);
            gui.Screen = defaultScreen;

            gameStateManager = new GameStateManager(new GameServiceContainer());
            gameStateManager.Push(new MainMenu(this, gameStateManager, gui, Input));

            base.Initialize();
        }
Exemplo n.º 22
0
 public void TestEnterLeave() {
   GameStateManager manager = new GameStateManager(new GameServiceContainer());
   TestGameState gameState = new TestGameState(manager);
   
   Assert.AreEqual(0, gameState.OnEnteredCallCount);
   manager.Push(gameState);
   Assert.AreEqual(1, gameState.OnEnteredCallCount);
   
   Assert.AreEqual(0, gameState.OnLeavingCallCount);
   manager.Pop();
   Assert.AreEqual(1, gameState.OnLeavingCallCount);
 }