//Function that loads the unit party public void loadParty() { //Create instance of FileIOS object FileIOS File = new FileIOS(); //Create an instance of a new Party object Party Team = new Party(); //If count of the ulBattleReadyParty is greater than or equal to 1 if (ulBattleReadyParty.Count >= 1) {//Remove all elements of the current ulBattleReadyParty list ulBattleReadyParty.RemoveRange(0, ulBattleReadyParty.Count); } //string victoryParty = EditorUtility.OpenFilePanel("Open File", Application.dataPath + "/GameData/VictoryParty", "xml"); //Store file path into the string variable string victoryParty = Application.dataPath + "/GameData/VictoryParty/WinningParty.xml"; //Deserialize the the object in the path and store into party variable Team = File.Deserialize<Party>(victoryParty); //Set proper text variables to proper values ifP1Name.text = Team.ulUnits[0].sName; ifP1Name.text = Team.ulUnits[0].sName; ifP1Health.text = Team.ulUnits[0].iHealth.ToString(); ifP1Strength.text = Team.ulUnits[0].iStrength.ToString(); ifP1Defense.text = Team.ulUnits[0].iDefense.ToString(); ifP1Speed.text = Team.ulUnits[0].iSpeed.ToString(); ifP1Level.text = Team.ulUnits[0].iLevel.ToString(); //Add unit to list ulBattleReadyParty.Add(Team.ulUnits[0]); //Set proper text variables to proper values ifP2Name.text = Team.ulUnits[1].sName; ifP2Name.text = Team.ulUnits[1].sName; ifP2Health.text = Team.ulUnits[1].iHealth.ToString(); ifP2Strength.text = Team.ulUnits[1].iStrength.ToString(); ifP2Defense.text = Team.ulUnits[1].iDefense.ToString(); ifP2Speed.text = Team.ulUnits[1].iSpeed.ToString(); ifP2Level.text = Team.ulUnits[1].iLevel.ToString(); //Add unit to list ulBattleReadyParty.Add(Team.ulUnits[1]); //Set proper text variables to proper values ifP3Name.text = Team.ulUnits[2].sName; ifP3Name.text = Team.ulUnits[2].sName; ifP3Health.text = Team.ulUnits[2].iHealth.ToString(); ifP3Strength.text = Team.ulUnits[2].iStrength.ToString(); ifP3Defense.text = Team.ulUnits[2].iDefense.ToString(); ifP3Speed.text = Team.ulUnits[2].iSpeed.ToString(); ifP3Level.text = Team.ulUnits[2].iLevel.ToString(); //Add unit to list ulBattleReadyParty.Add(Team.ulUnits[2]); //Set images to passed in list setImages(ulBattleReadyParty); //Create objects Unit TwoFaced = new Unit("2Faced", 100, 20, 15, 5, 25, "Enemy"); Unit AncientDragon = new Unit("Ancient Dragon", 200, 30, 12, 4, 100, "Enemy"); Unit Ghost = new Unit("Ghost", 80, 20, 15, 5, 30, "Enemy"); Unit IceGolem = new Unit("Ice Golem", 150, 25, 15, 5, 35, "Enemy"); Unit Zuu = new Unit("Zuu", 120, 15, 10, 5, 20, "Enemy"); Unit ToxicFrog = new Unit("Toxic Frog", 180, 22, 12, 5, 30, "Enemy"); Unit DeathClaw = new Unit("Death Claw", 140, 25, 18, 7, 50, "Enemy"); Unit MasterTonberry = new Unit("Master Tonberry", 170, 20, 15, 5, 50, "Enemy"); Unit Behemoth = new Unit("Behemoth", 200, 35, 14, 4, 100, "Enemy"); //Create a new list List<Unit> ulE = new List<Unit>(); //Add the Enemy Types to the list ulE.Add(TwoFaced); ulE.Add(AncientDragon); ulE.Add(Ghost); ulE.Add(IceGolem); ulE.Add(Zuu); ulE.Add(ToxicFrog); ulE.Add(DeathClaw); ulE.Add(MasterTonberry); ulE.Add(Behemoth); //Creat an instance of Random class System.Random a = new System.Random(); //call Next() 3 times giving random selection for enemy party members int e1 = a.Next(0, ulE.Count - 1); int e2 = a.Next(0, ulE.Count - 1); int e3 = a.Next(0, ulE.Count - 1); //while e1 is equal to ee2 while (e1 == e2) {//Randomize e2 e2 = a.Next(0, ulE.Count - 1); } //while e2 is equal to e3 while (e2 == e3) {//Randomize e3 e3 = a.Next(0, ulE.Count - 1); } //while e3 is equal to e1 while (e3 == e1) {//Randomize e1 e1 = a.Next(0, ulE.Count - 1); //while e1 is equal to e2 while (e1 == e2) {//Randomize e1 e1 = a.Next(0, ulE.Count - 1); } } //Add unit to list ulBattleReadyParty.Add(ulE[e1]); //Add unit to list ulBattleReadyParty.Add(ulE[e2]); //Add unit to list ulBattleReadyParty.Add(ulE[e3]); //Enable play button bPlayButton.enabled = true; }
//Function activated when the load party button is clicked private void LoadButton_Click(object sender, EventArgs e) {//Create an empty party object Party loadedunits; //Create a variable storing a directory string path = @"..\Saved Parties"; //Create an instance of an OpenFileDialog OpenFileDialog DialogWindow = new OpenFileDialog(); //If DialogWindow Initial Directory is not equal to the path variable if (DialogWindow.InitialDirectory != path) {//Set the directory to the path variable DialogWindow.InitialDirectory = path; } //Set file type choices to appear DialogWindow.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; //Sets filter selected DialogWindow.FilterIndex = 2; //If the Ok button is clicked int the DialogWindow if (DialogWindow.ShowDialog() == DialogResult.OK) {//Store the chosen file selected by the user into this string variable string chosenFile = DialogWindow.FileName; //Deserialize the chosen file as a Party Object and store into loadedunits variable loadedunits = _Save.Deserialize <Party>(chosenFile); //Set the P1NameBox.Text to the units name in the loadedunits party at the specified index P1NameBox.Text = loadedunits.ulUnits[0].sName; //Set the player1name to the units name in the loadedunits party at the specified index player1name = loadedunits.ulUnits[0].sName; //Set the P1HealthBox.Text to the units health in the loadedunits party at the specified index P1HealthBox.Text = loadedunits.ulUnits[0].iHealth.ToString(); //Set the P1strengthBox.Text to the units strength in the loadedunits party at the specified index P1StrengthBox.Text = loadedunits.ulUnits[0].iStrength.ToString(); //Set the P1SpeedBox.Text to the units speed in the loadedunits party at the specified index P1SpeedBox.Text = loadedunits.ulUnits[0].iSpeed.ToString(); //Set the P1DefenseBox.Text to the units defense in the loadedunits party at the specified index P1DefenseBox.Text = loadedunits.ulUnits[0].iDefense.ToString(); //Set the P1LevelBox.Text to the units level in the loadedunits party at the specified index P1LevelBox.Text = loadedunits.ulUnits[0].iLevel.ToString(); //Set the P2NameBox.Text to the units name in the loadedunits party at the specified index P2NameBox.Text = loadedunits.ulUnits[1].sName; //Set the player2name to the units name in the loadedunits party at the specified index player2name = loadedunits.ulUnits[1].sName; //Set the P2HealthBox.Text to the units health in the loadedunits party at the specified index P2HealthBox.Text = loadedunits.ulUnits[1].iHealth.ToString(); //Set the P2StrengthBox.Text to the units strength in the loadedunits party at the specified index P2StrengthBox.Text = loadedunits.ulUnits[1].iStrength.ToString(); //Set the P2SpeedBox.Text to the units speed in the loadedunits party at the specified index P2SpeedBox.Text = loadedunits.ulUnits[1].iSpeed.ToString(); //Set the P2DefenseBox.Text to the units defense in the loadedunits party at the specified index P2DefenseBox.Text = loadedunits.ulUnits[1].iDefense.ToString(); //Set the P2LevelBox.Text to the units level in the loadedunits party at the specified index P2LevelBox.Text = loadedunits.ulUnits[1].iLevel.ToString(); //Set the P3NameBox.Text to the units name in the loadedunits party at the specified index P3NameBox.Text = loadedunits.ulUnits[2].sName; //Set the player3name to the units name in the loadedunits party at the specified index player3name = loadedunits.ulUnits[2].sName; //Set the P3HealthBox.Text to the units health in the loadedunits party at the specified index P3HealthBox.Text = loadedunits.ulUnits[2].iHealth.ToString(); //Set the P3StrengthBox.Text to the units strength in the loadedunits party at the specified index P3StrengthBox.Text = loadedunits.ulUnits[2].iStrength.ToString(); //Set the P3SpeedBox.Text to the units speed in the loadedunits party at the specified index P3SpeedBox.Text = loadedunits.ulUnits[2].iSpeed.ToString(); //Set the P3DefenseBox.Text to the units defense in the loadedunits party at the specified index P3DefenseBox.Text = loadedunits.ulUnits[2].iDefense.ToString(); //Set the P3LevelBox.Text to the units level in the loadedunits party at the specified index P3LevelBox.Text = loadedunits.ulUnits[2].iLevel.ToString(); //If BattleReadyParty.Count is greater than or equal to 1 if (BattleReadyParty.Count >= 1) {//Remove all elements in the list BattleReadyParty.RemoveRange(0, BattleReadyParty.Count); } //Foreach unit in the loaddedunits.units list foreach (Unit i in loadedunits.ulUnits) {//Add the unit to the BattleReadyParty BattleReadyParty.Add(i); } //Create an empty list List <Unit> tempParty = new List <Unit>(); //Store the returned list from the CreateObjects function into the list tempParty = CreateObjects(); //Foreach unit in the new list foreach (Unit i in tempParty) { //If the type of the unit is Enemy if (i.sType == "Enemy") { //Add the unit to the Enemies List Enemies.Add(i); } } //Create instance of Random Object Random a = new Random(); //call Next() 3 times giving random selection for enemy members int e1 = a.Next(0, Enemies.Count); int e2 = a.Next(0, Enemies.Count); int e3 = a.Next(0, Enemies.Count); //while e1 is equal to e2 while (e1 == e2) {//Randomize e2 e2 = a.Next(0, Enemies.Count - 1); } //while e2 is equal to e3 while (e2 == e3) {//Randomize e3 e3 = a.Next(0, Enemies.Count - 1); } //while e3 is equal to e1 while (e3 == e1) {//Randomize e1 e1 = a.Next(0, Enemies.Count - 1); //while e1 is equal to e2 while (e1 == e2) {//Randomize e1 e1 = a.Next(0, Enemies.Count - 1); } } //Set enemy1name to the name of the object at the given index enemy1name = Enemies[e1].sName; //Set enemy2name to the name of the object at the given index enemy2name = Enemies[e2].sName; //Set enemy3name to the name of the object at the given index enemy3name = Enemies[e3].sName; //Add the specified unit to the BattlePartyReady list BattleReadyParty.Add(Enemies[e1]); //Add the specified unit to the BattlePartyReady list BattleReadyParty.Add(Enemies[e2]); //Add the specified unit to the BattlePartyReady list BattleReadyParty.Add(Enemies[e3]); //Set images for the units in the party list previewImages(loadedunits.ulUnits); } }
//Function that loads the unit party public void loadParty() {//Create instance of FileIOS object FileIOS File = new FileIOS(); //Create an instance of a new Party object Party Team = new Party(); //If count of the ulBattleReadyParty is greater than or equal to 1 if (ulBattleReadyParty.Count >= 1) {//Remove all elements of the current ulBattleReadyParty list ulBattleReadyParty.RemoveRange(0, ulBattleReadyParty.Count); } //string victoryParty = EditorUtility.OpenFilePanel("Open File", Application.dataPath + "/GameData/VictoryParty", "xml"); //Store file path into the string variable string victoryParty = Application.dataPath + "/GameData/VictoryParty/WinningParty.xml"; //Deserialize the the object in the path and store into party variable Team = File.Deserialize <Party>(victoryParty); //Set proper text variables to proper values ifP1Name.text = Team.ulUnits[0].sName; ifP1Name.text = Team.ulUnits[0].sName; ifP1Health.text = Team.ulUnits[0].iHealth.ToString(); ifP1Strength.text = Team.ulUnits[0].iStrength.ToString(); ifP1Defense.text = Team.ulUnits[0].iDefense.ToString(); ifP1Speed.text = Team.ulUnits[0].iSpeed.ToString(); ifP1Level.text = Team.ulUnits[0].iLevel.ToString(); //Add unit to list ulBattleReadyParty.Add(Team.ulUnits[0]); //Set proper text variables to proper values ifP2Name.text = Team.ulUnits[1].sName; ifP2Name.text = Team.ulUnits[1].sName; ifP2Health.text = Team.ulUnits[1].iHealth.ToString(); ifP2Strength.text = Team.ulUnits[1].iStrength.ToString(); ifP2Defense.text = Team.ulUnits[1].iDefense.ToString(); ifP2Speed.text = Team.ulUnits[1].iSpeed.ToString(); ifP2Level.text = Team.ulUnits[1].iLevel.ToString(); //Add unit to list ulBattleReadyParty.Add(Team.ulUnits[1]); //Set proper text variables to proper values ifP3Name.text = Team.ulUnits[2].sName; ifP3Name.text = Team.ulUnits[2].sName; ifP3Health.text = Team.ulUnits[2].iHealth.ToString(); ifP3Strength.text = Team.ulUnits[2].iStrength.ToString(); ifP3Defense.text = Team.ulUnits[2].iDefense.ToString(); ifP3Speed.text = Team.ulUnits[2].iSpeed.ToString(); ifP3Level.text = Team.ulUnits[2].iLevel.ToString(); //Add unit to list ulBattleReadyParty.Add(Team.ulUnits[2]); //Set images to passed in list setImages(ulBattleReadyParty); //Create objects Unit TwoFaced = new Unit("2Faced", 100, 20, 15, 5, 25, "Enemy"); Unit AncientDragon = new Unit("Ancient Dragon", 200, 30, 12, 4, 100, "Enemy"); Unit Ghost = new Unit("Ghost", 80, 20, 15, 5, 30, "Enemy"); Unit IceGolem = new Unit("Ice Golem", 150, 25, 15, 5, 35, "Enemy"); Unit Zuu = new Unit("Zuu", 120, 15, 10, 5, 20, "Enemy"); Unit ToxicFrog = new Unit("Toxic Frog", 180, 22, 12, 5, 30, "Enemy"); Unit DeathClaw = new Unit("Death Claw", 140, 25, 18, 7, 50, "Enemy"); Unit MasterTonberry = new Unit("Master Tonberry", 170, 20, 15, 5, 50, "Enemy"); Unit Behemoth = new Unit("Behemoth", 200, 35, 14, 4, 100, "Enemy"); //Create a new list List <Unit> ulE = new List <Unit>(); //Add the Enemy Types to the list ulE.Add(TwoFaced); ulE.Add(AncientDragon); ulE.Add(Ghost); ulE.Add(IceGolem); ulE.Add(Zuu); ulE.Add(ToxicFrog); ulE.Add(DeathClaw); ulE.Add(MasterTonberry); ulE.Add(Behemoth); //Creat an instance of Random class System.Random a = new System.Random(); //call Next() 3 times giving random selection for enemy party members int e1 = a.Next(0, ulE.Count - 1); int e2 = a.Next(0, ulE.Count - 1); int e3 = a.Next(0, ulE.Count - 1); //while e1 is equal to ee2 while (e1 == e2) {//Randomize e2 e2 = a.Next(0, ulE.Count - 1); } //while e2 is equal to e3 while (e2 == e3) {//Randomize e3 e3 = a.Next(0, ulE.Count - 1); } //while e3 is equal to e1 while (e3 == e1) {//Randomize e1 e1 = a.Next(0, ulE.Count - 1); //while e1 is equal to e2 while (e1 == e2) {//Randomize e1 e1 = a.Next(0, ulE.Count - 1); } } //Add unit to list ulBattleReadyParty.Add(ulE[e1]); //Add unit to list ulBattleReadyParty.Add(ulE[e2]); //Add unit to list ulBattleReadyParty.Add(ulE[e3]); //Enable play button bPlayButton.enabled = true; }
//Load a game from an xml file public void LoadGame() {//Create a Party instance Party EnemyE = new Party(); //Create a Party instance Party PlayerP = new Party(); //Open the file Path and store it in this variable string playerParty = Application.dataPath + "/GameData/PlayerParty/p.xml"; //Open the file Path and store it in this variable string enemyParty = Application.dataPath + "/GameData/EnemyParty/e.xml"; //Open the file Path and store it in this variable string currentstate = Application.dataPath + "/GameData/State/s.xml"; //Open the file Path and store it in this variable string currentUnit = Application.dataPath + "/GameData/index.xml"; //Deserialize the data as a Party object and store into this variable PlayerP = File.Deserialize <Party>(playerParty); //Deserialize the data as a Party object and store into this variable EnemyE = File.Deserialize <Party>(enemyParty); //Deserialize the data as a string object and store into this variable string state = File.Deserialize <string>(currentstate); //Deserialize the data as an int object and store into this variable game.iIndex = File.Deserialize <int>(currentUnit); //If the BattleReadyPartys count is greater than or equal to 1 if (game.canvasScript.ulBattleReadyParty.Count >= 1) {//Remove all elements from the list game.canvasScript.ulBattleReadyParty.RemoveRange(0, game.canvasScript.ulBattleReadyParty.Count); } //Add the specified unit to the BattlePartyReady list game.canvasScript.ulBattleReadyParty.Add(PlayerP.ulUnits[0]); //Add the specified unit to the BattlePartyReady list game.canvasScript.ulBattleReadyParty.Add(PlayerP.ulUnits[1]); //Add the specified unit to the BattlePartyReady list game.canvasScript.ulBattleReadyParty.Add(PlayerP.ulUnits[2]); //Add the specified unit to the BattlePartyReady list game.canvasScript.ulBattleReadyParty.Add(EnemyE.ulUnits[0]); //Add the specified unit to the BattlePartyReady list game.canvasScript.ulBattleReadyParty.Add(EnemyE.ulUnits[1]); //Add the specified unit to the BattlePartyReady list game.canvasScript.ulBattleReadyParty.Add(EnemyE.ulUnits[2]); //Call Function to print out the stats of all objects in battle game.a.ulParticipants = game.sortBySpeed(game.canvasScript.ulBattleReadyParty); //Loop through the list for (int i = 0; i < game.a.ulParticipants.Count; i++) {//Set the BattleOrderTextBox text to a newline with the current units name game.ifBattleOrderText.text += "\n" + game.a.ulParticipants[i].sName; } //Foreach unit in the list foreach (Unit i in game.a.ulParticipants) { //If the current unit is of type Player if (i.sType == "Player") { //Add the unit to this party game.ulPlayerParty.Add(i); } //If the current unit is of type Enemy if (i.sType == "Enemy") {//Add the unit to this party game.ulEnemyParty.Add(i); } } //Set the player1Name text to the given index of the PlayerP list game.canvasScript.tPlayer1Name.text = PlayerP.ulUnits[0].sName; //Set the player2Name text to the given index of the PlayerP list game.canvasScript.tPlayer2Name.text = PlayerP.ulUnits[1].sName; //Set the player3Name text to the given index of the PlayerP list game.canvasScript.tPlayer3Name.text = PlayerP.ulUnits[2].sName; //Set the enemy1Name text to the given index of the EnemyE list game.canvasScript.tEnemy1Name.text = EnemyE.ulUnits[0].sName; //Set the enemy2Name text to the given index of the EnemyE list game.canvasScript.tEnemy2Name.text = EnemyE.ulUnits[1].sName; //Set the enemy3Name text to the given index of the EnemyE list game.canvasScript.tEnemy3Name.text = EnemyE.ulUnits[2].sName; //Call the function to load in the proper images game.canvasScript.LoadedGameImages(game.a.ulParticipants); //Call Function to print out the stats of all objects in battle game.manager.StatsOfObjects(game.a.ulParticipants); //Set the StatsField text variable to the data in the statsText variable game.ifStatsField.text = game.manager.statsText; //Load Battle Scene cCanvas game.cBattleCanvas.enabled = true; //Disable the gamecCanvas game.canvasScript.cGameCanvas.enabled = false; //Print out whose current turn it is game.ifBattleBox.text += "It is " + game.a.ulParticipants[game.iIndex].sName + "'s turn!\n"; //Feed the state machine game.fsm.Feed(state); }