예제 #1
0
    void OnMouseDown()
    {
        if (GlobalScript.Instance.isInputPaused)
        {
            return;
        }

        if (GetGUIManagerScript().isEmoteScreen)
        {
            return;
        }

        if (GetBoardScript().gameMode == Defines.GAMEMODE.AI &&
            GetTurnHandler().turn == GameObject.FindGameObjectWithTag("AIMiniMax").GetComponent <AIMiniMax>().AITurn)
        {
            if (gridState == 0)
            {
                PlaceOnGrid(4);
            }
            return;
        }

        if (GetBoardScript().gameMode == Defines.GAMEMODE.ONLINE &&
            ((NetworkManager.IsPlayerOne() && GetTurnHandler().turn != Defines.TURN.P1) ||
             (!NetworkManager.IsPlayerOne() && GetTurnHandler().turn != Defines.TURN.P2)))
        {
            if (gridState == 0)
            {
                PlaceOnGrid(4);
            }
            return;
        }

        //if(Input.touchCount != 1)
        //	return;

        // Don't do anything if the big grid is already won, or game hasn't started/has ended, or game is paused.
        if (parentGrid.GetComponent <BigGridScript>().gridWinner != 0 ||
            GetTurnHandler().turn == Defines.TURN.NOTSTARTED ||
            GetTurnHandler().turn == Defines.TURN.GAMEOVER ||
            GetGUIManagerScript().GUIEmoteScreen.GetActive() ||
            GetTurnHandler().pausedState != 0 ||
            GetTurnHandler().turn == Defines.TURN.DISCONNECTED)
        {
            return;
        }


        // Special Case: Tutorials
        if (TutorialScript.Instance.isTutorial)
        {
            if ((TutorialScript.Instance.tStage == TUTORIALSTAGE.PLACE_TOPLEFT_P) ||
                TutorialScript.Instance.tStage == TUTORIALSTAGE.ICON_HIGHLIGHTED)
            {
                if (GetBoardScript().activeBigGrid == 0 && gridID == 5 && parentGrid.GetComponent <BigGridScript>().bigGridID == 0)
                {
                    if (gridState == 0)
                    {
                        HighlightGrid();
                        TutorialScript.Instance.tStage = TUTORIALSTAGE.ICON_HIGHLIGHTED;
                    }
                    else if (gridState == 3)
                    {
                        ConfirmPlacement();
                        TutorialScript.Instance.tStage = TUTORIALSTAGE.OPPONENT_TURN1;
                    }
                }
                else
                {
                    if (gridState == 0)
                    {
                        TutorialScript.Instance.tStage = TUTORIALSTAGE.PLACE_TOPLEFT_P;
                        PlaceOnGrid(4);
                    }
                }
            }

            else if (TutorialScript.Instance.tStage == TUTORIALSTAGE.PLACE_BOTLEFT)
            {
                if (GetBoardScript().activeBigGrid == 6 && gridID == 2 && parentGrid.GetComponent <BigGridScript>().bigGridID == 6)
                {
                    if (gridState == 0)
                    {
                        HighlightGrid();
                    }
                    else if (gridState == 3)
                    {
                        ConfirmPlacement();
                        TutorialScript.Instance.tStage = TUTORIALSTAGE.OPPONENT_TURN2;
                    }
                }
                else
                {
                    if (gridState == 0)
                    {
                        PlaceOnGrid(4);
                    }
                }
            }

            else if (TutorialScript.Instance.tStage == TUTORIALSTAGE.PLACE_BOTRIGHT_P2)
            {
                if (GetBoardScript().activeBigGrid == 10 && gridID == 1 && parentGrid.GetComponent <BigGridScript>().bigGridID == 8)
                {
                    if (gridState == 0)
                    {
                        HighlightGrid();
                    }
                    else if (gridState == 3)
                    {
                        ConfirmPlacement();
                        TutorialScript.Instance.tStage = TUTORIALSTAGE.WIN;
                    }
                }
                else
                {
                    if (gridState == 0)
                    {
                        PlaceOnGrid(4);
                    }
                }
            }
        }

        // Check if node belongs to the activeGrid
        else
        {
            if (GetBoardScript().activeBigGrid == parentGrid.GetComponent <BigGridScript>().bigGridID ||
                GetBoardScript().activeBigGrid == 10)
            {
                // Highlight grid
                if (gridState == 0)
                {
                    if (GetBoardScript().gameMode == Defines.GAMEMODE.ONLINE)
                    {
                        NetworkGameLogic networkLogic = NetworkGameLogic.GetNetworkGameLogic();
                        networkLogic.HighlightGrid(parentGrid.GetComponent <BigGridScript>().bigGridID, gridID);
                    }
                    else
                    {
                        HighlightGrid();
                    }
                }

                // Only allowed if grid is highlighted
                else if (gridState == 3)
                {
                    if (GetBoardScript().gameMode == Defines.GAMEMODE.ONLINE)
                    {
                        NetworkGameLogic networkLogic = NetworkGameLogic.GetNetworkGameLogic();
                        networkLogic.ConfirmPlacement(parentGrid.GetComponent <BigGridScript>().bigGridID, gridID,
                                                      NetworkManager.IsPlayerOne() ? Defines.TURN.P1 : Defines.TURN.P2,
                                                      NetworkManager.IsPlayerOne() ? GetGUIManagerScript().timerP1 : GetGUIManagerScript().timerP2);

                        // Player is acting like server
                        if (NetworkManager.IsPlayerOne())
                        {
                            ConfirmPlacement();
                        }
                    }
                    else
                    {
                        ConfirmPlacement();
                    }
                }
            }
            else
            {
                if (gridState == 0)
                {
                    PlaceOnGrid(4);                     // Current grid is invalid (red)
                }
            }
        }
    }
