Beispiel #1
0
        Logic.UnitAction IPlayerAI.SelectAction(Logic.API.Info.UnitInfo unitInfo)
        {
            Array values = Enum.GetValues(typeof(Direction));
            Direction direction = (Direction)values.GetValue(Random.Next(Enum.GetValues(typeof(Direction)).Length));
            UnitAction action = null;
            double choice = Random.NextDouble() * 100;

            if (choice < 30) action = new ShootAction() { Direction = direction };
            else if (choice < 60) action = new ScanAction() { Direction = direction };
            else action = new MoveAction() { Direction = direction };

            return action;
        }
Beispiel #2
0
        public void Move(Unit unit, MoveAction action)
        {
            int newX = Tools.GetX(unit.X, action.Direction);
            int newY = Tools.GetY(unit.Y, action.Direction);

            // is space off map
            if (newX < 0 || newX >= Data.Map.MapWidth) return; //fail
            if (newY < 0 || newY >= Data.Map.MapLength) return; //fail

            // Is space collision free
            Tile tile = Data.Map.Tiles[newY][newX];
            if (tile.IsWall) return;  //fail
            if (tile.Unit != null) return;

            MoveUnit(unit, tile);
        }