movePlayer() public method

Helper function - Actually moves the player
public movePlayer ( ) : void
return void
Beispiel #1
0
    /// <summary>
    /// Handles the results of a player clicking on the Action button.
    /// </summary>
    public void handleAction()
    {
        if (GUI.Button(actionRect, actionText))
        {
            if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_END)
            {
                return;
            }
            //don't do anythign after game ends

            if (gM.players.Count <= 1) //if there aren't enough players, the button should not do anything
            {
                return;
            }

            //start the game if there are enough players and a button is hit
            if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_SETUP)
            {
                gM.gameState.CurrentGameState = GameStateManager.GameState.GAME_PROSPECTING_STATE;
                if (gM.isOnline)
                {
                    gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentGameState + "/" + gM.ID);
                }
            }


            switch (gM.gameState.CurrentTurnState)
            {
            case GameStateManager.TurnState.TURN_ROLL:  // The player is choosing to roll

                gM.CurrentRoll = gM.Roll();             // roll the dice

                FeedbackGUI.setText("Please click on a space to move to. Double click to confirm, or click on the Action button.");

                gM.calculateMoveLocations();            // calculate where the player can move as a result of the dice roll

                // At the beginning, this bool is true - player can stay where he/she is by choosing not to roll.
                // Once the player rolls, he must move, so set this bool to false.
                showSkipButton = false;

                gM.gameState.CurrentTurnState = GameStateManager.TurnState.TURN_MOVE;     //move on to the next turn state
                if (gM.isOnline)
                {
                    gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID);
                }
                break;

            case GameStateManager.TurnState.TURN_MOVE:          // the player is moving after rolling the dice
                if (gM.pEnabled)
                {
                    if (gM.moves.Count > 1)
                    {
                        //after the player gets moved this is cleared, so if a stake is getting bumped and they click on the button again
                        //it won't try to move the player
                        clicker.movePlayer();
                    }

                    //if a stake doesn't need to be moved at all, or it it's already been taken care of
                    if (clicker.StakeOwnerIndex == -1 || clicker.MovedStake)
                    {
                        FeedbackGUI.setText("Please press a location to stake a claim on.");
                        gM.calculateStakes();                                                  // based on where the player has moved to, find the adjacent positions he/she can stake a claim

                        gM.gameState.CurrentTurnState = GameStateManager.TurnState.TURN_STAKE; //move on to the next turn state
                        if (gM.isOnline)
                        {
                            gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID);
                        }

                        clicker.StakeOwnerIndex = clicker.StakeIndex = -1;
                        clicker.MovedStake      = false;

                        Vector2 pos = gM.players[gM.CurrentPlayerIndex].Position;
                        clicker.TempCard = gM.board[(int)pos.x, (int)pos.y].GetComponent <Card>();    //reset to player's card
                    }
                    else
                    {
                        FeedbackGUI.setText("Please move your opponent's stake.");
                    }
                }
                else
                {
                    FeedbackGUI.setText("Once you roll you must move.");
                }

                break;

            case GameStateManager.TurnState.TURN_STAKE: //player is staking a claim after placing a marker

                if (gM.sEnabled)                        // make sure the player has actually placed a marker
                {                                       //sEnabled is set to true in clickHandler's stakeClick()
                      //clicker.selectedCard = false;

                    // Either move on or let the next player go
                    if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_MINING_STATE)
                    {
                        gM.gameState.CurrentTurnState = GameStateManager.TurnState.TURN_MINE;
                        if (gM.isOnline)
                        {
                            gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID);
                        }

                        showSkipButton = true;                  //the player can choose not to pick up a card this turn if he/she wants

                        //clear board and show new highlights
                        gM.clearHighlights();
                        gM.calculateMines();
                    }
                    else
                    {
                        gM.endTurn();
                    }
                }
                else
                {
                    if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_MINING_STATE)
                    {
                        FeedbackGUI.setText("Please stake a claim or press skip.");
                    }
                    else if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_PROSPECTING_STATE)
                    {
                        FeedbackGUI.setText("In the prospecting phase you must stake a claim.");
                    }
                }
                break;

            case GameStateManager.TurnState.TURN_MINE:
                Debug.Log("turn state: TURN_MINE");

                if (clicker.NumToMove == 0)
                {
                }
                else
                {
                    FeedbackGUI.setText("A player is in a dangerous mine! Please move them to solid ground.");
                    if (gM.players[clicker.indexToMove].Position != new Vector2(-1, -1))
                    {
                        Vector2 pos = gM.players[clicker.indexToMove].Position;
                        if (gM.isOnline)
                        {
                            gM.jsonFx.PerformUpdate("update_entity_pos/" + pos.x + "/" + pos.y + "/" + gM.players[clicker.indexToMove].ID);
                        }

                        clicker.NumToMove--;     //one less that needs to be looked at

                        //end the turn if all players are on valid spots now
                        if (clicker.NumToMove <= 0)
                        {
                            FeedbackGUI.setText("Good thing. It's safe now.");
                            gM.endTurn();
                        }
                        else
                        {
                            //someone isn't, find their index
                            for (int index = 0; index < gM.players.Count; index++)
                            {
                                if (gM.players[index].Position == new Vector2(-1, -1))
                                {
                                    clicker.indexToMove = index;
                                }
                            }
                        }
                    }
                }

                //endTurn();
                break;

            default: Debug.Log("whoops"); break;
            }
        }
    }