//Crafts a new attack from two items public void Craft(InventorySystem playerInventory, FightSystem fightSystem, int attackToCraft) { //Get the crafting items Item craftingItem1 = Recipes[attackToCraft].craftingItem1; Item craftingItem2 = Recipes[attackToCraft].craftingItem2; //If the player has both the needed items in it's inventory if (playerInventory.Inventory.Contains(craftingItem1) && playerInventory.Inventory.Contains(craftingItem2)) { //Add the attack to the players attacks //Then remove the recipe fightSystem.AddAttack(Recipes[attackToCraft].OutAttack); Console.WriteLine("Attack '" + Recipes[attackToCraft].name + "' crafted!"); Console.WriteLine("Press ENTER to continue"); fightSystem.PlayerXP += Recipes[attackToCraft].CraftXP; Recipes.RemoveAt(attackToCraft); Console.ReadKey(); } //If the player doesn't have the required items else { //Tell the player that it doesn't have the required items, and send it back Console.Clear(); Console.WriteLine("You do not have the required items!"); Console.WriteLine("Press ENTER to continue"); Console.ReadKey(); } }
//Shows the players inventory public void ShowInventory(InventorySystem playerInventory, FightSystem fightSystem) { Console.Clear(); Console.WriteLine("Your Inventory: "); //Go through every element in the inventory for (int i = 0; i < Inventory.Count; i++) { //Write out every item Console.WriteLine((i + 1) + ". " + Inventory[i].ItemName); } Console.WriteLine(""); Console.WriteLine("Press 0 to enter crafting menu"); string input = Console.ReadLine(); //If the player chooses 0 if (input == "0") { //Show the crafting menu PlayerCrafting.ShowCraftingMenu(fightSystem, playerInventory); } else { return; } }
//Drops an item from the players inventory public void DropItem(InventorySystem playerInventory, FightSystem fightSystem) { bool hasDropped = false; while (hasDropped) { ShowInventory(playerInventory, fightSystem); Console.WriteLine("Choose an item to drop or go back using 0"); //Gets the players input and converts it int itemToDrop = Convert.ToInt32(Console.ReadLine()); //If the player chose a wrong number if (itemToDrop > Inventory.Count) { Console.WriteLine("You don't have that many items!"); } //If the player entered a valid number else if (itemToDrop <= Inventory.Count) { //Remove the item Inventory.RemoveAt(itemToDrop - 1); hasDropped = true; } } Console.Clear(); }
//Shows the crafting menu public void ShowCraftingMenu(FightSystem fightSystem, InventorySystem playerInventory) { bool inMenu = true; while (inMenu) { //Tell the player it's attack amount Console.Clear(); Console.WriteLine("You have: " + fightSystem.Attacks.Count + " attacks!"); Console.WriteLine("Choose an Attack to craft or choose 0 to exit!"); Console.WriteLine(); //Print out all the recipes and it's needed items for (int i = 0; i < Recipes.Count; i++) { Console.WriteLine((i + 1) + ". " + Recipes[i].name + " - " + "Items needed: " + "1. " + Recipes[i].craftingItem1.ItemName + " and " + "1. " + Recipes[i].craftingItem2.ItemName); } //Get the player input int selection = Convert.ToInt32(Console.ReadLine()); //If the player chooses to exit if (selection == 0) { inMenu = false; return; } //Int and bool to handle the selection int j = 0; bool selected = false; //While the player hasn't selected a recipe to craft while (!selected) { //If the selection - 1 is equal to the always incrementing j, craft that item if ((selection - 1) == j) { Craft(playerInventory, fightSystem, selection - 1); selected = true; } //If j minus 1 is equal to the number of elements in the recipes list if (j - 1 == Recipes.Count) { //Set j to zero j = 0; } else { //Otherwise increment it j++; } } } }
//Generates an enemy Enemy GenerateEnemy(List <Attack> attacks, FightSystem fightSystem, Random random) { List <string> names = new List <string>(); names.Add("Damaged"); names.Add("Ruthless"); names.Add("Deatheater"); names.Add("Killerman"); names.Add("Tester"); //Create the new enemy Enemy newEnemy = new Enemy(); //Set the enemy's health based on the players level newEnemy.Health = random.Next(fightSystem.PlayerLevel * 10, (fightSystem.PlayerLevel * 2) * 10 + 30); newEnemy.MaxEnemyAttacks = random.Next(2, 5 + 1); newEnemy.name = names[random.Next(0, 5)]; //If the enemy has more than three attacks if (newEnemy.MaxEnemyAttacks > 3) { //Generate a random amount of xp between 70 and 110 newEnemy.XP = random.Next(70, 110); } else { //Generate a random amount of xp between 30 and 70 newEnemy.XP = random.Next(30, 70 + 1); } //Add all the attacks to the enemys attack array for (int i = 0; i < newEnemy.MaxEnemyAttacks; i++) { newEnemy.EnemyAttacks.Add(attacks[random.Next(0, attacks.Count)]); //Check if sniper or rocket attack is added if (newEnemy.EnemyAttacks[i].AttackName == "Sniper Shot" || newEnemy.EnemyAttacks[i].AttackName == "Rocket") { //Check if player is below level 15 if (fightSystem.PlayerLevel < 8) { //Remove the attack newEnemy.EnemyAttacks.RemoveAt(i); i--; } } } return(newEnemy); }
//Eats a food item public void Eat(int foodToEat, FightSystem fightSystem) { Console.Clear(); //Adds the values to the player fightSystem.PlayerHealth += Foods[foodToEat].HealingPower; fightSystem.FoodValue += Foods[foodToEat].FoodPower; Console.WriteLine("You ate: " + Foods[foodToEat].FoodName + "!"); Console.WriteLine("Press ENTER to continue"); Console.ReadLine(); //Removes the food from the array Foods.RemoveAt(foodToEat); }
//Generates random buildings when player //decides to go out and venture public void GenerateRandomBuilding(List <Attack> attacks, FightSystem fightSystem) { //Clear the list of enemies in the building at start Enemies.Clear(); Random randomEnemies = new Random(); //Generate a random amount of enemies int enemies = randomEnemies.Next(RandomEnemyCountMin, RandomEnemyCountMax + 1); //Generates the enemies for (int i = 0; i < enemies; i++) { //Called to generate an enemy Enemies.Add(GenerateEnemy(attacks, fightSystem, randomEnemies)); } }
//Sets all of the recipes values public void SetRecipes(FightSystem fightSystem) { //Spear throw PlayerCrafting.SpearThrowRes.name = "Spear throw"; PlayerCrafting.SpearThrowRes.craftingItem1 = WoodenStick; PlayerCrafting.SpearThrowRes.craftingItem2 = IronBar; PlayerCrafting.SpearThrowRes.OutAttack = fightSystem.SpearThrow; PlayerCrafting.SpearThrowRes.CraftXP = 30; //Spear throw //Gunshot PlayerCrafting.GunShotRes.name = "Gunshot"; PlayerCrafting.GunShotRes.craftingItem1 = IronBar; PlayerCrafting.GunShotRes.craftingItem2 = IronBar; PlayerCrafting.GunShotRes.OutAttack = fightSystem.GunShot; PlayerCrafting.GunShotRes.CraftXP = 70; //Gunshot //Shotgun shot PlayerCrafting.ShotgunShotRes.name = "Shotgun shot"; PlayerCrafting.ShotgunShotRes.craftingItem1 = WoodenStick; PlayerCrafting.ShotgunShotRes.craftingItem2 = IronBar; PlayerCrafting.ShotgunShotRes.OutAttack = fightSystem.ShotgunShot; PlayerCrafting.ShotgunShotRes.CraftXP = 100; //Shotgun shot //Sniper shot PlayerCrafting.SniperShotRes.name = "Sniper shot"; PlayerCrafting.SniperShotRes.craftingItem1 = IronBar; PlayerCrafting.SniperShotRes.craftingItem2 = RubberCube; PlayerCrafting.SniperShotRes.OutAttack = fightSystem.SniperShot; PlayerCrafting.SniperShotRes.CraftXP = 150; //Sniper shot //Rocket PlayerCrafting.RocketRes.name = "Rocket"; PlayerCrafting.RocketRes.craftingItem1 = IronBar; PlayerCrafting.RocketRes.craftingItem2 = Pot; PlayerCrafting.RocketRes.OutAttack = fightSystem.Rocket; PlayerCrafting.SniperShotRes.CraftXP = 140; //Rocket //Nailgun shot PlayerCrafting.NailgunShotRes.name = "Nailgun shot"; PlayerCrafting.NailgunShotRes.craftingItem1 = Nail; PlayerCrafting.NailgunShotRes.craftingItem2 = PlasticBar; PlayerCrafting.NailgunShotRes.OutAttack = fightSystem.NailgunShot; PlayerCrafting.SniperShotRes.CraftXP = 50; //Nailgun shot //Add all recipes to the recipes list, do this to be able to show //all recipes in recipe menu, and also to be able to painlessly add //new attacks if needed. PlayerCrafting.Recipes.Add(PlayerCrafting.SpearThrowRes); PlayerCrafting.Recipes.Add(PlayerCrafting.GunShotRes); PlayerCrafting.Recipes.Add(PlayerCrafting.ShotgunShotRes); PlayerCrafting.Recipes.Add(PlayerCrafting.SniperShotRes); PlayerCrafting.Recipes.Add(PlayerCrafting.RocketRes); PlayerCrafting.Recipes.Add(PlayerCrafting.NailgunShotRes); }
//Access the food menu public void AccessFoodMenu(FightSystem fightSystem) { //Tell the player it's health and show the food in the food inventory Console.Clear(); bool inMenu = true; while (inMenu) { Console.Clear(); Console.Write("Health: "); Print.PrintColorText(fightSystem.PlayerHealth.ToString(), ConsoleColor.Green); Console.Write(" " + "Hunger: "); Print.PrintColorText(fightSystem.FoodValue.ToString(), ConsoleColor.DarkYellow); Console.Write("/"); Print.PrintColorText("100" + "\n", ConsoleColor.Green); Console.WriteLine("Choose a food item to eat or choose 0 to quit"); //Show all the food items for (int i = 0; i < Foods.Count; i++) { //Shows the food and it's healing power Console.WriteLine((i + 1) + ". " + Foods[i].FoodName + " - " + "+" + Foods[i].HealingPower + ", +" + Foods[i].FoodPower); } //Get the user input int selection = Convert.ToInt32(Console.ReadLine()); //If the player chooses 0 if (selection == 0) { inMenu = false; return; } //Int and bool to handle the selection int j = 0; bool notSelected = true; //While the player hasn't selected an item while (notSelected) { //If selection - 1 is equal to the always increameanting j eat that item if ((selection - 1) == j) { inMenu = false; Eat(selection - 1, fightSystem); notSelected = false; } //If j is equal to the number of elements in the foods list if (j - 1 == Foods.Count) { //Set j to zero j = 0; } else { //Otherwise increment it j++; } } } }