diff --git a/Assets/Scenes/SceneGame.unity b/Assets/Scenes/SceneGame.unity index 38f547d..b903e88 100644 --- a/Assets/Scenes/SceneGame.unity +++ b/Assets/Scenes/SceneGame.unity @@ -5834,8 +5834,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 1000, y: 250} - m_SizeDelta: {x: 300, y: 200} + m_AnchoredPosition: {x: 1175, y: -225} + m_SizeDelta: {x: 250, y: 250} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &212927945 MonoBehaviour: @@ -36878,7 +36878,7 @@ RectTransform: m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 2560, y: 2000} + m_SizeDelta: {x: 2560, y: 1440} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1840452419 MonoBehaviour: @@ -36900,7 +36900,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: Card Inventory + m_text: Outcome of Trading in Cards m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: e3afd6450cbd8a84cbcc577456a52d03, type: 2} m_sharedMaterial: {fileID: 5575954358767294868, guid: e3afd6450cbd8a84cbcc577456a52d03, type: 2} diff --git a/Assets/Scripts/Country.cs b/Assets/Scripts/Country.cs index d769c54..a6390e7 100644 --- a/Assets/Scripts/Country.cs +++ b/Assets/Scripts/Country.cs @@ -121,7 +121,7 @@ public void ReverseColorChange() /// /// List of Country objects that are neighboring enemies. /// - public List HighlightEnemyNeighbours() + public List HighlightEnemyNeighbors() { TempColorChange(Color.grey); @@ -138,12 +138,12 @@ public List HighlightEnemyNeighbours() } /// - /// HighlightFriendlyNeighbours recursively checks all neighbors and if they are friendly, adds them to a list. + /// HighlightFriendlyNeighbors recursively checks all neighbors and if they are friendly, adds them to a list. /// /// /// List of Country that you can fortify with. /// - public List HighlightFriendlyNeighbours() // currently only finds 1 layer of neighbors + public List HighlightFriendlyNeighbors() // currently only finds 1 layer of neighbors { TempColorChange(Color.grey); diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index 9cfa16a..2a5c472 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -7,7 +7,6 @@ using UnityEngine.SceneManagement; using UnityEngine.UI; - /// /// GameController handles the logic of the local version of the game. /// @@ -100,7 +99,13 @@ private GameController(int playerCount, Canvas distributeCanvas, Canvas attackCa this.HandleObjectClick = SetupPhase; } - //singleton's constructor method access thru here + /// + /// New creates and starts a new game. + /// + /// The number of players the game will start with (players + agents). + /// + /// New GameController instance. + /// public static GameController New(int playerCount, Canvas distributeCanvas, Canvas attackCanvas, Canvas defendCanvas, Canvas transferCanvas, Canvas diceCanvas, Canvas cardInventory) { //if (instance != null) return GameController.instance; // find a better way of joining a game that already exists, this does not work @@ -108,9 +113,21 @@ public static GameController New(int playerCount, Canvas distributeCanvas, Canva return GameController.instance; } + /// + /// Get retrieves the instance of the currently open game. + /// + /// + /// Current GameController instance (including current game state). + /// public static GameController Get() => GameController.instance; - // returns a color from a random int + /// + /// IntToColor converts a number into a color. Use when setting up the game to get player colors. + /// + /// The number of players the game will start with (players + agents). + /// + /// Unique Color for each number input. + /// public static Color IntToColor(int num) => num switch { 0 => new Color(0.95f, 0.30f, 0.30f), @@ -122,8 +139,7 @@ public static GameController New(int playerCount, Canvas distributeCanvas, Canva _ => throw new Exception("color not found"), }; - // this generates a of colors that represents the distributed number of countries, - // if 5 reds are here red holds five countries + /* unused public List GenerateListOfColors() { int numberOfCountries = 0; @@ -171,8 +187,15 @@ private List GenerateTurnsOrderAsColors() } return output; } - - // generate the Randomized a color list to track turns + */ + + /// + /// CreateTurns gets the number of players required, creates the Player and AIPlayer objects required. + /// Then, these objects are added to a list. + /// + /// + /// List of players and AI agents in the order of their turns. + /// private static List CreateTurns() { List listOfPlayers = new List(); @@ -196,11 +219,19 @@ private static List CreateTurns() return output; } + /// + /// SetCountryMap sets the map of buttons to Country objects to handle clicks correctly. + /// + /// The map of buttons to their Country object. public void SetCountryMap(Dictionary map) { this.countryMap = map; } + /// + /// SetupPhase handles clicks in the phase where not all countries are owned. + /// + /// The object the user has clicked. public void SetupPhase(GameObject selectedObj) { if (selectedObj == null || (!selectedObj.name.StartsWith("country") && !selectedObj.name.StartsWith("Rename"))) return; @@ -233,6 +264,11 @@ public void SetupPhase(GameObject selectedObj) } } + /// + /// SetupDeployPhase handles clicks in the phase where all countries are owned; + /// but some players have troops left to deploy. + /// + /// The object the user has clicked. public void SetupDeployPhase(GameObject selectedObj) { if (selectedObj == null) return; @@ -333,6 +369,10 @@ public void SetupDeployPhase(GameObject selectedObj) } } + /// + /// DraftPhase handles clicks in the first phase of each player's turn, troops are deployed. + /// + /// The object the user has clicked. public void DraftPhase(GameObject selectedObj) { if (selectedObj == null) return; @@ -429,6 +469,10 @@ public void DraftPhase(GameObject selectedObj) } } + /// + /// AttackPhase handles clicks in the attacking phase of the turn. + /// + /// The object the user has clicked. public void AttackPhase(GameObject selectedObj) { if (selectedObj == null) return; @@ -509,6 +553,10 @@ public void AttackPhase(GameObject selectedObj) return; } + /// + /// FortifyPhase handles clicks in the phase after attack where players can fortify a country. + /// + /// The object the user has clicked. public void FortifyPhase(GameObject selectedObj) { if (TransferCanvas.enabled) @@ -587,24 +635,29 @@ public void FortifyPhase(GameObject selectedObj) return; } + /// + /// HandleCardClick handles clicks in the card inventory screen. + /// + /// The object the user has clicked. private void HandleCardClick(GameObject selectedObj) { switch (selectedObj.name) { case "Trade": - if (this.turnPlayer.Trade()) + if (this.turnPlayer.Trade()) { - GameObject.Find("TradeResultText").GetComponent().text = "Trade was successful. You gained 6 troops."; + GameObject.Find("TradeResultText").GetComponent().text = "Trade was successful. You gained 6 troops."; GameObject.Find("TradeResultText").GetComponent().color = Color.green; } - else + else { - GameObject.Find("TradeResultText").GetComponent().text = "Trade was unsuccessful. You have to trade one of each type or three of a type."; + GameObject.Find("TradeResultText").GetComponent().text = "Trade was unsuccessful. You have to trade one of each type or three of a type."; GameObject.Find("TradeResultText").GetComponent().color = Color.red; } GameObject.Find("TradeResult").GetComponent().enabled = true; - Wait.Start(2f, () => { + Wait.Start(2f, () => + { GameObject.Find("TradeResult").GetComponent().enabled = false; }); return; @@ -637,39 +690,70 @@ private void HandleCardClick(GameObject selectedObj) } } - private void HandleRenameClick(GameObject selectedObj) + /// + /// HandleRenameClick handles clicks in the rename country screen. + /// + /// The object the user has clicked. + public void HandleRenameClick(GameObject selectedObj) { switch (selectedObj.name) { case "RenameCountryButton": GameObject.Find("RenameCountry").GetComponent().enabled = true; break; + case "RenameConfirm": string from = GameObject.Find("RenameCountryFrom").GetComponent().text.FirstCharacterToUpper(); string to = GameObject.Find("RenameCountryTo").GetComponent().text.FirstCharacterToUpper(); + Country foundCountry = null; + string[] names = new string[countryMap.Count]; + int i = 0; + foreach (var kvp in countryMap) { - if (kvp.Value.GetName().ToLower().Equals(from.ToLower())) + string name = kvp.Value.GetName(); + names[i] = name; + i++; + if (to.ToLower().Equals(name.ToLower())) { - kvp.Value.SetName(to); - Killfeed.Update($"'{from}' was renamed to '{to}'"); + Killfeed.Update($"Country '{to}' already exists"); GameObject.Find("RenameCountry").GetComponent().enabled = false; + GameObject.Find("RenameCountryFrom").GetComponent().text = ""; + GameObject.Find("RenameCountryTo").GetComponent().text = ""; return; } + + if (name.ToLower().Equals(from.ToLower())) foundCountry = kvp.Value; + } + + if (foundCountry != null) + { + foundCountry.SetName(to); + Killfeed.Update($"'{from}' was renamed to '{to}'"); + } + else + { + Killfeed.Update($"Country '{from}' does not exist"); } - Killfeed.Update($"Country '{from}' does not exist"); GameObject.Find("RenameCountry").GetComponent().enabled = false; - break; + GameObject.Find("RenameCountryFrom").GetComponent().text = ""; + GameObject.Find("RenameCountryTo").GetComponent().text = ""; + return; + case "RenameCancel": GameObject.Find("RenameCountry").GetComponent().enabled = false; - break; - default: - break; + return; + + default: return; } } + /// + /// HandleAttackClick handles clicks in the attacking screen. + /// + /// The object the user has clicked. private void HandleAttackClick(GameObject selectedObj) { TextMeshProUGUI numberOfTroops = GameObject.Find("NumberOfTroopsToSend").GetComponent(); @@ -734,6 +818,10 @@ private void HandleAttackClick(GameObject selectedObj) } } + /// + /// HandleAttackClick handles clicks in the troop defend screen. + /// + /// The object the user has clicked. private void HandleDefendClick(GameObject selectedObj) { int attacker_num = Int32.Parse(GameObject.Find("RemainingDefend").GetComponent().text.Split("\n")[0].Substring(18)); @@ -774,6 +862,10 @@ private void HandleDefendClick(GameObject selectedObj) } } + /// + /// HandleTransferClick handles clicks in the transferring of troops screen. + /// + /// The object the user has clicked. private void HandleTransferClick(GameObject selectedObj) { int available = recentFight[0].GetTroops() - 1; @@ -822,6 +914,10 @@ private void HandleTransferClick(GameObject selectedObj) } } + /// + /// HandleFortifyClick handles clicks in the country fortification screen. + /// + /// The object the user has clicked. private void HandleFortifyClick(GameObject selectedObj) { if (selectedObj == null) return; @@ -890,20 +986,44 @@ private void HandleFortifyClick(GameObject selectedObj) } } + /// + /// HighlightEnemy changes the color of all enemies that you can attack. + /// + /// The country that has enemies you want to highlight. public void HighlightEnemy(Country country) { this.attacker = country; - this.considered = country.HighlightEnemyNeighbours(); + this.considered = country.HighlightEnemyNeighbors(); return; } - public void HighlightFriendly(Country country) + /// + /// HighlightConnectedCountries recurses through all connected countries to find which ones can be fortified. + /// + private void HighlightConnectedCountries() { - this.attacker = country; - this.considered = country.HighlightFriendlyNeighbours(); - return; + List visited = new List(); + Action, Country> recurse = null; + recurse = (visited, country) => + { + visited.Add(country); + country.TempColorChange(Color.white); + + foreach (Country neighbor in country.GetNeighbors()) + { + if (neighbor.GetOwner() != attacker.GetOwner() || visited.Contains(neighbor)) continue; + recurse(visited, neighbor); + } + }; + + recurse(visited, this.attacker); + this.attacker.TempColorChange(Color.grey); + this.considered = visited; } + /// + /// UnHighlight reverses any color changes that happened during attack or fortify. + /// public void UnHighlight() { if (attacker != null) @@ -917,6 +1037,14 @@ public void UnHighlight() } } + /// + /// Attack handles the whole attack after the users have chosen countries and troops. + /// Rolls dice and shows outcome of fight. + /// + /// The country that is going to attack. + /// The country that is going to defend. + /// The number of troops that are going to attack. + /// The number of troops that are going to defend. public bool Attack(Country attacker, Country defender, int num, int defender_num) { @@ -1039,6 +1167,12 @@ public bool Attack(Country attacker, Country defender, int num, int defender_num return true; } + /// + /// Transfer moves num troops from a country to another country. + /// + /// The country that is going to send the troops. + /// The country that is going to receive the troops. + /// The number of troops that are going to be sent. public void Transfer(Country from, Country to, int num) { from.ChangeTroops(-num); @@ -1048,6 +1182,9 @@ public void Transfer(Country from, Country to, int num) Killfeed.Update($"{turnPlayer.GetName()}: sent {num} troop(s) from {from.GetName()} to {to.GetName()}"); } + /// + /// NextTurn finds the next player that can take a turn and switches to them. + /// public void NextTurn() { if (this.turnPlayer.GetNumberOfOwnedCountries() == this.countryMap.Count) @@ -1078,6 +1215,9 @@ public void NextTurn() else EnableButtons(); } + /// + /// ResetTurn goes back to the first player's turn. + /// public void ResetTurn() { turnIndex = 0; @@ -1087,10 +1227,25 @@ public void ResetTurn() EnableButtons(); } + /// + /// GetTurnsName finds the name of the current player. + /// + /// + /// The name of the currently playing player. + /// public string GetTurnsName() => turnPlayer.GetName(); + /// + /// GetTurnsColor finds the color of the current player. + /// + /// + /// The color of the currently playing player. + /// public Color GetTurnsColor() => turnPlayer.GetColor(); + /// + /// EnableButtons allows the player to click all buttons on the screen when it is their turn. + /// private void EnableButtons() { foreach (var kvp in countryMap) @@ -1101,6 +1256,9 @@ private void EnableButtons() GameObject.Find("EndPhase").GetComponent