/// <summary> /// Prepares the inputted territory to either defend or receive soldiers /// </summary> /// <param name="defender"> The territory to be attacked or fortified </param> private void SelectDefendingCountry(TerritoryNode defender) { defender.outline.color = Color.red; defendingCountry.text = defender.name; defendingSoldierCount.text = defender.DisplaySoldiers().ToString(); defendingTerritory = defender; defendingCol.color = currentPlayers[defendingTerritory.DisplayOwner()].armyColour; }
private void FixedUpdate() { if (!setup) { CheckPlayers(); } if (attackPanel.activeInHierarchy) { attackingSoldierCount.text = (currentTerritory.DisplaySoldiers() - (int)attackSlider.value).ToString(); if (currentPhase == TURN_PHASE.FORTIFY || territoryConquered) { defendingSoldierCount.text = (defendingTerritory.DisplaySoldiers() + (int)attackSlider.value).ToString(); } } }
/// <summary> /// Makes the inputted territory active after deactivating the last selected territory. /// This selected territory is now ready to interact with the player /// </summary> /// <param name="attacker"> The territory that will be either attacking enemy territories, or sending reinforcements</param> private void SelectActiveTerritory(TerritoryNode attacker) //Highlights the active Territory, before querrying it's adjacentTerritories. { DeselectTerritory(); attackingCountry.text = attacker.name; attackingSoldierCount.text = attacker.DisplaySoldiers().ToString(); switch (currentPhase) { case (TURN_PHASE.ATTACK): attacker.HighlightAdjacentTerritories(false); break; case (TURN_PHASE.FORTIFY): attacker.HighlightAdjacentTerritories(true); break; } currentTerritory = attacker; }
// Update is called once per frame void Update() { if (optionsSelected) //gameplay { if (!setup) { // Game Over - Display Winner and limit interacion if (activePlayers < 2) { //TODO : GAME OVER STUFF } // Main game loop - filtered by gamestate switch (currentPhase) { #region RECRUIT case TURN_PHASE.RECRUIT: // Beginning of round Initialization if (!didOnce) { reinforceUI.SetActive(true); attackUI.SetActive(false); fortifyUI.SetActive(false); CalculateReinforcements(currentPlayers[currentPlayersTurn]); didOnce = true; } // Entry point for input - left mouse button to interact if (Input.GetMouseButtonDown(0) && currentPlayersTurn != -1) { RaycastHit2D mouseCast2D = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition), 100, 1 << LayerMask.NameToLayer("Territory")); // Raycast mouse position, return hit on territory if (mouseCast2D) { // Deselect a territory that has been selected already if (currentTerritory) { currentTerritory.SetCurrentSelection(false); currentTerritory = null; } currentTerritory = mouseCast2D.rigidbody.GetComponent <TerritoryNode>(); // Set the current active territory to the one that was clicked if (currentPlayers[currentPlayersTurn].GetArmies() > 0 && currentTerritory.DisplayOwner() == currentPlayersTurn) { currentTerritory.SetCurrentSelection(true); currentTerritory.AdjustSoldiers(1); currentPlayers[currentPlayersTurn].AddArmies(-1); if (currentPlayers[currentPlayersTurn].GetArmies() == 0) { turnButton.SetActive(true); } } } } break; #endregion #region ATTACK case TURN_PHASE.ATTACK: // Beginning of Attack Phase Initialization if (!didOnce) { reinforceUI.SetActive(false); attackUI.SetActive(true); fortifyUI.SetActive(false); didOnce = true; } ResolveCombat(); if (territoryConquered) { attackButton.text = "Move"; attackSlider.maxValue = currentTerritory.DisplaySoldiers() - 1; attackDice.text = attackSlider.value.ToString(); if (!attackPanel.activeInHierarchy) { OpenAttackPanel(); } //Mouse Input while the attack options panel is closed } else if (Input.GetMouseButtonDown(0) && !attackPanel.activeInHierarchy && currentPlayersTurn != -1) { RaycastHit2D mouseCast2D = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition), 100, 1 << LayerMask.NameToLayer("Territory")); if (mouseCast2D) { TerritoryNode newTerritory = mouseCast2D.rigidbody.GetComponent <TerritoryNode>(); // clicked territory is a territory adjacent to selected player territory. if (newTerritory != currentTerritory && newTerritory.GetCurrentSelection()) { currentTerritory.DeselectAdjacentTerritories(); SelectDefendingCountry(newTerritory); attackSlider.minValue = 1; OpenAttackPanel(); //clicked territory is owned by the player and is eligible to attack } else if (newTerritory.DisplayOwner() == currentPlayersTurn && newTerritory.DisplaySoldiers() > 1) { SelectActiveTerritory(newTerritory); //clicked territory does not qualify as an attacking country or defending country } else { DeselectTerritory(); } } else { DeselectTerritory(); } } // Attack options panel/finalizing the attack. if (attackPanel.activeInHierarchy && !territoryConquered) { attackButton.text = "Attack!"; if (currentTerritory.DisplaySoldiers() > 3) { attackSlider.maxValue = 3; } else { attackSlider.maxValue = currentTerritory.DisplaySoldiers() - 1; } attackDice.text = attackSlider.value.ToString(); } break; #endregion #region FORTIFY case TURN_PHASE.FORTIFY: // Beginning of phase initialization if (!didOnce) { reinforceUI.SetActive(false); attackUI.SetActive(false); fortifyUI.SetActive(true); } //Mouse Input while the attack options panel is closed if (Input.GetMouseButtonDown(0) && !attackPanel.activeInHierarchy && currentPlayersTurn != -1 && !fortified) { RaycastHit2D mouseCast2D = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition), 100, 1 << LayerMask.NameToLayer("Territory")); if (mouseCast2D) { TerritoryNode newTerritory = mouseCast2D.rigidbody.GetComponent <TerritoryNode>(); // clicked territory is a territory adjacent to selected player territory. if (newTerritory != currentTerritory && newTerritory.GetCurrentSelection()) { currentTerritory.DeselectAdjacentTerritories(); SelectDefendingCountry(newTerritory); OpenAttackPanel(); } else if (newTerritory.DisplayOwner() == currentPlayersTurn && newTerritory.DisplaySoldiers() > 1) //clicked territory is owned by the player and is eligible to fortify another territory { DeselectTerritory(); SelectActiveTerritory(newTerritory); } else //clicked territory does not qualify as an attacking country or defending country { DeselectTerritory(); } } else { DeselectTerritory(); } } if (attackPanel.activeInHierarchy) //Fortify options panel. (repurposed attack options panel) { attackButton.text = "Fortify"; attackSlider.minValue = 1; attackSlider.maxValue = currentTerritory.DisplaySoldiers() - 1; attackDice.text = attackSlider.value.ToString(); } if (fortified) { NextTurnButton(); // Advance turn when all actions have been taken } break; #endregion default: Debug.Log("Its just a phase...."); break; } #region SETUP } else //Setup Phase -- Ends when all Players are out of soldiers to place { if (unclaimedTerritories <= 0) { allTsClaimed = true; phaseInfoTxt.text = "Reinforce claimed territories"; } if (Input.GetMouseButtonDown(0) && currentPlayersTurn != -1) //Mouse Input handling ( Click on Territory to place soldier) { RaycastHit2D mouseCast2D = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition), 100, 1 << LayerMask.NameToLayer("Territory")); if (mouseCast2D) { if (currentTerritory) { currentTerritory.SetCurrentSelection(false); } currentTerritory = mouseCast2D.rigidbody.GetComponent <TerritoryNode>(); // can only pick neutral territories until there are no more if (!allTsClaimed) { // Can only pick neutral territories - territories with owner set to -1 if (currentTerritory.DisplayOwner() < 0) { // Hide the populate button once the first territory has been selected if (debugPopulateButton.activeInHierarchy) { debugPopulateButton.SetActive(false); } currentTerritory.SetCurrentSelection(true); currentTerritory.AdjustSoldiers(1); currentPlayers[currentPlayersTurn].AddArmies(-1); currentPlayers[currentPlayersTurn].AddTerritory(currentTerritory); currentTerritory.SetColor(currentPlayers[currentPlayersTurn].armyColour); currentTerritory.SetOwner(currentPlayersTurn); unclaimedTerritories -= 1; if (currentTerritory.GetContinent().CheckBonus(currentPlayersTurn)) { currentTerritory.GetContinent().UpdateBorderColour(GetCurrentPlayer().armyColour); } AdvanceTurn(); } } else //can only click on owned territories to add soldiers //TODO: Add new graphic or text to show that all territories have been claimed, and the player must now only choose territories they own { if (currentTerritory.DisplayOwner() == currentPlayersTurn) { currentTerritory.SetCurrentSelection(true); currentTerritory.AdjustSoldiers(1); currentPlayers[currentPlayersTurn].AddArmies(-1); AdvanceTurn(); } } } //end of raycasts } // end of input if (currentPlayers[currentPlayersTurn].GetArmies() < 1) { setup = false; phaseInfoTxt.text = "Current Phase: "; } } //end of setup phase #endregion //Display Info int uITurnInfo = currentPlayersTurn + 1; turnInfo.text = "Player " + uITurnInfo + "'s Turn!"; turnInfoCol.color = currentPlayers[currentPlayersTurn].armyColour; border.color = currentPlayers[currentPlayersTurn].armyColour; } //end of gameplay }