Beispiel #1
0
        public void TurnBaseProcess_TwoPlayersAllAtOnce_TurnsAppliedAllAtOnce()
        {
            var entities = new EntityList();
            var systems  = new EntitySystemList(entities);

            systems.Add(new DumbPlayerSystem());
            systems.Add(new TurnSelectorUpdateSystem());
            systems.Add(new DumbGameLogicSystem());

            systems.AddExecutionOrder <DumbPlayerSystem, TurnSelectorUpdateSystem>();
            systems.AddExecutionOrder <TurnSelectorUpdateSystem, DumbGameLogicSystem>();

            var player1     = new Entity("player1");
            var player1Turn = player1.AddComponent <PlayerTurnComponent>();

            player1Turn.TurnData = new TurnData(5);
            entities.Add(player1);
            var player2     = new Entity("player2");
            var player2Turn = player2.AddComponent <PlayerTurnComponent>();

            player2Turn.TurnData = new TurnData(7);
            entities.Add(player2);
            var gameRule = new Entity();

            gameRule.AddComponent(new PlayerSwitcherComponent(PlayerSwitcherComponent.PlayerSwitchType.AllAtOnce, player1Turn, player2Turn));
            gameRule.AddComponent(new ApplyTurnComponent());
            var gameState = gameRule.AddComponent <DumbGameState>();

            entities.Add(gameRule);
            entities.CommitChanges();

            // Player 1 make turn, selector put turn to be applied, game logic wait for other players
            systems.NotifyDoAction(TimeSpan.Zero);
            Assert.AreEqual(0, gameState.State.Data);

            // Player 2 make turn, selector put turn to be applied, game logic apply turn
            systems.NotifyDoAction(TimeSpan.Zero);
            Assert.AreEqual(12, gameState.State.Data);

            // Player 1 and 2 enabled to make its turns
            systems.NotifyDoAction(TimeSpan.Zero);

            // Player 1 make turn, selector put turn to be applied, game logic wait for other players
            systems.NotifyDoAction(TimeSpan.Zero);
            Assert.AreEqual(12, gameState.State.Data);

            // Player 2 make turn, selector put turn to be applied, game logic apply turn
            systems.NotifyDoAction(TimeSpan.Zero);
            Assert.AreEqual(24, gameState.State.Data);
        }
Beispiel #2
0
        public void NotifyDoAction_SubsystemDisableEntity_ChangesTakesEffectOnlyAfterCommitChanges()
        {
            var entity        = new Entity();
            var component     = new Component();
            var system        = new EntitySystems();
            var disabler      = new DisablerSystem();
            var entities      = new EntityList();
            var entitySystems = new EntitySystemList(entities);

            entities.Add(entity);
            entitySystems.Add(disabler);
            entitySystems.Add(system);
            entity.AddComponent(component);
            entities.CommitChanges();

            entitySystems.NotifyDoAction(TimeSpan.Zero);
            entities.CommitChanges();
            entitySystems.NotifyDoAction(TimeSpan.Zero);

            Assert.AreEqual(111, system.Counter);
        }
Beispiel #3
0
        public void BeforeFirstCommit_NoEntitiesHandled()
        {
            var entity        = new Entity();
            var component     = new Component();
            var system        = new EntitySystems();
            var entities      = new EntityList();
            var entitySystems = new EntitySystemList(entities);

            entities.Add(entity);
            entitySystems.Add(system);
            entity.AddComponent(component);

            entitySystems.NotifyDoAction(TimeSpan.Zero);

            Assert.AreEqual(0, system.Counter);
        }
Beispiel #4
0
        public void DisableComponent_EntityRemovedFromSystem()
        {
            var entity        = new Entity();
            var component     = new Component();
            var system        = new EntitySystems();
            var entities      = new EntityList();
            var entitySystems = new EntitySystemList(entities);

            entities.Add(entity);
            entitySystems.Add(system);
            entity.AddComponent(component);
            entities.CommitChanges();

            component.Enabled = false;
            entities.CommitChanges();

            entitySystems.NotifyDoAction(TimeSpan.Zero);

            Assert.AreEqual(110, system.Counter);
        }
Beispiel #5
0
        public void EnableEntity_EntityAddedToSystem()
        {
            var entity        = new Entity();
            var component     = new Component();
            var system        = new EntitySystems();
            var entities      = new EntityList();
            var entitySystems = new EntitySystemList(entities);

            entities.Add(entity);
            entitySystems.Add(system);
            entity.AddComponent(component);
            entity.Enabled = false;
            entities.CommitChanges();

            entity.Enabled = true;
            entities.CommitChanges();

            entitySystems.NotifyDoAction(TimeSpan.Zero);

            Assert.AreEqual(11, system.Counter);
        }
Beispiel #6
0
        public void ComponentEnabled_WhenEntityDisabled_NoNotification()
        {
            var entity        = new Entity();
            var component     = new Component();
            var system        = new EntitySystems();
            var entities      = new EntityList();
            var entitySystems = new EntitySystemList(entities);

            entities.Add(entity);
            entitySystems.Add(system);
            entity.AddComponent(component);
            entity.Enabled    = false;
            component.Enabled = false;
            entities.CommitChanges();

            component.Enabled = true;
            entities.CommitChanges();

            entitySystems.NotifyDoAction(TimeSpan.Zero);

            Assert.AreEqual(0, system.Counter);
        }