예제 #2
0
    void OnMouseDown()
    {
        if (GetBoardScript().gameMode == Defines.GAMEMODE.AI &&
            GetTurnHandler().turn == GameObject.FindGameObjectWithTag("AIMiniMax").GetComponent <AIMiniMax>().AITurn)
        {
            return;
        }
        if (GetBoardScript().gameMode == Defines.GAMEMODE.ONLINE &&
            ((NetworkManager.IsPlayerOne() && GetTurnHandler().turn != Defines.TURN.P1) ||
             (!NetworkManager.IsPlayerOne() && GetTurnHandler().turn != Defines.TURN.P2)))
        {
            return;
        }

        //if(Input.touchCount != 1)
        //	return;

        // Don't do anything if the big grid is already won, or game hasn't started/has ended, or game is paused.
        if (parentGrid.GetComponent <BigGridScript>().gridWinner != 0 ||
            GetTurnHandler().turn == Defines.TURN.NOTSTARTED ||
            GetTurnHandler().turn == Defines.TURN.GAMEOVER ||
            GetTurnHandler().pausedState != 0)
        {
            return;
        }

        // Check if node belongs to the activeGrid
        if (GetBoardScript().activeBigGrid == parentGrid.GetComponent <BigGridScript>().bigGridID ||
            GetBoardScript().activeBigGrid == 10)
        {
            // Highlight grid
            if (gridState == 0)
            {
                if (GetBoardScript().gameMode == Defines.GAMEMODE.ONLINE)
                {
                    NetworkGameLogic networkLogic = NetworkGameLogic.GetNetworkGameLogic();
                    networkLogic.HighlightGrid(parentGrid.GetComponent <BigGridScript>().bigGridID, gridID);
                }
                else
                {
                    HighlightGrid();
                }
            }

            // Only allowed if grid is highlighted
            else if (gridState == 3)
            {
                if (GetBoardScript().gameMode == Defines.GAMEMODE.ONLINE)
                {
                    NetworkGameLogic networkLogic = NetworkGameLogic.GetNetworkGameLogic();
                    networkLogic.ConfirmPlacement(parentGrid.GetComponent <BigGridScript>().bigGridID, gridID,
                                                  NetworkManager.IsPlayerOne() ? Defines.TURN.P1 : Defines.TURN.P2,
                                                  NetworkManager.IsPlayerOne() ? GetGUIManagerScript().timerP1 : GetGUIManagerScript().timerP2);
                }
                else
                {
                    ConfirmPlacement();
                }
            }
        }
    }