public Hero sellItems(Hero hero) { Console.WriteLine(); Console.WriteLine("Items you can sell: "); Utils.displayListOfItems(equipmentBusiness.GetAllByOwnerId(hero.Id)); List <Equipment> heroItems = equipmentBusiness.GetAllByOwnerId(hero.Id); Console.WriteLine("Enter number of item to sell, (Q)uit or (G)o back"); string command = Console.ReadLine().ToLower(); if (command == "q") //quit shop menu { return(hero); } else if (command == "g") //back to shop menu buy page { return(showShopItems(hero)); } if (int.TryParse(command, out int result)) //check if input is int and in heroItems size { if (Utils.inArrayRange(heroItems.Count, result - 1)) { string commandForSale = ItemBuyAndSellMenu.DoYouWishToSell(heroItems[result - 1]); //Do you wish to sell menu if (commandForSale == "y") //sell item and delete from DBcontext { Console.Clear(); Console.WriteLine("You sold an item!"); hero.Money += (int)heroItems[result - 1].Price; Console.WriteLine("Current gold: " + hero.Money); heroBusiness.Update(hero); equipmentBusiness.Delete(heroItems[result - 1].Id); Console.WriteLine(); sellItems(hero); //back to selling item menu } } else { Console.Clear(); Console.WriteLine("Invalid command!"); hero = sellItems(hero); } } else { Console.Clear(); Console.WriteLine("Invalid command!"); hero = showShopItems(hero); } return(hero); }
public Hero enemyDied(Enemy enemy, Hero hero) { hero.ExperiencePoints += enemy.XpGain; hero.Money += enemy.MoneyGain; Console.WriteLine($"{enemy.Name.Trim()} has died"); Console.WriteLine($"You get {enemy.XpGain} experience points and {enemy.MoneyGain} gold!"); Console.WriteLine($"Current Health Points: {CurrentHealthPoints}"); checkForLevelUp(); hb.Update(hero); return(hero); }
public Hero useBed(Hero hero) { HeroBusiness hb = new HeroBusiness(); Console.WriteLine("You are in an inn"); Console.WriteLine($"You are currently at {hero.CurrentHealthPoints} out of {hero.HealthPoints}"); Console.WriteLine("Do you wish to sleep and regenerate your Health Points for 5 gold? (Y) or (N)"); String command = Console.ReadLine().ToLower(); if (command == "y" && hero.Money >= 5 && hero.CurrentHealthPoints == hero.HealthPoints) { Console.WriteLine("You don't need to sleep yet!"); } else if (command == "y" && hero.Money >= 5 && hero.CurrentHealthPoints != hero.HealthPoints) { hero.CurrentHealthPoints = hero.HealthPoints; hero.Money -= 5; Console.WriteLine("You now have " + hero.HealthPoints + " health points"); hb.Update(hero); } else if (command == "y" && hero.Money < 5) { Console.WriteLine("You don't have enough money for this action"); } return(hero); }
public static Hero enemyAttack(Hero hero, Enemy enemy, Random rand) { int enemyAttackChance = rand.Next(0, enemy.Accuracy * 2); int heroDodgeChance = rand.Next(0, (int)Math.Round((double)hero.Dexterity / 2)); if (enemyAttackChance > heroDodgeChance) { EquipmentBusiness eq = new EquipmentBusiness(); HeroBusiness hb = new HeroBusiness(); int heroDefencePoints = 0; if (eq.GetEquipedByIdAndType(hero.Id, "Armor") != null) { heroDefencePoints = (int)eq.GetEquipedByIdAndType(hero.Id, "Armor").Points; } if (enemy.Strength * 2 - heroDefencePoints > 0) { hero.CurrentHealthPoints -= enemy.Strength * 2 - heroDefencePoints; Console.WriteLine(enemy.Name.Trim() + " deals " + (enemy.Strength * 2 - heroDefencePoints) + " damage to " + hero.Name.Trim() + "!"); hb.Update(hero); } else { Console.WriteLine(enemy.Name.Trim() + " can't penetrade " + hero.Name.Trim() + "'s armor!"); } } else { Console.WriteLine(enemy.Name.Trim() + " misses!"); } return(hero); }
public static Hero startFight(Hero hero, Enemy enemy) { HeroBusiness hb = new HeroBusiness(); Console.WriteLine("you fight!"); Random rand = new Random(); while (hero.CurrentHealthPoints >= 0 && enemy.CurrentHealthPoints >= 0) { enemy = heroAttack(enemy, hero, rand); if (enemy.CurrentHealthPoints <= 0) { hero = hero.enemyDied(enemy, hero); break; } hero = enemyAttack(hero, enemy, rand); if (hero.CurrentHealthPoints <= 0) { hero = hero.heroDied(hero); break; } hb.Update(hero); } return(hero); }
public Hero payingForUpgrade(int weaponNumber, Hero hero, List <Equipment> weaponsInInventory) { Console.WriteLine("Do you wish to upgrade this weapon for " + weaponsInInventory[weaponNumber].Price + " gold?"); Console.WriteLine("(Y)es or (N)o"); Console.WriteLine("(Q)uit to show"); string command = Console.ReadLine().ToLower(); if (command == "n") { Console.Clear(); hero = showForgeOptions(hero); } else if (command == "y" && (int)hero.Money >= (int)weaponsInInventory[weaponNumber].Price / 2) { Console.Clear(); hero.Money -= (int)weaponsInInventory[weaponNumber].Price / 2; weaponsInInventory[weaponNumber].Points += 1 + (int)Math.Ceiling((double)weaponsInInventory[weaponNumber].Points / 3); weaponsInInventory[weaponNumber].Name = weaponsInInventory[weaponNumber].Name.Trim() + "*"; weaponsInInventory[weaponNumber].Price *= 2; Console.WriteLine("You upgraded your weapon!"); Console.WriteLine("Current money balance: " + hero.Money); Console.WriteLine(); eb.Update(weaponsInInventory[weaponNumber]); hb.Update(hero); hero = showForgeOptions(hero); } else if (command == "y" && hero.Money < weaponsInInventory[weaponNumber].Price / 2) { Console.Clear(); Console.WriteLine("You don't have enough money for this action!"); Console.WriteLine(); hero = showForgeOptions(hero); } else if (command == "q") { return(hero); } return(hero); }