コード例 #1
0
ファイル: Combat.cs プロジェクト: arturcp/Samjokgo
        public static void HeroesAction(int turn, Attackers attackers, Defenders defenders)
        {
            bool attackerTurn = IsHeroTurn(turn, attackers.CurrentHeroPower);
            bool defenderTurn = IsHeroTurn(turn, defenders.CurrentHeroPower);
            bool hasDiv = false;

            if (attackerTurn || defenderTurn)
            {
                hasDiv = true;
                Combat.Log.Add("<div class='heroesActions'>");
            }

            while (attackerTurn || defenderTurn)
            {
                if (attackerTurn && defenderTurn)
                {
                    int attackerInitiative = Dice.Throw(attackers.CurrentHero.Speed);
                    int defenderInitiative = Dice.Throw(defenders.CurrentHero.Speed);

                    if (attackerInitiative.BiggerThan(defenderInitiative))
                    {
                        HeroCombat(attackers, defenders);
                        if (defenders.CurrentHero.Life > 0 && IsHeroTurn(turn, defenders.CurrentHeroPower))
                            HeroCombat(defenders, attackers);
                    }
                    else
                    {
                        HeroCombat(defenders, attackers);
                        if (attackers.CurrentHero.Life > 0 && IsHeroTurn(turn, attackers.CurrentHeroPower))
                            HeroCombat(attackers, defenders);
                    }

                }
                else
                {
                    if (attackerTurn)
                        HeroCombat(attackers, defenders);
                    else if (defenderTurn)
                        HeroCombat(defenders, attackers);
                }

                if (attackers.Powers.Count > 0 && attackers.CurrentHeroPower.Executed) attackers.Powers.RemoveAt(0);
                if (defenders.Powers.Count > 0 && defenders.CurrentHeroPower.Executed) defenders.Powers.RemoveAt(0);

                Combat.Log.Add("<br />");

                attackerTurn = IsHeroTurn(turn, attackers.CurrentHeroPower);
                defenderTurn = IsHeroTurn(turn, defenders.CurrentHeroPower);
              }

            if (hasDiv)
                Combat.Log.Add("</div>");
        }
コード例 #2
0
ファイル: Generate.cs プロジェクト: arturcp/Samjokgo
        public void HeroesPowers(int turns, Attackers attackers, Defenders defenders)
        {
            attackers.Powers = new List<HeroPower>();
            defenders.Powers = new List<HeroPower>();

            foreach (Hero hero in attackers.Heroes) {
                PreparePowers(hero);
                PowerList(turns, hero.Powers, attackers.Powers);
            }

            foreach (Hero hero in defenders.Heroes) {
                PreparePowers(hero);
                PowerList(turns, hero.Powers, defenders.Powers);
            }

            attackers.Powers = attackers.Powers.OrderBy(x=>x.Turn).ToList();
            defenders.Powers = defenders.Powers.OrderBy(x=>x.Turn).ToList();
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: arturcp/Samjokgo
        public ActionResult Show()
        {
            Combat.Log.Clear();
            Generate generate = new Generate(Request);
            UnitFactory.StartUnitFactory();
            DateTime startTime = DateTime.Now;

            Attackers attackers = new Attackers(generate);
            Defenders defenders = new Defenders(generate);

            int turns = attackers.Units.Count.BiggerThan(defenders.Units.Count)? attackers.Units.Count : defenders.Units.Count;
            int rounds = ReadIntFromRequest("rounds");

            generate.HeroesPowers(turns, attackers, defenders);

            int i = 1;
            while (i <= rounds && defenders.Units.Count + defenders.Heroes.Count > 0 && attackers.Units.Count + attackers.Heroes.Count > 0)
            {
                Combat.Log.Add(string.Format("<h2>Round {0}</h2><p>Atacando: {1} unidades</p><p>Defendendo: {2} unidades</p>", i, attackers.Units.Count, defenders.Units.Count));
                Combat.StartCombat(turns, attackers, defenders);

                #region LOG
                Combat.Log.Add(attackers.PV());
                Combat.Log.Add(defenders.PV());
                generate.RoundReport(i, attackers, defenders);
                #endregion

                #region RESET
                generate.RoundResetUnitLives(attackers.Units);
                generate.RoundResetUnitLives(defenders.Units);
                attackers.ResetHeroes();
                defenders.ResetHeroes();
                #endregion

                turns = attackers.Units.Count.BiggerThan(defenders.Units.Count)? attackers.Units.Count : defenders.Units.Count;
                generate.HeroesPowers(turns, attackers, defenders);
                i++;
            }
            DateTime finishTime = DateTime.Now;
            TimeSpan ts = finishTime.Subtract(startTime);
            ViewData["TimeSpent"] = ts;
            ViewData["Rounds"] = rounds;
            return View();
        }
コード例 #4
0
ファイル: Generate.cs プロジェクト: arturcp/Samjokgo
        public void RoundReport(int turn, Attackers attackers, Defenders defenders)
        {
            Combat.Log.Add("<hr>");
            Combat.Log.Add(string.Format("<a name='turno{0}'>&nbsp;</a><h2>Obituário do round {0}</h2>", turn));
            Combat.Log.Add("<div class='attacker'>Atacantes</div>");
            var attackersDied = (from atk in attackers.cemitery
                                 orderby atk.Type
                                 group atk by atk.Type);

            foreach (var group in attackersDied)
                Combat.Log.Add(string.Format("<b>Tipo {1}:</b> {0}", group.Count<Unit>(), group.Key));

            Combat.Log.Add("<br />");
            Combat.Log.Add("<div class='defender'>Defensores</div>");
            var defendersDied = (from dfr in defenders.cemitery
                                 orderby dfr.Type
                                 group dfr by dfr.Type);

            foreach (var group in defendersDied)
                Combat.Log.Add(string.Format("<b>Tipo {1}:</b> {0}", group.Count<Unit>(), group.Key));

            Combat.Log.Add("<hr>");
        }
コード例 #5
0
ファイル: Combat.cs プロジェクト: arturcp/Samjokgo
        public static void StartCombat(int turns, Attackers attackers, Defenders defenders)
        {
            attackers.ResetCemitery();
            defenders.ResetCemitery();

            if (defenders.Units.Count > 0 && attackers.Units.Count > 0)
            {
                Unit defender = null;
                Unit attacker = null;

                int i = 1;
                while (i < turns && defenders.Units.Count + defenders.Heroes.Count > 0 && attackers.Units.Count + attackers.Heroes.Count > 0)
                {
                    HeroesAction(i, attackers, defenders);

                    if (defenders.Units.Count > 0 && attackers.Units.Count > 0)
                    {
                        attacker = attackers.CurrentUnit;
                        defender = defenders.CurrentUnit;

                        attackers.CurrentUnit.Fight(defender);

                        defenders.Units.RemoveAt(0);
                        attackers.Units.RemoveAt(0);

                        if (defender.Life > 0)
                            defenders.Units.Add(defender);
                        else
                            defenders.BuryUnit(defender);

                        if (attacker.Life > 0)
                            attackers.Units.Add(attacker);
                        else
                            attackers.BuryUnit(attacker);

                        Combat.Log.Add("<br />");
                    }
                    i++;
                }
            }
        }