示例#1
0
文件: UnitView.cs 项目: eske/INSAWars
        public UnitView(Unit unit)
        {
            Unit = unit;
            Attack = unit.AttackTotal;
            Defense = unit.DefenseTotal;
            HitPoints = unit.HitPoints;
            MovementPoints = unit.MovementPoints;
            RemainingHitPoints = unit.RemainingHitPoints;
            RemainingMovementPoints = unit.RemainingMovementPoints;
            Type = unit.ToString();

            unit.PropertyChanged += new PropertyChangedEventHandler(delegate(object sender, PropertyChangedEventArgs args)
            {
                switch (args.PropertyName)
                {
                    case "RemainingMovementPoints":
                        RemainingMovementPoints = ((Unit)sender).RemainingMovementPoints;
                        break;
                    case "RemainingHitPoints":
                        RemainingHitPoints = ((Unit)sender).RemainingHitPoints;
                        break;
                    default:
                        break;
                }
            });
        }
示例#2
0
文件: Case.cs 项目: eske/INSAWars
 /// <summary>
 /// Removes a unit from this case.
 /// </summary>
 /// <param name="unit"></param>
 public virtual void RemoveUnit(Unit unit)
 {
     units.Remove(unit);
     OnPropertyChanged("Units");
 }
示例#3
0
文件: Case.cs 项目: eske/INSAWars
 /// <summary>
 /// Returns true if the case contains the given unit.
 /// </summary>
 /// <param name="unit"></param>
 /// <returns></returns>
 public virtual bool Contains(Unit unit)
 {
     return units.Contains(unit);
 }
示例#4
0
文件: Case.cs 项目: eske/INSAWars
        /// <summary>
        /// Adds a unit on the case.
        /// </summary>
        /// <param name="unit">The new unit to occupy the case.</param>
        public virtual void AddUnit(Unit unit)
        {
            if (HasCity && Occupant != unit.Player)
            {
                // If an enemy city is built on this case, invade it.
                _city.Invade(unit.Player);
            }
            else if (IsUsed && Occupant != unit.Player)
            {
                // If the case is used as a field by an enemy, sack it.
                _city.RemoveField(this);
                Free();
            }

            this.units.Add(unit);
            OnPropertyChanged("Units");
            Occupant = unit.Player;
        }
示例#5
0
文件: Game.cs 项目: eske/INSAWars
        /// <summary>
        /// Builds a city on the case on which the given teacher stands.
        /// Note: this should not be in this class. Refactoring needed.
        /// </summary>
        /// <param name="name">Name of the city.</param>
        /// <param name="teacher">Teacher building the city.</param>
        public void BuildCity(Unit teacher)
        {
            Player player = teacher.Player;
            Case position = teacher.Location;

            City city = new City(position, player, map.TerritoryAround(position, City.Radius));

            position.BuildCity(city);
            player.AddCity(city);

            // The teacher sacrifices himself to build the city (may he rest in peace).
            teacher.Kill();
        }
示例#6
0
 /// <summary>
 /// The player's unit that must attack.
 /// </summary>
 /// <param name="u"></param>
 public AttackCommand(Unit u)
 {
     _unit = u;
 }
示例#7
0
文件: Player.cs 项目: eske/INSAWars
 /// <summary>
 /// Removes a unit.
 /// </summary>
 /// <param name="unit"></param>
 public void RemoveUnit(Unit unit)
 {
     units.Remove(unit);
     OnPropertyChanged("Units");
     if (LoseCondition())
     {
         Lose();
     }
 }
示例#8
0
文件: Player.cs 项目: eske/INSAWars
 /// <summary>
 /// Adds a unit.
 /// </summary>
 /// <param name="unit"></param>
 public void AddUnit(Unit unit)
 {
     units.Add(unit);
     OnPropertyChanged("Units");
 }
示例#9
0
 /// <summary>
 /// Note: ideally, this class should not be coupled to Game. Refactoring needed.
 /// </summary>
 /// <param name="game"></param>
 /// <param name="unit"></param>
 public MoveUnitCommand(Game game, Unit unit)
 {
     _unit = unit;
     _game = game;
 }
示例#10
0
文件: Unit.cs 项目: eske/INSAWars
        /// <summary>
        /// Starts an attack on another unit.
        /// </summary>
        /// <param name="opponent"></param>
        /// <returns></returns>
        protected bool Attack(Unit opponent)
        {
            if (opponent.DefenseTotal == 0)
            {
                opponent.Kill();
            }

            int hits = Math.Max(RemainingHitPoints, opponent.RemainingHitPoints) + 2;
            int rounds = Game.Game.random.Next(3, hits);

            for (int i = 0; i < rounds; i++)
            {
                double ratio = AttackTotal / opponent.DefenseTotal;
                double proba = 0.5 * ratio;

                if (Game.Game.random.NextDouble() < proba)
                {
                    if (--opponent.RemainingHitPoints == 0)
                    {
                        opponent.Kill();
                        return true;
                    }
                }
                else
                {
                    if (--RemainingHitPoints == 0)
                    {
                        Kill();
                        return false;
                    }
                }
            }
            return false;
        }