示例#1
0
    public void InitializeTerritoryCard(TerritoryNode newTerritory, int newArmy)
    {
        //TerritoryInformation
        SetTerritory(newTerritory);
        GetTerritory().SetColor(newTerritory.GetTerritoryColor());
        territoryName        = newTerritory.gameObject.name;
        territoryNameOb.text = territoryName;
        sprTerritory.sprite  = newTerritory.GetSpriteRenderer().sprite;



        switch (newArmy)
        {
        //INFANTRY
        case 1:

            break;

        //CAVALRY
        case 2:


            break;

        //ARTILLERY
        case 3:

            break;
        }
    }
示例#2
0
 /// <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;
 }
示例#3
0
    /// <summary>
    /// Used at the beginning of the game to shuffle the territories and distribute them randomly to each player active in the game
    /// </summary>
    public void DebugPopulateTerritories()
    {
        System.Random rng = new System.Random();
        int           n   = unclaimedTerritories;

        TerritoryNode[] shuffledTerritories = allTerritories;

        debugPopulateButton.SetActive(false);

        // Shuffle All the territories
        while (n > 1)
        {
            n--;
            int k = rng.Next(n + 1);

            TerritoryNode terry = shuffledTerritories[k];
            shuffledTerritories[k] = shuffledTerritories[n];
            shuffledTerritories[n] = terry;
        }


        // Distribute the territories in order to each active player
        int i = 0;

        n = unclaimedTerritories;
        while (i < n)
        {
            for (int j = 0; j < activePlayers; j++)
            {
                TerritoryNode terry = shuffledTerritories[i];

                terry.SetCurrentSelection(true);
                ConquerTerritory(terry, j);
                terry.SetCurrentSelection(false);
                unclaimedTerritories--;
                i++;

                if (i >= n)
                {
                    currentPlayersTurn = j;                           // set player's turn to the last player to place an army before advancing
                    break;
                }
            }
        }

        AdvanceTurn();
    }
示例#4
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
    }
示例#5
0
    /// <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;
    }
示例#6
0
 public void RemoveTerritory(TerritoryNode terry)
 {
     currentTerritories.Remove(terry);
 }
示例#7
0
 public void AddTerritory(TerritoryNode terry)
 {
     currentTerritories.Add(terry);
 }
示例#8
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
    }
示例#9
0
 public void SetTerritory(TerritoryNode terry)
 {
     territory = terry;
 }