Пример #1
0
        public void CreateUnit(Tile tile)
        {
            Unit unit = new Unit();
            unit.X = tile.X;
            unit.Y = tile.Y;
            unit.Player = this;

            tile.Unit = unit;
            unit.Tile = tile;
            Units.Add(unit);
        }
Пример #2
0
 public void RemoveUnit(Unit unit)
 {
     unit.Tile.Unit = null;
     unit.Tile = null;
 }
Пример #3
0
        public void Shoot(Unit unit, ShootAction action)
        {
            Shot shot = new Shot();
            shot.Direction = action.Direction;
            shot.X = Tools.GetX(unit.X, action.Direction);
            shot.Y = Tools.GetY(unit.Y, action.Direction);

            Tile tile = Data.Map.Tiles[shot.Y][shot.X];
            if (tile.IsWall) return;

            shot.Tile = tile;
            tile.Shot = shot;
            ShotList.Add(shot);
        }
Пример #4
0
 public UnitFormation(List<Unit> units)
 {
     this.units = units;
        this.leader = units.First();
        this.leader.IfLeader = true;
 }
Пример #5
0
 public void Scan(Unit unit, ScanAction action)
 {
     ScanInfo scanInfo = new ScanInfo();
     if (action.Direction == API.Direction.Down || action.Direction == API.Direction.Up)
     {
         int del;
         if (action.Direction == API.Direction.Down) del = -1;
         else del = 1;
         for (int x=-1;x<1;x++)
         {
             int ax = unit.X + x;
             int ay = unit.Y + del;
             if (ax < 0 || ax >= Data.Map.MapWidth) return;
             if (ay < 0 || ay >= Data.Map.MapLength) return;
             Tile tile = Data.Map.Tiles[ay][ax];
             if (tile != null) scanInfo.Tiles.Add(tile.GetInfo());
         }
     }
     if (action.Direction == API.Direction.Left || action.Direction == API.Direction.Right)
     {
         int del;
         if (action.Direction == API.Direction.Left) del = -1;
         else del = 1;
         for (int y = -1; y < 1; y++)
         {
             int ax = unit.X + del;
             int ay = unit.Y + y;
             if (ax < 0 || ax >= Data.Map.MapWidth) return;
             if (ay < 0 || ay >= Data.Map.MapLength) return;
             Tile tile = Data.Map.Tiles[ay][ax];
             if (tile != null) scanInfo.Tiles.Add(tile.GetInfo());
         }
     }
     unit.Player.AI.ReceiveScanInfo(scanInfo);
 }
Пример #6
0
 public void ProcessUnitAction(Unit unit, UnitAction action)
 {
     if (action is MoveAction) Move(unit, (MoveAction)action);
     else if (action is ScanAction) Scan(unit, (ScanAction)action);
     else if (action is ShootAction) Shoot(unit, (ShootAction)action);
 }
Пример #7
0
        public void MoveUnit(Unit unit, Tile tile)
        {
            unit.Tile.Unit = null;

            unit.X = tile.X;
            unit.Y = tile.Y;

            tile.Unit = unit;
            unit.Tile = tile;
        }
Пример #8
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);
        }
Пример #9
0
 public void KillUnit(Unit unit)
 {
     unit.Tile.Unit = null;
     unit.Tile = null;
     if (unit.Player.Units.Contains(unit)) unit.Player.Units.Remove(unit);
     unit.Player = null;
 }