/// <summary> /// Creates a new random item and asks the player what they want to do with it. /// </summary> /// <param name="hero">The players hero</param> private static void HandleFoundItem(Hero hero) { Item item = CreateRandomItem(); string typeOfItem = item.GetType().Name; GameWriter.ItemFoundMessage(item.ItemDescription()); switch (GameReader.GetFoundItemAction()) { case 1: try { string typeOfWeapon = new Weapon().GetType().Name; if (typeOfItem.Equals(typeOfWeapon)) { hero.Equip((Weapon)item); } else { hero.Equip((Armor)item); } GameWriter.ItemEquippedMessage(typeOfItem); GameWriter.PressKeyToContinue(); } catch (Exception e) { GameWriter.ItemEquippedErrorMessage(e.Message); GameWriter.PressKeyToContinue(); } break; default: break; } }
/// <summary> /// Creates a Hero of a random type with a random weapon. /// </summary> /// <param name="level">Level of the hero</param> /// <returns>Random Hero</returns> private static Hero CreateRandomOpponent(int level) { var rand = new Random(); int type = rand.Next(1, 5); int damage = rand.Next(1, level); double attackSpeed = rand.NextDouble() * (level - 0.1) + 0.1; Weapon weapon = new() { ItemName = "Weapon", ItemLevel = level, ItemSlot = Slot.SLOT_WEAPON, WeaponAttributes = new WeaponAttributes() { Damage = damage, AttackSpeed = attackSpeed } }; Hero opponent; string name = "Opponent"; switch (type) { default: case 1: opponent = new Mage(name); weapon.WeaponType = WeaponType.WEAPON_WAND; break; case 2: opponent = new Ranger(name); weapon.WeaponType = WeaponType.WEAPON_BOW; break; case 3: opponent = new Rogue(name); weapon.WeaponType = WeaponType.WEAPON_DAGGER; break; case 4: opponent = new Warrior(name); weapon.WeaponType = WeaponType.WEAPON_SWORD; break; } if (level > 1) { opponent.LevelUp(level - 1); } try { opponent.Equip(weapon); } catch (Exception e) { GameWriter.ItemEquippedErrorMessage(e.Message); } opponent.CalculateTotalStats(); return(opponent); }