Beispiel #1
0
        public void EnumerateTurnShouldRunAllActions()
        {
            var game   = new Game();
            var player = new GameActor(GameActor.Alignment.Player);
            var mob    = new GameActor(GameActor.Alignment.Mob);

            var mock1 = new MockAction();
            var mock2 = new MockAction();

            player.AddAction(mock1);
            mob.AddAction(mock2);
            game.AddActor(player);
            game.AddActor(mob);

            var turns = game.EnumerateRound();

            while (turns.MoveNext())
            {
                ;
            }

            Assert.AreEqual(1, mock1.timesCalled);
            Assert.AreEqual(1, mock2.timesCalled);
            Assert.IsTrue(mock1.orderCalledIn < mock2.orderCalledIn);
        }
Beispiel #2
0
        public TestGameWithActors(int seed = 2112)
        {
            game = new Game(seed);

            playerAlice.AddAction(playerMockAction);
            mobCarly.AddAction(mobMockAction);

            game.AddActor(playerAlice);
            game.AddActor(playerBob);
            game.AddActor(mobCarly);
            game.AddActor(mobDenise);
        }
Beispiel #3
0
        private void TestAddActor(GameActor.Alignment align)
        {
            var game   = new Game();
            var actor1 = new GameActor(align, "one");
            var actor2 = new GameActor(align, "two");

            game.AddActor(actor1);
            game.AddActor(actor2);

            var coll = align == GameActor.Alignment.Player ? game.Players : game.Mobs;

            Assert.AreEqual(coll[0], actor1);
            Assert.AreEqual(coll[1], actor2);
        }
Beispiel #4
0
        public void GetTargetsShouldReturnTargetedActors()
        {
            GameActor actor1 = new GameActor();
            GameActor actor2 = new GameActor();
            GameActor actor3 = new GameActor();

            actor1.Targeted = true;
            actor2.Targeted = true;

            var game = new Game();

            game.AddActor(actor1);
            game.AddActor(actor2);
            game.AddActor(actor3);

            var targets = game.GetTargets();

            Assert.AreEqual(2, targets.Count);
            Assert.IsTrue(targets.Contains(actor1));
            Assert.IsTrue(targets.Contains(actor2));
        }
Beispiel #5
0
        public void GetPositionsShouldReturnActorPositions()
        {
            GameActor actor1 = new GameActor();
            GameActor actor2 = new GameActor();

            actor1.pos = new Point <int>(-3, 3);
            actor2.pos = new Point <int>(10, 10);

            var game = new Game();

            game.AddActor(actor1);
            game.AddActor(actor2);

            var field = game.GetPositions();

            Assert.AreEqual(field.size.x, Math.Abs(actor1.pos.x - actor2.pos.x) + 1);
            Assert.AreEqual(field.size.y, Math.Abs(actor1.pos.y - actor2.pos.y) + 1);

            int total = 0;

            field.ForEach((x, y, actor) =>
            {
                if (actor != null)
                {
                    ++total;
                }
                else if (actor == actor1)
                {
                    Assert.AreEqual(x, actor1.pos.x);
                    Assert.AreEqual(y, actor1.pos.x);
                }
                else if (actor == actor2)
                {
                    Assert.AreEqual(x, actor2.pos.x);
                    Assert.AreEqual(y, actor2.pos.x);
                }
            });
            Assert.AreEqual(2, total);
        }
Beispiel #6
0
        static private Game CreateTestGameWithScrypt()
        {
            var testGame  = new Game();
            var testActor = new GameActor();

            testActor.SetScrypt(@"
            function actorActions(game, actor) {
                actor.TakeDamage(5);
            }
            ");

            testGame.AddActor(testActor);
            return(testGame);
        }
Beispiel #7
0
        private void TestAddActorEvent(GameActor.Alignment align)
        {
            var game   = new Game();
            var actor  = new GameActor();
            int called = 0;

            GameEvents.Instance.ActorAdded += (g, a) =>
            {
                ++called;
                Assert.AreEqual(game, g);
                Assert.AreEqual(a, actor);
            };
            game.AddActor(actor);
            Assert.AreEqual(1, called);
        }