Exemplo n.º 1
0
 public void AddUnit(Unit unit, Point tile)
 {
     if (!Units.ContainsKey(tile))
     {
         Units[tile] = new List<Unit>();
     }
     Units[tile].Add(unit);
 }
Exemplo n.º 2
0
 public Unit GetBestUnitOn(Point tile)
 {
     Unit bestUnit = null;
     if (Units.ContainsKey(tile) && Units[tile].Count > 0)
     {
         foreach (var unit in Units[tile])
         {
             if (bestUnit == null || bestUnit.DefensePoints < unit.DefensePoints)
             {
                 bestUnit = unit;
             }
         }
     }
     return bestUnit;
 }
Exemplo n.º 3
0
 public DwarfFaction(int size, Point spawn)
     : base(size, spawn)
 {
 }
Exemplo n.º 4
0
 public Unit GetFirstUnitOn(Point tile)
 {
     if (Units.ContainsKey(tile) && Units[tile].Count > 0)
     {
         return Units[tile][0];
     }
     return null;
 }
Exemplo n.º 5
0
 public Faction(int size, Point spawn)
 {
     Size = size;
     Spawn = spawn;
     BuildUnits();
 }
Exemplo n.º 6
0
 public int UnitCountOn(Point tile)
 {
     if (Units.ContainsKey(tile))
     {
         return Units[tile].Count;
     }
     return 0;
 }
Exemplo n.º 7
0
 public void MoveUnit(Unit unit, Point origin, Point destination)
 {
     if (RemoveUnit(unit, origin))
     {
         AddUnit(unit, destination);
     }
 }
Exemplo n.º 8
0
 public bool RemoveUnit(Unit unit, Point tile)
 {
     if (Units.ContainsKey(tile) && Units[tile].Contains(unit))
     {
         Units[tile].Remove(unit);
         if (Units[tile].Count == 0)
         {
             Units.Remove(tile);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 9
0
 public OrcFaction(int size, Point spawn)
     : base(size, spawn)
 {
 }
Exemplo n.º 10
0
 public bool HasUnitsOn(Point tile)
 {
     return UnitCountOn(tile) > 0;
 }
Exemplo n.º 11
0
 public UnitsContext(Point coordinates, List<Unit> units, Color color)
 {
     Units = new ObservableCollection<Unit>(units);
     Coordinates = coordinates;
     Color = color;
 }
Exemplo n.º 12
0
 public KnightFaction(int size, Point spawn)
     : base(size, spawn)
 {
 }
Exemplo n.º 13
0
 private void SelectTile(Point tile)
 {
     if (!Game.CurrentPlayer.IsAI() && Game.Map.HasTile(tile))
     {
         // "Select unit" Action
         if (SelectedTile == null && Game.CurrentPlayer.HasUnitsOn(tile))
         {
             SelectedTile = tile;
             SelectedUnit = Game.CurrentPlayer.GetFirstUnitOn(tile);
             RaisePropertyChanged("SelectUnitAction");
         }
         // "Unselect unit" Action
         else if (SelectedTile == tile)
         {
             Unselect();
             RaisePropertyChanged("UnselectUnitAction");
         }
         // "Move unit" Action
         else if (SelectedTile != null && SelectedUnit != null)
         {
             MoveUnitTo(tile);
         }
     }
 }
Exemplo n.º 14
0
 private void OverTile(Point tile)
 {
     if (tile == null || Game.Map.HasTile(tile))
     {
         OveredTile = tile;
     }
 }
Exemplo n.º 15
0
        private void MoveUnitTo(Point destination)
        {
            if (!Game.CurrentPlayer.IsAI() && SelectedTile != null && SelectedUnit != null)
            {
                var destinationController = Game.Map.GetTileController(destination);
                var destinationHasEnemy = destinationController != null && destinationController != Game.CurrentPlayer;
                var moveSucceed = Game.MoveUnit(SelectedUnit, SelectedTile, destination);
                if (moveSucceed)
                {
                    if(destinationHasEnemy)
                    {
                        RaisePropertyChanged("AttackUnitAction");
                    }
                    else
                    {
                        RaisePropertyChanged("MoveUnitAction");
                    }

                    // Unselects Tile and Unit
                    Unselect();

                    // Notifies of the changes
                    RaiseUnitMove();
                }
            }
        }