示例#1
0
        public BattleViewModel(Clickers.Models.Army attackingArmy, Clickers.Models.Army defenseArmy, Castle attackedCastle, Castle attackingCastle)
        {
            this.AttackSoldiers  = new List <Soldier>();
            this.DefenseSoldiers = new List <Soldier>();
            this.AttackDeaths    = new List <Soldier>();
            this.DefenseDeaths   = new List <Soldier>();
            this.AttackedCastle  = attackedCastle;
            this.AttackingCastle = attackingCastle;
            this.rng             = new Random();
            this.View            = new BattleReport();

            if ((attackingArmy.Hero == null || attackingArmy.Hero.Life <= 0) && (defenseArmy.Hero != null || defenseArmy.Hero.Life > 0))
            {
                ArmyCreation(attackingArmy, AttackSoldiers);
                ArmyCreationWithHero(defenseArmy, DefenseSoldiers);
            }
            else if ((defenseArmy.Hero == null || defenseArmy.Hero.Life <= 0) && (attackingArmy.Hero != null || attackingArmy.Hero.Life > 0))
            {
                ArmyCreation(defenseArmy, DefenseSoldiers);
                ArmyCreationWithHero(attackingArmy, AttackSoldiers);
            }
            else
            {
                ArmyCreation(attackingArmy, AttackSoldiers);
                ArmyCreation(defenseArmy, DefenseSoldiers);
            }

            Randomizer(AttackSoldiers);
            Randomizer(DefenseSoldiers);
            Fight();


            if (AttackWin == true)
            {
                view.WinOrLoseLabel.Text  = "VICTOIRE";
                this.AttackedCastle.Life -= 25;
            }
            else
            {
                view.WinOrLoseLabel.Text   = "DÉFAITE..";
                this.AttackingCastle.Life -= 25;
            }
            if (this.AttackedCastle.Life <= 0)
            {
                System.Windows.MessageBoxResult result = System.Windows.MessageBox.Show("Bravo vous avez gagné !");
                if (result == System.Windows.MessageBoxResult.OK)
                {
                    System.Windows.Application.Current.Shutdown();
                }
            }
            else
            {
                view.AllyUnitslose.Text   = "Unités attaquantes perdue : " + AttackDeaths.Count;
                view.AllyUnitsRest.Text   = "Unités attaquantes restantes : " + (GameViewModel.Instance.MainCastle.Army.AllSoldiers.Count - AttackDeaths.Count);
                view.EnnemyUnitslose.Text = "Unités défendantes perdue : " + DefenseDeaths.Count;
                view.EnnemyUnitsRest.Text = "Unités défendantes restantes : " + (GameViewModel.Instance.EnnemyCastle.Army.AllSoldiers.Count - DefenseDeaths.Count);
                Switcher.Switch(view);
                EventGenerator();
            }
        }
示例#2
0
 private void ArmyCreation(Clickers.Models.Army Army, List <Soldier> listToFill)
 {
     foreach (Soldier soldier in Army.AllSoldiers)
     {
         Soldier newSoldier = new Soldier();
         newSoldier.InitializeSoldier(soldier);
         listToFill.Add(newSoldier);
     }
 }
示例#3
0
 public HeroFightViewModel(Clickers.Models.Army attackingArmy, Clickers.Models.Army defendingArmy, Castle attackedCastle)
 {
     this.View           = new HeroDuelFightView();
     this.Actions        = new Dictionary <Hero, string>();
     this.AttackingHero  = attackingArmy.Hero;
     this.DefendingHero  = defendingArmy.Hero;
     this.attackingArmy  = attackingArmy;
     this.defendingArmy  = defendingArmy;
     this.attackedCastle = attackedCastle;
     GenerateUI(AttackingHero, DefendingHero);
     View.TurnTB.DataContext = this;
     Switcher.Switch(this.View);
 }
示例#4
0
        public BattleViewModel(Clickers.Models.Army attackingArmy, Clickers.Models.Army defenseArmy, Castle attackedCastle)
        {
            this.AttackSoldiers  = new List <Soldier>();
            this.DefenseSoldiers = new List <Soldier>();
            this.AttackDeaths    = new List <Soldier>();
            this.DefenseDeaths   = new List <Soldier>();
            this.AttackedCastle  = attackedCastle;
            this.rng             = new Random();
            this.View            = new BattleReport();

            if (attackingArmy.Hero.Life <= 0 && defenseArmy.Hero != null && defenseArmy.Hero.Life > 0)
            {
                ArmyCreation(attackingArmy, AttackSoldiers);
                ArmyCreationWithHero(defenseArmy, DefenseSoldiers);
            }
            else if (defenseArmy.Hero.Life <= 0 && attackingArmy.Hero != null && attackingArmy.Hero.Life > 0)
            {
                ArmyCreation(defenseArmy, DefenseSoldiers);
                ArmyCreationWithHero(attackingArmy, AttackSoldiers);
            }
            else
            {
                ArmyCreation(attackingArmy, AttackSoldiers);
                ArmyCreation(defenseArmy, DefenseSoldiers);
            }

            Randomizer(AttackSoldiers);
            Randomizer(DefenseSoldiers);
            Fight();


            if (AttackWin == true)
            {
                view.WinOrLoseLabel.Content = "VICTOIRE";
            }
            else
            {
                view.WinOrLoseLabel.Content = "DÉFAITE..";
            }

            view.AllyUnitslose.Text   = "Unités attaquantes perdue : " + AttackDeaths.Count;
            view.AllyUnitsRest.Text   = "Unités attaquantes restantes : " + (GameViewModel.Instance.MainCastle.Army.AllSoldiers.Count - AttackDeaths.Count);
            view.EnnemyUnitslose.Text = "Unités défendantes perdue : " + DefenseDeaths.Count;
            view.EnnemyUnitsRest.Text = "Unités défendantes restantes : " + (GameViewModel.Instance.EnnemyCastle.Army.AllSoldiers.Count - DefenseDeaths.Count);
            Switcher.Switch(view);
            EventGenerator();
        }
示例#5
0
 private void ArmyCreationWithHero(Clickers.Models.Army Army, List <Soldier> listToFill)
 {
     foreach (Soldier soldier in Army.AllSoldiers)
     {
         Soldier newSoldier;
         if (Army.Hero != null && soldier.Name == Army.Hero.Type)
         {
             newSoldier = new Soldier();
             newSoldier.InitializeSoldier(soldier);
             newSoldier.AttackValue += 5;
         }
         else
         {
             newSoldier = new Soldier();
             newSoldier.InitializeSoldier(soldier);
         }
         listToFill.Add(newSoldier);
     }
 }
示例#6
0
 public Battle(Army attackingArmy, Army defenseArmy, Castle attackedCastle, Castle attackingCastle)
 {
     this.Controller = new BattleViewModel(attackingArmy, defenseArmy, attackedCastle, attackingCastle);
 }