Exemple #1
0
        public void TestPauseAndResume()
        {
            var obscured = new TestGameState();
            var active   = new TestGameState();

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

                Assert.AreEqual(0, obscured.OnPauseCallCount);
                manager.Push(active);
                Assert.AreEqual(1, obscured.OnPauseCallCount);

                Assert.AreEqual(0, active.OnPauseCallCount);
                manager.Pause();
                Assert.AreEqual(1, active.OnPauseCallCount);

                Assert.AreEqual(0, active.OnResumeCallCount);
                manager.Resume();
                Assert.AreEqual(1, active.OnResumeCallCount);

                Assert.AreEqual(0, obscured.OnResumeCallCount);
                manager.Pop();
                Assert.AreEqual(1, obscured.OnResumeCallCount);
            }
        }
Exemple #2
0
        public void TestUpdateAndDrawListRollbackInPop()
        {
            var obscured = new TestGameState();
            var blocker1 = new TestGameState();
            var popup    = new TestGameState();
            var blocker2 = new TestGameState();

            using (var manager = new GameStateManager()) {
                manager.Push(obscured);
                manager.Push(blocker1);
                manager.Push(popup, GameStateModality.Popup);

                manager.Update(new GameTime());
                Assert.AreEqual(0, obscured.UpdateCallCount);
                Assert.AreEqual(1, blocker1.UpdateCallCount);
                Assert.AreEqual(1, popup.UpdateCallCount);
                Assert.AreEqual(0, blocker2.UpdateCallCount);

                manager.Push(blocker2);
                manager.Update(new GameTime());
                Assert.AreEqual(0, obscured.UpdateCallCount);
                Assert.AreEqual(1, blocker1.UpdateCallCount);
                Assert.AreEqual(1, popup.UpdateCallCount);
                Assert.AreEqual(1, blocker2.UpdateCallCount);

                manager.Pop();
                manager.Update(new GameTime());
                Assert.AreEqual(0, obscured.UpdateCallCount);
                Assert.AreEqual(2, blocker1.UpdateCallCount);
                Assert.AreEqual(2, popup.UpdateCallCount);
                Assert.AreEqual(1, blocker2.UpdateCallCount);
            }
        }
Exemple #3
0
        public void TestDraw()
        {
            var gameState = new TestGameState();

            gameState.Draw(new GameTime());
            Assert.AreEqual(1, gameState.DrawCallCount);
        }
Exemple #4
0
        public void TestUpdate()
        {
            var testGameState = new TestGameState();

            testGameState.Update(new GameTime());
            Assert.AreEqual(1, testGameState.UpdateCallCount);
        }
Exemple #5
0
        public void TestEnabledChangedEvent()
        {
            IUpdateable updateableState = new TestGameState();

            // There's no point in doing any testing here because the events are
            // never triggered, thus no exception on this means the part that
            // needs to be implemented is working right (ie. doing nothing)
            updateableState.EnabledChanged += delegate(object sender, EventArgs arguments) { };
            updateableState.EnabledChanged -= delegate(object sender, EventArgs arguments) { };
        }
Exemple #6
0
        public void TestUpdateForwarding()
        {
            GameStateManager manager   = new GameStateManager(new GameServiceContainer());
            TestGameState    gameState = new TestGameState(manager);

            manager.Switch(gameState);

            manager.Update(new GameTime());
            Assert.AreEqual(1, gameState.UpdateCallCount);
        }
Exemple #7
0
        public void TestDrawPropagation()
        {
            GameStateManager manager   = new GameStateManager(new GameServiceContainer());
            TestGameState    gameState = new TestGameState(manager);

            manager.Switch(gameState);

            manager.Draw(new GameTime());
            Assert.AreEqual(1, gameState.DrawCallCount);
        }
Exemple #8
0
        public void TestLeaveOnDisposal()
        {
            GameStateManager manager = new GameStateManager(new GameServiceContainer());
            TestGameState    test    = new TestGameState(manager);

            manager.Switch(test);

            Assert.AreEqual(0, test.OnLeavingCallCount);
            manager.Dispose();
            Assert.AreEqual(1, test.OnLeavingCallCount);
        }
Exemple #9
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);
        }
Exemple #10
0
        public void TestRedundantPauseIsIgnored()
        {
            var testGameState = new TestGameState();

            Assert.AreEqual(0, testGameState.OnPauseCallCount);
            ((IGameState)testGameState).Pause();
            Assert.AreEqual(1, testGameState.OnPauseCallCount);

            ((IGameState)testGameState).Pause();
            Assert.AreEqual(1, testGameState.OnPauseCallCount);
        }
Exemple #11
0
        public void TestEnterLeave()
        {
            var testGameState = new TestGameState();

            Assert.AreEqual(0, testGameState.OnEnteredCallCount);
            ((IGameState)testGameState).Enter();
            Assert.AreEqual(1, testGameState.OnEnteredCallCount);

            Assert.AreEqual(0, testGameState.OnLeavingCallCount);
            ((IGameState)testGameState).Leave();
            Assert.AreEqual(1, testGameState.OnLeavingCallCount);
        }
