Example #1
0
        public void Fight(LifeForm hero1, LifeForm hero2)
        {
            Collection <LifeForm> heros = new Collection <LifeForm>();

            heros.Add(hero1);
            heros.Add(hero2);
            bool hasWinner = false;
            long tick      = 0;

            while (hasWinner == false)
            {
                foreach (var hero in heros)
                {
                    if (hero.nextActionTime <= tick)
                    {
                        //Do attack

                        if (hero1 == hero)
                        {
                            ResolveAttack(hero, hero2);
                        }
                        else
                        {
                            ResolveAttack(hero, hero1);
                        }

                        if (hero1.currentHealth <= 0)
                        {
                            hasWinner = true;
                        }

                        if (hero2.currentHealth <= 0)
                        {
                            hasWinner = true;
                        }


                        hero.nextActionTime = tick + Convert.ToInt64(hero.Speed);
                    }
                }

                tick++;
            }
        }
Example #2
0
        private void ResolveAttack(LifeForm attacker, LifeForm defender)
        {
            float hitChance = attacker.Agility - defender.Agility + 50;

            if (Convert.ToSingle(Dice.Roller.Roll("1d100").Value) < hitChance)
            {
                float damage = 0;

                foreach (var offensiveItem in attacker.EquipedOffensiveItems)
                {
                    damage += Convert.ToSingle(Dice.Roller.Roll(offensiveItem.Damage).Value);
                }

                foreach (var defensiveItem in defender.EquipedDefensiveItems)
                {
                    damage -= Convert.ToSingle(Dice.Roller.Roll(defensiveItem.Protection).Value);
                }
                if (damage > 0)
                {
                    defender.currentHealth -= damage;
                }
            }
        }