//This is the function that moves all the items in the array to the allocated text files. static public void MovingArrayToFile() { //This is to save the array of shopKeeper items onto a text file called ShopKeeper.txt //If the shopKeeper text doesnt exist... StreamWriter shopKeeperWriter = new StreamWriter("ShopKeeper.txt");//Create the text file shopKeeper. for (int i = 0; i < shopKeeperInventory.InventoryLength; i++) { //Going through the length of the array of the shopKeeper inventory. if (shopKeeperInventory.inventory[i] != null) { //This checks is the inventory is not equal to nothing. //This is a manual way of placing the values of the items onto the text file. string theItemTypeSK = shopKeeperInventory.inventory[i].GetType().ToString(); //The type of string is defined first. string theNameSK = shopKeeperInventory.inventory[i].Name; //This is the name of the item. ulong theWeightSK = shopKeeperInventory.inventory[i].Weight; //This is the Weight of the item. ulong theCostSK = shopKeeperInventory.inventory[i].Cost; //This is the cost of the item. string a1 = "|"; //This is the attributes of the other variables that are with the class/Item. string a2 = "|"; string a3 = "|"; switch (theItemTypeSK)//Depending on the type within the inventory. { //This is the switch statement for when the item type is changed when its displayed to the text file. case "Project_Assessment.Weapon": //Accessing the weapons class under the project assessment. Weapon redefinedWeaponSK = (Weapon)shopKeeperInventory.inventory[i]; //Defining redefinedWeaponSK is a weapon within the shopKeeperInventory. a1 = redefinedWeaponSK.Range.ToString(); //Adds the range to the text file and uses it as a string. a2 = redefinedWeaponSK.Damage.ToString(); //Adds the damage to the text file and uses it as a string. a3 = redefinedWeaponSK.AttackSpeed.ToString(); //Adds the AttackSpeed to the text file and uses it as a string. break; //Leaves the array. case "Project_Assessment.Armour": //Accessing the Armour class under the project assessment. Armour redefinedArmourSK = (Armour)shopKeeperInventory.inventory[i]; //Defining redefinedArmourSK is a armour within the shopKeeperInventory. a1 = redefinedArmourSK.ArmourType.ToString(); //Adds the ArmourType to the text file and uses it as a string. a2 = redefinedArmourSK.ArmourHealth.ToString(); //Adds the ArmourHealth to the text file and uses it as a string. a3 = redefinedArmourSK.ArmourResistence.ToString(); //Adds the ArmourResistence to the text file and uses it as a string. break; //Leaves the array. case "Project_Assessment.Potion": //Accessing the Potions class under the project assessment. Potion redefinedPotionsSK = (Potion)shopKeeperInventory.inventory[i]; //Defining redefinedPotionsSK is a potion within the shopKeeperInventory. a1 = redefinedPotionsSK.TypeOfPotion.ToString(); //Adds the TypeOfPotion to the text file and uses it as a string. a2 = redefinedPotionsSK.ChangedStatsOfPotion.ToString(); //Adds the ChangeStatsOfPotion to the text file and uses it as a string. a3 = redefinedPotionsSK.PotionDescription.ToString(); //Adds the PotionDescription to the text file and uses it as a string. break; //Leaves the array. default: //If neither of the case statements are true. break; //Leaves the array. } //This displays on the writeLine, the item type, the name, the cost, the weight, and the additional information from the child classes. shopKeeperWriter.WriteLine($"{theItemTypeSK}|{theNameSK}|{theWeightSK}|{theCostSK}|{a1}|{a2}|{a3}"); } } //Closes the writer so that it stops writing. Also flushes it to the text file before it closes the program. shopKeeperWriter.Flush(); shopKeeperWriter.Close(); //This is to save the array of player items onto a text file called player.txt //If the player text doesnt exist... //Create a new file called player.txt StreamWriter playerWriter = new StreamWriter("Player.txt"); for (int j = 0; j < playerInventory.InventoryLength; j++) { //THis is a loop of the players inventory length and the items within that array. if (playerInventory.inventory[j] != null) { //If it isnt equal to null. string theItemTypeP = playerInventory.inventory[j].GetType().ToString(); //The type of string is defined first. string theNameP = playerInventory.inventory[j].Name; //This is the name of the item. ulong theWeightP = playerInventory.inventory[j].Weight; //This is the Weight of the item. ulong theCostP = playerInventory.inventory[j].Cost; //This is the cost of the item. string a1 = "|"; //This is the attributes of the other variables that are with the class/Item. string a2 = "|"; string a3 = "|"; //This is the switch statement for when the item type is changed when its displayed to the text file. switch (theItemTypeP) //Depending on the type within the inventory. { case "Project_Assessment.Weapon": //Accessing the weapons class under the project assessment. Weapon redefinedWeaponP = (Weapon)playerInventory.inventory[j]; //Defining redefinedWeaponP is a weapon within the playerInventory. a1 = redefinedWeaponP.Range.ToString(); //Adds the range to the text file and uses it as a string. a2 = redefinedWeaponP.Damage.ToString(); //Adds the Damage to the text file and uses it as a string. a3 = redefinedWeaponP.AttackSpeed.ToString(); //Adds the AttackSpeed to the text file and uses it as a string. break; //Leaves the array. case "Project_Assessment.Armour": Armour redefinedArmourP = (Armour)playerInventory.inventory[j]; //Defining redefinedArmourP is a weapon within the playerInventory. a1 = redefinedArmourP.ArmourType.ToString(); //Adds the ArmourType to the text file and uses it as a string. a2 = redefinedArmourP.ArmourHealth.ToString(); //Adds the ArmourHealth to the text file and uses it as a string. a3 = redefinedArmourP.ArmourResistence.ToString(); //Adds the ArmourResistence to the text file and uses it as a string. break; //Leaves the array. case "Project_Assessment.Potion": Potion redefinedPotionsP = (Potion)playerInventory.inventory[j]; //Defining redefinedPotionsP is a weapon within the playerInventory. a1 = redefinedPotionsP.TypeOfPotion.ToString(); //Adds the TypeOfPoions to the text file and uses it as a string. a2 = redefinedPotionsP.ChangedStatsOfPotion.ToString(); //Adds the ChangedStatsOfPotion to the text file and uses it as a string. a3 = redefinedPotionsP.PotionDescription.ToString(); //Adds the PotionDescription to the text file and uses it as a string. break; //Leaves the array. default: //If neither of the case statements are true. break; //Leaves the array. } //This displays on the writeLine, the item type, the name, the cost, the weight, and the additional information from the child classes. playerWriter.WriteLine($"{theItemTypeP}|{theNameP}|{theWeightP}|{theCostP}|{a1}|{a2}|{a3}"); } } //Closes the writer so that it stops writing. Also flushes it to the text file before it closes the program. playerWriter.Flush(); playerWriter.Close(); StreamWriter secretShopKeeperWriter = new StreamWriter("SecretShopKeeper.txt");//Create the text file shopKeeper. for (int k = 0; k < shopKeeperSecretInventory.InventoryLength; k++) { //Going through the length of the array of the shopKeeper inventory. if (shopKeeperSecretInventory.inventory[k] != null) { //This checks is the inventory is not equal to nothing. //This is a manual way of placing the values of the items onto the text file. string theItemTypeSSK = shopKeeperSecretInventory.inventory[k].GetType().ToString(); //The type of string is defined first. string theNameSSK = shopKeeperSecretInventory.inventory[k].Name; //This is the name of the item. ulong theWeightSSK = shopKeeperSecretInventory.inventory[k].Weight; //This is the Weight of the item. ulong theCostSSK = shopKeeperSecretInventory.inventory[k].Cost; //This is the cost of the item. string a1 = "|"; //This is the attributes of the other variables that are with the class/Item. string a2 = "|"; string a3 = "|"; switch (theItemTypeSSK)//Depending on the type within the inventory. { //This is the switch statement for when the item type is changed when its displayed to the text file. case "Project_Assessment.Weapon": //Accessing the weapons class under the project assessment. Weapon redefinedWeaponSSK = (Weapon)shopKeeperSecretInventory.inventory[k]; //Defining redefinedWeaponSK is a weapon within the shopKeeperInventory. a1 = redefinedWeaponSSK.Range.ToString(); //Adds the range to the text file and uses it as a string. a2 = redefinedWeaponSSK.Damage.ToString(); //Adds the damage to the text file and uses it as a string. a3 = redefinedWeaponSSK.AttackSpeed.ToString(); //Adds the AttackSpeed to the text file and uses it as a string. break; //Leaves the array. case "Project_Assessment.Armour": //Accessing the Armour class under the project assessment. Armour redefinedArmourSSK = (Armour)shopKeeperSecretInventory.inventory[k]; //Defining redefinedArmourSK is a armour within the shopKeeperInventory. a1 = redefinedArmourSSK.ArmourType.ToString(); //Adds the ArmourType to the text file and uses it as a string. a2 = redefinedArmourSSK.ArmourHealth.ToString(); //Adds the ArmourHealth to the text file and uses it as a string. a3 = redefinedArmourSSK.ArmourResistence.ToString(); //Adds the ArmourResistence to the text file and uses it as a string. break; //Leaves the array. case "Project_Assessment.Potion": //Accessing the Potions class under the project assessment. Potion redefinedPotionsSSK = (Potion)shopKeeperSecretInventory.inventory[k]; //Defining redefinedPotionsSK is a potion within the shopKeeperInventory. a1 = redefinedPotionsSSK.TypeOfPotion.ToString(); //Adds the TypeOfPotion to the text file and uses it as a string. a2 = redefinedPotionsSSK.ChangedStatsOfPotion.ToString(); //Adds the ChangeStatsOfPotion to the text file and uses it as a string. a3 = redefinedPotionsSSK.PotionDescription.ToString(); //Adds the PotionDescription to the text file and uses it as a string. break; //Leaves the array. default: //If neither of the case statements are true. break; //Leaves the array. } //This displays on the writeLine, the item type, the name, the cost, the weight, and the additional information from the child classes. secretShopKeeperWriter.WriteLine($"{theItemTypeSSK}|{theNameSSK}|{theWeightSSK}|{theCostSSK}|{a1}|{a2}|{a3}"); } } //Closes the writer so that it stops writing. Also flushes it to the text file before it closes the program. secretShopKeeperWriter.Flush(); secretShopKeeperWriter.Close(); }
public void SuperUserCreating() { //This is a statement that allows the superusers to be able to add items to the store. Console.Clear(); Console.WriteLine("Name of the Item:"); _playerInteraction = Console.ReadLine(); //The player is said to input new item name. string newName = _playerInteraction; //Stores the new name of the item thats inputted. Console.WriteLine("Weight of the Item [write it in just numbers and no letters and other characters]:"); ulong playerValueW = 0; //The player value is default at 0. TryandCatch(ref playerValueW, playerInteraction); //This is a function in case the player accidentally puts in a value that isnt a number. ulong newWeight = playerValueW; //Stores the new weight of the item thats inputted. Console.WriteLine("Cost of the Item [write it in just numbers and no letters and other characters]: "); ulong playerValueC = 0; //The playerValue is default at 0. TryandCatch(ref playerValueC, playerInteraction); //This is a function in case the player accidentally puts in a value that isnt a number. ulong newCost = playerValueC; //Stores the new cost of the item thats inputted. //This asks for what type of item that the player would like to classify it as. bool playerInteractionIsCorrect = false; while (playerInteractionIsCorrect == false) { Console.WriteLine("What type of Item is it? Is it a Weapon or Armour or Potion? [Write the word of the type of item.]"); _playerInteraction = Console.ReadLine(); //The player is said to input what type of item they are making. playerInteraction = _playerInteraction.ToUpper(); //Stores the weapon class into the playerInteraction string. if (playerInteraction == "WEAPON" || playerInteraction == "ARMOUR" || playerInteraction == "POTION") { playerInteractionIsCorrect = true; } } while (playerInteractionIsCorrect == true) { switch (playerInteraction)//Depending on what the person says. { case "WEAPON": //If the user says they want to make a weapon. //This is divised into - range damage attackspeed looking downwards. Console.WriteLine("Okay, awesome. What is the range in metres? [write it in just NUMBERS and no letters and other characters]"); ulong playerValueR = 0;; //The playerValue of the range is 0; TryandCatch(ref playerValueR, playerInteraction); //This is a function in case the player accidentally puts in a value that isnt a number. ulong newRange = playerValueR; //Stores the new range of the weapon thats inputted. Console.WriteLine("What is the damage of the Weapon? [write it in just NUMBERS and no letters and other characters]"); ulong playerValueD = 0; //Converts the interaction to an integer. TryandCatch(ref playerValueD, playerInteraction); //This is a function in case the player accidentally puts in a value that isnt a number. ulong newDamage = playerValueD; //Stores the new damage of the weapon thats inputted. Console.WriteLine("What is the Attack Speed of the Weapon? [write it in just NUMBERS and no letters and other characters]"); ulong playerValueAS = 0; //Converts the interaction to an integer. TryandCatch(ref playerValueAS, playerInteraction); //This is a function in case the player accidentally puts in a value that isnt a number. ulong newAttackSpeed = playerValueAS; //Stores the new attack speed of the weapon thats inputted. Weapon newWeapon = new Weapon(newName, newWeight, newCost, newRange, newDamage, newAttackSpeed); //Converts the name, weight, cost, range, damage and as into an array shopKeeperSecretInventory.AddInventory(newWeapon); //Keeps the new weapon in the secret inventory. playerInteractionIsCorrect = false; break; case "ARMOUR": //If the user says they want to make a peice of armour. //This is divised into - Type of Gear, Health, What it resists. Console.WriteLine("Okay, awesome. What is the gear type?"); _playerInteraction = Console.ReadLine(); //This would be asking what type of gear the new armour is. string newTypeOfArmour = _playerInteraction; //Stores the type of armour in a string. Console.WriteLine("What is the Health of the armour? [write it in just NUMBERS and no letters and other characters]"); ulong playerValueH = 0; //Converts the interaction to an integer. TryandCatch(ref playerValueH, playerInteraction); //This is a function in case the player accidentally puts in a value that isnt a number. ulong newHealth = playerValueH; //Saves the armous health in newHealth. Console.WriteLine("What weapon does it resist?"); _playerInteraction = Console.ReadLine(); //Asks what weapon this armour resists. string newResistence = _playerInteraction; //This resistence is then saved in newResistence. Armour newArmour = new Armour(newName, newWeight, newCost, newTypeOfArmour, newHealth, newResistence); //Converts the name, weight, cost, armourtype, health and resistence into an array. shopKeeperSecretInventory.AddInventory(newArmour); //Keeps the new armour in the secret inventory. playerInteractionIsCorrect = false; break; case "POTION": //If the user says they want to make a potion. //This is divised into - Type of Potion, Stat changes, Description. Console.WriteLine("Okay, awesome. What is the Potion type? [does it heal or does it do damage?]"); _playerInteraction = Console.ReadLine(); //Asking the player what the potion varient is "what the benefits or do damage". string newTypeOfPotion = _playerInteraction; //This stores the potion type into a string called newTypeOfPotion. Console.WriteLine("What are the stat changes by default? [write it in just NUMBERS and no letters and other characters]"); ulong playerValuePSC = 0; //Converts the interaction to an integer. TryandCatch(ref playerValuePSC, playerInteraction); //This is a function in case the player accidentally puts in a value that isnt a number. ulong newPStatChange = playerValuePSC; //Saves the the stat changes newPStatChange. Console.WriteLine("What is the description of the item? [What does it do?]"); _playerInteraction = Console.ReadLine(); //Asking the player what the description is of the item. string newDescription = _playerInteraction; //Saves the description under the string newDescription. Potion newPotion = new Potion(newName, newWeight, newCost, newTypeOfPotion, newPStatChange, newDescription); //COnverts the name, weight, cost, typeofpotion, statchanges and description into an array. shopKeeperSecretInventory.AddInventory(newPotion); //Keeps the new armour in the secret inventory. playerInteractionIsCorrect = false; break; //Gets out of the loop. default: //In case the player did not write the correct item type. Console.WriteLine("Sorry I don't think you understand the purpose of making a new item. Test error{}{}"); //In case the player does not write the correct item type. break; } } Console.WriteLine("Congratulations, you have created a new item."); Program EndStatement = new Program(); EndStatement.EndStatement();//Once the player hase completed the item, they are returned to the endstatement function. }
//This function is for the loading of the array items back onto the array. //This will act as a save file. static public void LoadingInventoryFromFile(string newFileName, ref Inventory inv) { //This is the function for loading the text file onto a array and rewriting the default one every time you open the program. if (File.Exists(newFileName)) { //Withing this feature, the called variable newFileName is defined as the streamReader called reader. StreamReader reader = new StreamReader(newFileName); while (reader.EndOfStream == false) { //Whilst the reader of the streamReader newFileName is not at the end of the text file. string reading = reader.ReadLine(); //This saves the line called reading. string[] args = reading.Split('|'); //Splits the variables using the commers. string projectDefiner = args[0]; //Grabs the file location of the different items so that it can be defined within a case statement. switch (projectDefiner) { case "Project_Assessment.Weapon": //If the projectDefiner is named Project_Assessment.Weapon... //Converting a string to a int. ulong convertToIntWeightW = UInt32.Parse(args[2]); //Converting the weapon weight to a int from string. ulong convertToIntCostW = UInt32.Parse(args[3]); //Converting the weapon Cost to a int from string. ulong convertToIntRangeW = UInt32.Parse(args[4]); //Converting the weapon Range to a int from string. ulong convertToIntDamageW = UInt32.Parse(args[5]); //Converting the weapon Damage to a int from string. ulong convertToIntAttackSpeedW = UInt32.Parse(args[6]); //Converting the weapon AttackSpeed to a int from string. //For weapons, the categories are displayed as Name, Weight, Cost, Range, Damage, AttackSpeed. Item tempWeap = new Weapon(args[1], convertToIntWeightW, convertToIntCostW, convertToIntRangeW, convertToIntDamageW, convertToIntAttackSpeedW); inv.AddInventory(tempWeap); break; //Leaves the array. case "Project_Assessment.Armour": //If the projectDefiner is named Project_Assessment.Armour... ulong convertToIntWeightA = UInt32.Parse(args[2]); //Converting the Armour weight to a int from string. ulong convertToIntCostA = UInt32.Parse(args[3]); //Converting the Armour Cost to a int from string. ulong convertToIntHealthA = UInt32.Parse(args[5]); //Converting the Armour Health to a int from string. //For Armour, the categories are displayed as Name, Weight, Cost, Type of Gear, Health, What it resists. Item tempArmour = new Armour(args[1], convertToIntWeightA, convertToIntCostA, args[4], convertToIntHealthA, args[6]); inv.AddInventory(tempArmour); break; //Leaves the array. case "Project_Assessment.Potion": //If the projectDefiner is named Project_Assessment.Potion... //For Potions, the categories are displayed as Name, Weight, Cost, Type of Potion, Stat changes, Description. ulong convertToIntWeightP = UInt32.Parse(args[2]); //Converting the Potion weight to a int from string. ulong convertToIntCostP = UInt32.Parse(args[3]); //Converting the Potion Cost to a int from string. ulong convertToIntIBOP = UInt32.Parse(args[5]); //Converting the Potion increased bonuses to a int from string. //For Armour, the categories are displayed as Name, Weight, Cost, Type of Gear, Health, What it resists. Item tempPotion = new Potion(args[1], convertToIntWeightP, convertToIntCostP, args[4], convertToIntIBOP, args[6]); inv.AddInventory(tempPotion); break; //Leaves the array. default: //If neither of the case statements are true. break; //Leaves the array. } } reader.Dispose(); reader.Close(); } }