Exemplo n.º 1
0
        /// <summary>
        /// The fighting process itself. Starts with the hero taking the first hit.
        /// </summary>
        /// <param name="monster">The monster that our player fights against.</param>
        public void Fight(IMonster monster)
        {
            this.Fights++;

            double damageDone = this.Hero.Hit(monster);

            this.Logger.Add($"The {this.Hero.GetType().Name} hits the {monster.GetType().Name} dealing {damageDone} damage to it.");

            if (monster.IsDead())
            {
                this.Hero.GainExperience(monster.Experience());
                this.Logger.Add($"The monster dies. ({monster.Experience()} XP gained.)");
                return;
            }

            double monsterDamageDone = monster.Hit(this.Hero);

            this.Logger.Add($"The {monster.GetType().Name} hits the {this.Hero.GetType().Name} dealing {monsterDamageDone} damage to it.");

            if (this.Hero.IsDead())
            {
                this.Hero.Heal();
                this.HealsUsed++;

                if (this.HealsUsed > 3)
                {
                    this.Logger.Add($"The hero dies on level {this.Hero.Level} after {this.Fights} fights.");
                    return;
                }

                this.Logger.Add($"The hero has taken fatal damage. Luckily he has managed to heal just before he dies.");
            }

            this.Fight(monster);
        }
Exemplo n.º 2
0
        public void SimulateGame()
        {
            IHero    hero    = HeroFactory.CreateHero();
            IMonster monster = MonsterFactory.CreateMonster();

            while (!hero.IsDead && !monster.IsDead)
            {
                var rng = new Random();
                int num = rng.Next(0, 100);

                if (num < 50)
                {
                    var w = hero.ActiveWeapon;
                    monster.SubtractHealth(w.Damage);

                    Console.WriteLine($"'{hero.Name}' je napao/la žrtvu '{monster.Name}' pomoću oružja '{w.Name}'");
                }
                else
                {
                    var attack = monster.AttackTypes[rng.Next(0, monster.AttackTypes.Length)];
                    hero.SubtractHealth(attack.Damage);

                    Console.WriteLine($"'{monster.GetType().Name}' je napao/la '{hero.GetType().Name}' pomoću oružja '{attack.Name}'");
                }
            }

            if (hero.IsDead)
            {
                Console.WriteLine($"'{hero.Name}' je pobedio/la u duelu sa '{monster.Name}'");
            }
            else
            {
                Console.WriteLine($"'{monster.Name}' je pobedio/la u duelu sa '{hero.Name}'");
            }
        }
        private void DrawShadow(Brush color, Point coordinates, int width, int height, IMonster monster)
        {
            switch (monster.GetType().ToString())
            {
            case "ProxyVirtualPatternDemo.Wolf":
                gForm.FillEllipse(color, coordinates.X - (width / 2), coordinates.Y - (height / 2), width, height);
                break;

            case "ProxyVirtualPatternDemo.MagicFrog":
                gForm.FillRectangle(color, coordinates.X - (width / 2), coordinates.Y - (height / 2), width, height);
                break;
            }
        }