コード例 #1
0
ファイル: TestMap.cs プロジェクト: pchaigno/smallworld
        public void TestGetIdleUnit()
        {
            Player player = new Player("test", new VikingFactory());
            IViking vikingA = new Viking(player);
            map.PlaceUnit(vikingA, new Point(0, 0));

            Tuple<IUnit, IPoint> idleUnit = map.GetIdleUnit(player);
            Assert.IsTrue(idleUnit.Item2.Equals(new Point(0, 0)));
            Assert.AreSame(idleUnit.Item1, vikingA);

            IViking vikingB = new Viking(player);
            map.PlaceUnit(vikingB, new Point(1, 1));
            Assert.IsTrue(vikingA.Move(new Forest()));

            idleUnit = map.GetIdleUnit(player);
            Assert.IsTrue(idleUnit.Item2.Equals(new Point(1, 1)));
            Assert.AreSame(idleUnit.Item1, vikingB);
        }
コード例 #2
0
ファイル: TestMap.cs プロジェクト: pchaigno/smallworld
        public void TestUnitPositions()
        {
            // Places a few units for tests:
            Player player1 = new Player("test1", new VikingFactory());
            Player player2 = new Player("test2", new GauloisFactory());
            IViking vikingA = new Viking(player1);
            IViking vikingB = new Viking(player1);
            IGaulois gauloisA = new Gaulois(player2);
            IGaulois gauloisB = new Gaulois(player2);
            map.PlaceUnit(vikingA, new Point(0, 0));
            map.PlaceUnit(vikingB, new Point(0, 0));
            map.PlaceUnit(gauloisA, new Point(14, 14));
            map.PlaceUnit(gauloisB, new Point(14, 14));
            List<IUnit> units = map.GetUnits(new Point(0, 0));
            Assert.AreEqual(2, units.Count);
            units = map.GetUnits(new Point(14, 14));
            Assert.AreEqual(2, units.Count);

            // Tests RemoveUnit:
            Assert.IsTrue(map.RemoveUnit(gauloisB, new Point(14, 14)));
            units = map.GetUnits(new Point(14, 14));
            Assert.AreEqual(1, units.Count);

            // Tests MoveUnit:
            map.MoveUnit(vikingB, new Point(0, 0), new Point(0, 1));
            units = map.GetUnits(new Point(0, 0));
            Assert.AreEqual(1, units.Count);
            units = map.GetUnits(new Point(0, 1));
            Assert.AreEqual(1, units.Count);

            // Tests EnemyPosition:
            Assert.IsFalse(map.IsEnemyPosition(new Point(14, 14), gauloisA));
            Assert.IsTrue(map.IsEnemyPosition(new Point(0, 0), gauloisB));
        }