/// <summary>
        /// Callback that is fired every time the count of ListBlueUnits or ListRedUnits changes.
        /// If IsBattleGoingOn = true and one of the fields gets empty. The battle is over.
        /// When the battle ends, a message is shown, both fields get cleared and both teams points are restored.
        /// </summary>
        private async void ListUnits_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (!((IEnumerable <UnitViewModel>)sender).Any() && IsBattleGoingOn)
            {
                var winningTeam = ListBlueUnits.Any() ? "Blue" : "Red";
                var message     = new MessageDialog("The " + winningTeam + " won the battle!!!");
                await message.ShowAsync();

                IsBattleGoingOn = false;
                DoClearBattleField();
            }
        }
 /// <summary>
 /// Resets the battle field.
 /// </summary>
 private void DoClearBattleField()
 {
     while (ListRedUnits.Any())
     {
         ListRedUnits.First().Dead();
     }
     while (ListBlueUnits.Any())
     {
         ListBlueUnits.First().Dead();
     }
     FormVisible = false;
     BluePoints  = MAX_TEAM_POINTS;
     RedPoints   = MAX_TEAM_POINTS;
 }
        /// <summary>
        /// When a unit dies, the MainViewModel unsubscribes the unit events, restores unit points to the
        /// total of the team points and remove it from the field of battle.
        /// </summary>
        /// <param name="sender">The dead unit</param>
        /// <param name="Team">The team of the dead unit</param>
        private void Unit_UnitDied(object sender, UnitTeam Team)
        {
            var unit = sender as UnitViewModel;

            unit.UnitAttack -= Unit_UnitAttack;
            unit.UnitDied   -= Unit_UnitDied;
            if (Team == UnitTeam.Red)
            {
                ListRedUnits.Remove(unit);
                ObserverHelper <MainViewModel, int> .NotifyObservers(unit, RedPoints + unit.UsedPoints);
            }
            else
            {
                ListBlueUnits.Remove(unit);
                ObserverHelper <MainViewModel, int> .NotifyObservers(unit, BluePoints + unit.UsedPoints);
            }
        }
 /// <summary>
 /// Starts the battle. Closes the form. disable all buttons.
 /// </summary>
 private async void DoStartBattle()
 {
     if (ListBlueUnits.Any() && ListRedUnits.Any())
     {
         IsBattleGoingOn = true;
         foreach (var one in ListRedUnits)
         {
             one.StartAttack();
         }
         foreach (var one in ListBlueUnits)
         {
             one.StartAttack();
         }
         FormVisible = false;
     }
     else
     {
         var message = new MessageDialog("Each team must have at least one unit");
         await message.ShowAsync();
     }
 }
 private void OnNewBlueCavalryClicked()
 {
     ListBlueUnits.Add(HookCallBacks(UnitViewModel.GetNewCavalry(UnitTeam.Blue, BluePoints)));
 }
 private void OnNewBlueRangedClicked()
 {
     ListBlueUnits.Add(HookCallBacks(UnitViewModel.GetNewRanged(UnitTeam.Blue, BluePoints)));
 }