Esempio n. 1
0
        public void Check_Unit_State_Transitions()
        {
            var world = WorldService.Create(200, 200);

            var spearMan = new Unit
                               {
                                   CurrentUnitState = new Spearman(),
                                   Location = world.GetHex(50, 50)
                               };

            spearMan.ExecuteTurn(new MoveStateContext()
            {
                Source = spearMan,
                Target = world.GetHex(70,70)
            });

            while(spearMan.Location.X != 70 && spearMan.Location.Y != 70)
            {
                var x = spearMan.Location.X;
                var y = spearMan.Location.Y;
                spearMan.ExecuteTurn(new ContinueStateContext());

                Assert.AreNotEqual(x, spearMan.Location.X);
                Assert.AreNotEqual(y, spearMan.Location.Y);
            }

            Assert.AreEqual(70, spearMan.Location.X);
            Assert.AreEqual(70, spearMan.Location.Y);
        }
Esempio n. 2
0
        public virtual void AddUnit(Unit unit)
        {
            if(Units == null)
                Units = new List<Unit>();

            unit.Nation = this;
            Units.Add(unit);
        }
Esempio n. 3
0
        //TODO: inject IPathCalculator
        public static IList<Hex> CalculatePath(Hex start, Hex end, Unit unit)
        {
            // var pathFinder = IoC.Resolve<>()
            var currentHex = start;
            var path = new List<Hex>();
            while(!currentHex.IsAdjacentTo(end))
            {
                // need to inject the pathfinder here, which takes into account what a unit can traverse
                // and relative terrain cost, also avoiding enemy units
                currentHex = currentHex.FindClosestSurroundingHexTo(end);
                path.Add(currentHex);
            }

            return path;
        }
Esempio n. 4
0
 public virtual bool IsTraversable(Unit unit)
 {
     return true;
 }