/// <summary> /// Resolves one turn of the combat. /// </summary> protected void CombatTurn() { int index; bool flag; // Gets a skill using input manager do { PrintHeroSkills(); flag = int.TryParse(IOManager.AskForInput(), out index); }while (!flag || index < 0 || index >= Hero.Skills.Count); // Gets the damage assigned to the chosen skill Skill skill = SkillService.GetSkillByName(Hero.Skills[index]); int damage = skill.Damage; // Inflicts the damage to the enemy health Enemy.TakeDamage(damage); IOManager.PushOutput($"Enemy took {damage} point(s) of damage!"); // If enemy is still alive counterattacks if (Enemy.IsAlive) { // Chooses a random skill from the set of the enemy index = _random.Next(0, Enemy.Skills.Count); skill = SkillService.GetSkillByName(Enemy.Skills[index]); damage = skill.Damage; // Inflicts the damage to the hero health Hero.TakeDamage(damage); IOManager.PushOutput($"Hero took {damage} point(s) of damage!"); } }
/// <summary> /// Prints the entire Hero skill set. /// </summary> protected void PrintHeroSkills() { for (int i = 0; i < Hero.Skills.Count; i++) { Skill skill = SkillService.GetSkillByName(Hero.Skills[i]); // Skips all null skills if (skill == null) { IOManager.PushOutput($"{i}. UNKNOWN SKILL NAME"); continue; } IOManager.PushOutput($"{i}. {skill.Name}, Damage: {skill.Damage}, {skill.Description}"); } }
/// <summary> /// Initializes the current game specifing the hero's name and the skill file path. /// </summary> /// <param name="heroName">Name of the hero.</param> /// <param name="skillFilePath">Path of the file containing the skills.</param> public GameManager(string heroName, string skillFilePath = "") { // Complete initialization of the managers SkillService.Initialize(skillFilePath); IOManager = new ConsoleManager(this); CombatManager = new CombatManager(IOManager); // Default hero created for the game Hero = new Hero() { Name = heroName, MaxHealth = 15, CurrentHealth = 15, Skills = new List <string>() { "Unarmed attack", "Fireball" } }; }