private void btnSave_Click(object sender, EventArgs e) { //Values from both the buildings and units are saved into seperate textfiles FileStream fsU = new FileStream("SavedUnits/unitTextFile", FileMode.Create, FileAccess.Write); fsU.Close(); FileStream fsB = new FileStream("SavedBuildings/buildingTextFile", FileMode.Create, FileAccess.Write); fsB.Close(); foreach (Unit temp in ge.MapTracker.unitArray) { string typeCheck = temp.GetType().ToString(); string[] splitArray = typeCheck.Split('.'); typeCheck = splitArray[splitArray.Length - 1]; if (typeCheck == "MeleeUnit") { MeleeUnit obj = (MeleeUnit)temp; obj.Save(); } else { RangedUnit obj = (RangedUnit)temp; obj.Save(); } } foreach (Building temp in ge.MapTracker.buildingArray) { string typeCheck = temp.GetType().ToString(); string[] splitArray = typeCheck.Split('.'); typeCheck = splitArray[splitArray.Length - 1]; if (typeCheck == "ResourceBuilding") { ResourceBuilding obj = (ResourceBuilding)temp; obj.Save(); } else { FactoryBuilding obj = (FactoryBuilding)temp; obj.Save(); } } }
//Both units and buildings tostrings have been added to the rich text box to display stats private void Display() { battleInfo = ""; foreach (Unit temp in ge.MapTracker.unitArray) { string typeCheck = temp.GetType().ToString(); string[] splitArray = typeCheck.Split('.'); typeCheck = splitArray[splitArray.Length - 1]; if (typeCheck == "MeleeUnit") { MeleeUnit obj = (MeleeUnit)temp; battleInfo += obj.ToString(); } else { RangedUnit obj = (RangedUnit)temp; battleInfo += obj.ToString(); } } foreach (Building temp in ge.MapTracker.buildingArray) { string typeCheck = temp.GetType().ToString(); string[] splitArray = typeCheck.Split('.'); typeCheck = splitArray[splitArray.Length - 1]; if (typeCheck == "ResourceBuilding") { ResourceBuilding obj = (ResourceBuilding)temp; battleInfo += obj.ToString(); } else { FactoryBuilding obj = (FactoryBuilding)temp; battleInfo += obj.ToString(); } } rtxProgress.Text = battleInfo; }