Exemple #12
0
        public void TestPauseResume()
        {
            var testGameState = new TestGameState();

            Assert.AreEqual(0, testGameState.OnPauseCallCount);
            ((IGameState)testGameState).Pause();
            Assert.AreEqual(1, testGameState.OnPauseCallCount);

            Assert.AreEqual(0, testGameState.OnResumeCallCount);
            ((IGameState)testGameState).Resume();
            Assert.AreEqual(1, testGameState.OnResumeCallCount);
        }
Exemple #13
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);
            }
        }
Exemple #14
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);
        }
Exemple #15
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);
        }
Exemple #16
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);
        }
Exemple #17
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);
        }
Exemple #18
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);
        }
Exemple #19
0
        public void TestPushUnenterableState()
        {
            GameStateManager manager = new GameStateManager(new GameServiceContainer());
            TestGameState    test    = new TestGameState(manager);

            manager.Push(test);

            Assert.Throws <InvalidOperationException>(
                delegate() { manager.Push(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);
        }
Exemple #20
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);
        }
Exemple #21
0
        public void TestGameControllers()
        {
            // Arrange
            GameController controller = new GameController();

            DateTime currentDate = DateTime.Today;

            TestGame game1 = new TestGame(currentDate, "A game", "start");

            TestGameState gameState1 = new TestGameState("start", 1, 1, DateTime.Today);
            TestGameState gameState2 = new TestGameState("made a move", 2, 1, DateTime.Today);

            // Act
            game1.addState(gameState1);
            game1.addState(gameState2);

            // Assert
        }
Exemple #22
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);
            }
        }
Exemple #23
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);
                }
            }
        }
Exemple #24
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);
            }
        }
Exemple #25
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);
            }
        }
Exemple #26
0
 public void TestConstructor()
 {
     GameStateManager manager   = new GameStateManager(new GameServiceContainer());
     GameState        gameState = new TestGameState(manager);
 }
    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);
    }
    public void TestGameStateManagerReference() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState gameState = new TestGameState(manager);

      Assert.AreSame(manager, gameState.GameStateManager);
    }
    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);
    }
Exemple #30
0
 public void BaseSetup()
 {
     TestGameState.ResetState();
 }
 public void TestUpdateForwarding() {
   GameStateManager manager = new GameStateManager(new GameServiceContainer());
   TestGameState gameState = new TestGameState(manager);
   manager.Switch(gameState);
   
   manager.Update(new GameTime());
   Assert.AreEqual(1, gameState.UpdateCallCount);
 }
    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);
    }
    public void TestDrawPropagation() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState gameState = new TestGameState(manager);
      manager.Switch(gameState);

      manager.Draw(new GameTime());
      Assert.AreEqual(1, gameState.DrawCallCount);
    }
    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);
    }
 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);
 }
    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);
    }
Exemple #37
0
        public void TestUpdateOrderProperty()
        {
            IUpdateable updateableState = new TestGameState();

            Assert.AreEqual(0, updateableState.UpdateOrder);
        }
    public void TestLeaveOnDisposal() {
      GameStateManager manager = new GameStateManager(new GameServiceContainer());
      TestGameState test = new TestGameState(manager);

      manager.Switch(test);

      Assert.AreEqual(0, test.OnLeavingCallCount);
      manager.Dispose();
      Assert.AreEqual(1, test.OnLeavingCallCount);
    }
Exemple #39
0
 public void SetPlayersAndEnemies(TestGameState state, int numberOfPlayers, int numberOfEnemies)
 {
     state.numberOfPlayers = numberOfPlayers;
     state.numberOfEnemies = numberOfEnemies;
 }
    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);
    }
Exemple #41
0
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Environment.Exit(0);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.D1))
            {
                gameState = TestGameState.Drawing;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.D2))
            {
                gameState = TestGameState.SerpTriangle;
            }

            if (gameState == TestGameState.Drawing)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    figure.ClearVectors();
                }

                if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    if ((DateTime.Now - lastTime).TotalSeconds >= 0.02)
                    {
                        pointPos = Mouse.GetState().Position.ToVector2();
                        figure.AddVector(pointPos);
                        lastTime = DateTime.Now;
                    }
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Left))
                {
                    figure.Rotate(-5f * (float)gameTime.ElapsedGameTime.TotalSeconds);
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Right))
                {
                    figure.Rotate(5f * (float)gameTime.ElapsedGameTime.TotalSeconds);
                }
            }

            if (gameState == TestGameState.SerpTriangle)
            {
                if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    if ((DateTime.Now - lastTime).TotalSeconds >= 0.1)
                    {
                        pointPos = Mouse.GetState().Position.ToVector2();
                        serpinskiTriangle.AddPoint(pointPos);
                        lastTime = DateTime.Now;
                    }
                }

                if (Mouse.GetState().RightButton == ButtonState.Pressed)
                {
                    if ((DateTime.Now - lastTime).TotalSeconds >= 0.1)
                    {
                        serpinskiTriangle.IsBaked = true;
                        lastTime = DateTime.Now;
                    }
                }
            }

            base.Update(gameTime);
        }
 public void TestConstructor() {
   GameStateManager manager = new GameStateManager(new GameServiceContainer());
   GameState gameState = new TestGameState(manager);
 }