Exemple #1
0
    /// <summary>
    /// Used in conjunction with the Attack Panel: Once the player confirms their attack or fortification,
    /// AttackButton() calls this to transfer the selected number of troops from the 'attacker' territory
    /// to the 'defender' territory
    /// </summary>
    private void MoveTroops()
    {
        territoryConquered = false;
        int soldiers = (int)attackSlider.value;

        currentTerritory.AdjustSoldiers(-soldiers);
        defendingTerritory.AdjustSoldiers(soldiers);
        DeselectTerritory();


        if (defendingTerritory.GetContinent().CheckBonus(currentPlayersTurn))
        {
            defendingTerritory.GetContinent().UpdateBorderColour(GetCurrentPlayer().armyColour);
        }

        else
        {
            defendingTerritory.GetContinent().ResetBorderColour();
        }

        CloseAttackPanelButton();
    }
Exemple #2
0
    /// <summary>
    /// Flexible way of assigning a territory to a player. Will subtract 'soldierCount' from the player and initialize the territory appropriately
    /// </summary>
    /// <param name="annexedTerritory"> The territory to be assigned to the player. </param>
    /// <param name="playerId"> The player's index within currentPlayers[]. </param>
    /// <param name="soldierCount"> Optional: The number of soldiers to be transfered to the annexedTerritory. </param>
    private void ConquerTerritory(TerritoryNode annexedTerritory, int playerId, int soldierCount = 1)
    {
        if (soldierCount != 0)
        {
            annexedTerritory.AdjustSoldiers(soldierCount);                                // Add Soldiers to the territory
            currentPlayers[playerId].AddArmies(soldierCount * -1);                        // Remove Soldiers from the player's pool
        }

        currentPlayers[playerId].AddTerritory(annexedTerritory);                     // Give the player a reference to their new territory
        annexedTerritory.SetColor(currentPlayers[playerId].armyColour);              // Change colour of the territory to the player's colour

        // Remove the old player's ownership of the territory
        if (annexedTerritory.DisplayOwner() >= 0)
        {
            currentPlayers[annexedTerritory.DisplayOwner()].RemoveTerritory(annexedTerritory);
        }

        annexedTerritory.SetOwner(playerId);                                         // Give the territory their new owner's player ID
    }
Exemple #3
0
    // 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
    }