//Set the races playing public void AddRace() { string Player1_race; string Player2_race; string Player3_race; string Player4_race; string Player5_race; string Player6_race; print("Adding Races"); //Reference to RaceSelection script RaceSelection race = raceInfo.GetComponent <RaceSelection>(); Player1_race = race.Player1Race; //Set to name of player's race in RaceSelection if (Player1_race != null && race.Player1Joined) //Check both name and boolean { races.Add(Player1_race); //Add to list of races playing print("Player 1 in the game"); print("Player 1 playing as: " + Player1_race); } Player2_race = race.Player2Race; if (Player2_race != null && race.Player2Joined) { races.Add(Player2_race); //Add to list of races playing print("Player 2 in the game"); print("Player 2 playing as: " + Player2_race); } Player3_race = race.Player3Race; if (Player3_race != null && race.Player3Joined) { races.Add(Player3_race); print("Player 3 in the game"); print("Player 3 playing as: " + Player3_race); } Player4_race = race.Player4Race; if (Player4_race != null && race.Player4Joined) { races.Add(Player4_race); print("Player 4 in the game"); print("Player 4 playing as: " + Player4_race); } Player5_race = race.Player5Race; if (Player5_race != null && race.Player5Joined) { races.Add(Player5_race); print("Player 5 in the game"); print("Player 5 playing as: " + Player5_race); } Player6_race = race.Player6Race; if (Player1_race != null && race.Player6Joined) { races.Add(Player6_race); print("Player 6 in the game"); print("Player 6 playing as: " + Player6_race); } print("Races Added!"); }
private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } //Dont destroy objects DontDestroyOnLoad(gameObject); }
//Load the saved game state public void Loading() { RaceSelection info = raceInfo.GetComponent <RaceSelection>(); print("Loading Game"); print("Game Beginning: " + gameBegins); //If a file exists if (File.Exists(Application.persistentDataPath + "/SaveFile.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream stream = new FileStream(Application.persistentDataPath + "/SaveFile.dat", FileMode.Open); SaveData data = (SaveData)bf.Deserialize(stream); stream.Close(); //For all saved Territories for (int i = 0; i < data.savedCountries.Count; i++) { //For all Territories to fill for (int j = 0; j < CountryManager.instance.territoryList.Count; j++) { if (data.savedCountries[i].name == CountryManager.instance. territoryList[j].GetComponent <CountryHandler>().country.name) { CountryManager.instance.territoryList[j]. GetComponent <CountryHandler>().country = data.savedCountries[i]; } } } //Restore progress values for (int j = 0; j < data.playingRaces.Count; j++) { if (data.playingRaces[j] == "AVIAN") { info.Player1Joined = true; exp_AVIAN = data.cur_exp_AVIAN; money_AVIAN = data.cur_money_AVIAN; level_AVIAN = data.cur_level_AVIAN; battalions_AVIAN = data.cur_battalions_AVIAN; territories_AVIAN = data.cur_territories_AVIAN; } if (data.playingRaces[j] == "VORTA") { info.Player2Joined = true; exp_VORTA = data.cur_exp_VORTA; money_VORTA = data.cur_money_VORTA; level_VORTA = data.cur_level_VORTA; battalions_VORTA = data.cur_battalions_VORTA; territories_VORTA = data.cur_territories_VORTA; } if (data.playingRaces[j] == "KABAL") { info.Player3Joined = true; exp_KABAL = data.cur_exp_KABAL; money_KABAL = data.cur_money_KABAL; level_KABAL = data.cur_level_KABAL; battalions_KABAL = data.cur_battalions_KABAL; territories_KABAL = data.cur_territories_KABAL; } if (data.playingRaces[j] == "EVREI") { info.Player4Joined = true; exp_EVREI = data.cur_exp_EVREI; money_EVREI = data.cur_money_EVREI; level_EVREI = data.cur_level_EVREI; battalions_EVREI = data.cur_battalions_EVREI; territories_EVREI = data.cur_territories_EVREI; } if (data.playingRaces[j] == "TENNO") { info.Player5Joined = true; exp_TENNO = data.cur_exp_TENNO; money_TENNO = data.cur_money_TENNO; level_TENNO = data.cur_level_TENNO; battalions_TENNO = data.cur_battalions_TENNO; territories_TENNO = data.cur_territories_TENNO; } if (data.playingRaces[j] == "HUMAN") { info.Player6Joined = true; exp_HUMAN = data.cur_exp_HUMAN; money_HUMAN = data.cur_money_HUMAN; level_HUMAN = data.cur_level_HUMAN; battalions_HUMAN = data.cur_battalions_HUMAN; territories_HUMAN = data.cur_territories_HUMAN; } } CURRENTRACE = data.cur_race; SetUpDone = true; CountryManager.instance.TintTerritories(); print("Game Loaded!"); for (int j = 0; j < data.playingRaces.Count; j++) { races.Add(data.playingRaces[j]); } gameBegins = false; StartCoroutine(Turn()); //If a file does not exist } else { print("No Save File found. Starting SetUp."); AddRace(); SetUpDone = false; StartCoroutine(SetUp(true)); if (SetUpDone == true) { CountryManager.instance.TintTerritories(); } } }
public void RemoveRace() { print("Checking if a player has been eliminated"); int count = 0; foreach (string race in races) { print("Checking " + race); count = 0; foreach (GameObject owned in CountryManager.instance.territoryList) { CountryHandler handler = owned.GetComponent <CountryHandler>(); if (handler.country.race == race) { print("Owned territory found"); count++; } } if (count == 0) { RaceSelection info = raceInfo.GetComponent <RaceSelection>(); print("Removing: " + race + " they have been eliminated."); if (race == "AVIAN") { info.Player1Joined = false; print(race + "has been removed"); } if (race == "VORTA") { info.Player2Joined = false; print(race + "has been removed"); } if (race == "KABAL") { info.Player3Joined = false; print(race + "has been removed"); } if (race == "EVREI") { info.Player4Joined = false; print(race + "has been removed"); } if (race == "TENNO") { info.Player5Joined = false; print(race + "has been removed"); } if (race == "HUMAN") { info.Player6Joined = false; print(race + "has been removed"); } } print("Territories owned by " + race + " = " + count); } }
//Thread for the main game loop public IEnumerator Turn() { print("Starting Turn Thread."); int i; RaceSelection info = raceInfo.GetComponent <RaceSelection>(); CountryManager.instance.RestoreLeaderboard(); for (i = 1; i <= 1000; i++) { for (int j = 0; j < races.Count; j++) //For each race playing { //Skip over turns until the last played player is found if (races[j] != CURRENTRACE && i == 1 && CountryManager.instance.turnOver == false) { continue; } print("Starting turn for " + races[j]); print("turnover state: " + CountryManager.instance.turnOver); CURRENTRACE = races[j]; //Set the playing race to be used in other classes if (CURRENTRACE == "AVIAN" && info.Player1Joined) { exp = exp_AVIAN; money = money_AVIAN; level = level_AVIAN; territory = territories_AVIAN; battalions = battalions_AVIAN; print("Info loaded for AVIAN"); CountryManager.instance.turnOver = false; } if (CURRENTRACE == "VORTA" && info.Player2Joined) { exp = exp_VORTA; money = money_VORTA; level = level_VORTA; territory = territories_VORTA; battalions = battalions_VORTA; print("Info loaded for VORTA"); CountryManager.instance.turnOver = false; } if (CURRENTRACE == "KABAL" && info.Player3Joined) { exp = exp_KABAL; money = money_KABAL; level = level_KABAL; territory = territories_KABAL; battalions = battalions_KABAL; print("Info loaded for KABAL"); CountryManager.instance.turnOver = false; } if (CURRENTRACE == "EVREI" && info.Player4Joined) { exp = exp_EVREI; money = money_EVREI; level = level_EVREI; territory = territories_EVREI; battalions = battalions_EVREI; print("Info loaded for EVREI"); CountryManager.instance.turnOver = false; } if (CURRENTRACE == "TENNO" && info.Player5Joined) { exp = exp_TENNO; money = money_TENNO; level = level_TENNO; territory = territories_TENNO; battalions = battalions_TENNO; print("Info loaded for TENNO"); CountryManager.instance.turnOver = false; } if (CURRENTRACE == "HUMAN" && info.Player6Joined) { exp = exp_HUMAN; money = money_HUMAN; level = level_HUMAN; territory = territories_HUMAN; battalions = battalions_HUMAN; print("Info loaded for HUMAN"); CountryManager.instance.turnOver = false; } CountryManager.instance.ShowGUI(CURRENTRACE, money, exp, level); //Display progress on screen if (DraftDone == false) //if in the draft phase { CountryManager.instance.CalculateOwnedTerritories(); CountryManager.instance.ShowDraftPanel(); } print("Waiting for end of turn..."); //Wait for turn to end while (CountryManager.instance.turnOver == false) { yield return(null); } if (CURRENTRACE == "AVIAN") { exp_AVIAN = exp; money_AVIAN = money; level_AVIAN = level; territories_AVIAN = territory; battalions_AVIAN = battalions; print("Saved AVIAN info"); } if (CURRENTRACE == "VORTA") { exp_VORTA = exp; money_VORTA = money; level_VORTA = level; territories_VORTA = territory; battalions_VORTA = battalions; print("Saved VORTA info"); } if (CURRENTRACE == "KABAL") { exp_KABAL = exp; money_KABAL = money; level_KABAL = level; territories_KABAL = territory; battalions_KABAL = battalions; print("Saved KABAL info"); } if (CURRENTRACE == "EVREI") { exp_EVREI = exp; money_EVREI = money; level_EVREI = level; territories_EVREI = territory; battalions_EVREI = battalions; print("Saved EVREI info"); } if (CURRENTRACE == "TENNO") { exp_TENNO = exp; money_TENNO = money; level_TENNO = level; territories_TENNO = territory; battalions_TENNO = battalions; print("Saved TENNO info"); } if (CURRENTRACE == "HUMAN") { exp_HUMAN = exp; money_HUMAN = money; level_HUMAN = level; territories_HUMAN = territory; battalions_HUMAN = battalions; print("Saved HUMAN info"); } print("Turn number: " + i + " complete for " + CURRENTRACE); } if (gameActive == true) { print("Game is still active: " + gameActive); } //If game has ended if (gameActive == false) { i = 1000; print("GAME OVER!!!"); } } }