// Use this for initialization
    void Start()
    {
        playerData = PlayerData.GetInstance();
        gameInfo   = GameInfo.GetInstance();

        GameObject currentMarker;

        switch (gameInfo.GetLatestWinner())
        {
        case GameOutcome.Tie:
            m_BackgroundColorGoTo = new Color
                                    (
                ExtendedFunctions.Convert8ToFloat(50),
                ExtendedFunctions.Convert8ToFloat(50),
                ExtendedFunctions.Convert8ToFloat(50)
                                    );

            m_congratsMessage.text = "TIE GAME!";

            break;

        case GameOutcome.PlayerWon:

            currentMarker = GetMarker(gameInfo.GetPlayerMarker());

            m_BackgroundColorGoTo = ExtendedFunctions.GetColorOfGameObject(currentMarker);

            SetupMarkerDisplay(currentMarker);

            m_congratsMessage.text = "YOU WON!";

            break;

        case GameOutcome.AIWon:

            currentMarker = GetMarker(gameInfo.GetAIMarker());

            m_BackgroundColorGoTo = ExtendedFunctions.GetColorOfGameObject(currentMarker);

            SetupMarkerDisplay(currentMarker);

            m_congratsMessage.text = "YOU LOSS!";

            break;
        }

        m_statsTitle.text = playerData.ActiveSave.m_saveName + "'s stats";

        m_winStats.text = "Total wins\n" + playerData.ActiveSave.m_TotalWins;

        m_lossStats.text = "Total losses\n" + playerData.ActiveSave.m_TotalLosses;
    }
Пример #2
0
    /// <summary>
    /// Game loop
    /// </summary>
    /// <returns></returns>
    IEnumerator GameLoop()
    {
        // Delay start for wipe animation
        yield return(new WaitForSeconds(0.5f));

        int player = GI.GetPlayerFirst() ? 1 : 2;

        for (m_turns = 0; m_turns < 9 && Win(m_board) == 0; ++m_turns)
        {
            m_TurnText.text = "Turns: " + m_turns.ToString();

            if ((m_turns + player) % 2 == 0)
            {
                Debug.Log("Computer's turn!");
                currentTurnMove = TurnMode.AIMove;
                UpdateTurnVisual();
                m_BackgroundColorGoTo = GetMarkerColor(AIMarker);

                yield return(new WaitForSeconds(m_AITurnDuration));

                ComputerMove(m_board);
                Debug.Log("Computer has made their turn!");
                UpdateBoardVisuals();
            }
            else
            {
                Debug.Log("Player's turn!");
                currentTurnMove = TurnMode.PlayerMove;
                UpdateTurnVisual();
                m_BackgroundColorGoTo = GetMarkerColor(playerMarker);

                yield return(new WaitUntil(() => m_turnOver));

                Debug.Log("Player has made their turn!");
                UpdateBoardVisuals();
            }

            m_turnOver = false;
        }

        currentTurnMove = TurnMode.GameOver;

        yield return(new WaitForSeconds(1));

        switch (Win(m_board).ToInt())
        {
        case 0:
            Debug.Log("A draw. How droll.\n");
            m_BackgroundColorGoTo = Color.black;
            UpdateText("Tie game!",
                       new Color(
                           ExtendedFunctions.Convert8ToFloat(50.0f),
                           ExtendedFunctions.Convert8ToFloat(50.0f),
                           ExtendedFunctions.Convert8ToFloat(50.0f)
                           )
                       );

            GI.SetLatestWinner(GameOutcome.Tie);

            break;

        case 1:
            Debug.Log("You lose.\n");
            WinVisual(m_WinPositions);
            UpdateText("AI won!", GetMarkerColor(AIMarker));
            LoseState();
            break;

        case -1:
            Debug.Log("You win.\n");
            WinVisual(m_WinPositions);
            UpdateText("You win!", GetMarkerColor(playerMarker));
            WinState();
            break;
        }

        yield return(new WaitForSeconds(1.0f));

        m_WhiteWipe.SetTrigger("WipeIn");
    }