Пример #1
0
    public void HotSeatGameLogic()
    {
        if (instantiationFlag)
        {
            gameBoard         = GameObject.FindWithTag("Board").GetComponent("GameBoard") as GameBoard;
            instantiationFlag = false;
        }
        else if (turn.currentTurnState == (int)TurnState.States.Player1)
        {
            mouseClick      = MouseClickToTileCoords();
            mouseClickInRWC = new Vector3(mouseClick.x * spacing, 1.0f, mouseClick.y * spacing);
            if (mouseClick != noClick && !gameBoard.SpaceTaken(mouseClick))
            {
                gameBoard.TakeSpace(mouseClick);
                Instantiate(TTT_X, mouseClickInRWC, Quaternion.identity);
                turn.NextTurn();
            }
        }
        else if (turn.currentTurnState == (int)TurnState.States.Player2)
        {
            mouseClick      = MouseClickToTileCoords();
            mouseClickInRWC = new Vector3(mouseClick.x * spacing, 1.0f, mouseClick.y * spacing);
            if (mouseClick != noClick && !gameBoard.SpaceTaken(mouseClick))
            {
                gameBoard.TakeSpace(mouseClick);
                Instantiate(TTT_O, mouseClickInRWC, Quaternion.identity);
                turn.NextTurn();
            }
        }

        if (gameBoard != null && gameBoard.ReturnWinner() != 0 && turn.currentTurnState != (int)TurnState.States.Menu &&
            turn.currentTurnState != (int)TurnState.States.Start && turn.currentTurnState != (int)TurnState.States.End)
        {
            Debug.Log("Winner found, game set to end");
            winner = gameBoard.ReturnWinner();
            if (winner == (int)GameBoard.SpaceStatus.X)
            {
                p1Wins++;
            }
            else if (winner == (int)GameBoard.SpaceStatus.O)
            {
                p2Wins++;
            }

            turn.EndGame();
        }

        if (gameBoard != null && gameBoard.BoardFull() && turn.currentTurnState != (int)TurnState.States.End && turn.currentTurnState != (int)TurnState.States.Menu)
        {
            Debug.Log("Board is full, game set to end");
            draws++;
            turn.EndGame();
        }
    }