예제 #1
0
    //one player play on one case tagged by its index
    public void PlayerMove(Board.ePlayer player, int index)
    {
        if (m_Winner != ePlayer.eNone)
        {
            return;
        }

        m_BoardState[index] = player;
        ePlayer nextturn = (ePlayer)(((int)m_CurrentTurn + 1) % 2);

        m_CurrentTurn = nextturn;
        //check win
        CheckWinner();

        if (m_Winner != ePlayer.eNone)
        {
            Console.Out.WriteLine("winner");
        }
    }
    //Main rendering function
    void OnGUI()
    {
        // Render out the blank background
        GUI.Label(new Rect(0, 0, 320, 480), new GUIContent(m_BackGround));

        //if game as not start, do nothing
        if (m_Board.GetCurrentTurnPlayer() == Board.ePlayer.eNone)
        {
            return;
        }

        //if winner, just render the board as labels, and flash winner line
        if (m_Board.GetWinner() != Board.ePlayer.eNone)
        {
            bool hideflash = m_FlashTime >= m_FlashDelay;
            for (int istate = 0; istate < m_Board.GetBoard().Length; ++istate)
            {
                //compute cell position
                int xPos = m_xOffset + istate % 3 * m_BoardButtonWidth + istate % 3 * m_xSpacing;
                int yPos = m_yOffset + istate / 3 * m_BoardButtonHeight + istate / 3 * m_ySpacing;

                bool hide = false; //show cell by default
                if (istate == m_Board.GetWinningLine()[0] || istate == m_Board.GetWinningLine()[1] || istate == m_Board.GetWinningLine()[2])
                {
                    hide = hideflash; //hide only if this cell is on winner liner, and flashing
                }

                Board.ePlayer state = m_Board.GetBoard()[istate];
                //render cell
                if (state != Board.ePlayer.eNone && !hide)
                {
                    GUI.Label(new Rect(xPos, yPos, m_BoardButtonWidth, m_BoardButtonHeight), m_BoardButtons[(int)state]);
                }
            }
            return;
        }

        ///in game //////////////////////////////////

        //render owner of current turn;
        float smallbtnwidth  = m_BoardButtonWidth / 2;
        float smallbtnheight = m_BoardButtonHeight / 2;

        GUI.Label(new Rect(m_BackGround.width / 2 - smallbtnwidth / 2, 36 - smallbtnheight / 2, smallbtnwidth, smallbtnheight), m_BoardButtons[(int)m_Board.GetCurrentTurnPlayer()]);


        //render board
        for (int istate = 0; istate < m_Board.GetBoard().Length; ++istate)
        {
            //compute cell position
            int xPos = m_xOffset + istate % 3 * m_BoardButtonWidth + istate % 3 * m_xSpacing;
            int yPos = m_yOffset + istate / 3 * m_BoardButtonHeight + istate / 3 * m_ySpacing;

            Board.ePlayer state = m_Board.GetBoard()[istate];
            //render as button if empty
            if (state == Board.ePlayer.eNone)
            {
                //if the current player clic on this cell, mark the cell state as his own, and switch turn
                if (GUI.Button(new Rect(xPos, yPos, m_BoardButtonWidth, m_BoardButtonHeight), GUIContent.none, m_style))
                {
                    //if it's not my turn, do nothing
                    if (OnlineManager.Instance.IsHost() && m_Board.GetCurrentTurnPlayer() == Board.ePlayer.eCircle ||
                        !OnlineManager.Instance.IsHost() && m_Board.GetCurrentTurnPlayer() == Board.ePlayer.eCross)
                    {
                        SendPlayerMove((int)m_Board.GetCurrentTurnPlayer(), istate);
                        m_Board.PlayerMove(istate);
                    }
                }
            }
            //or as label
            else
            {
                GUI.Label(new Rect(xPos, yPos, m_BoardButtonWidth, m_BoardButtonHeight), m_BoardButtons[(int)state]);
            }
        }
    }
예제 #3
0
    //Main rendering function
    void OnGUI()
    {
        //aply custom skin
        GUI.skin = m_CustomGUISkin;

        // Render out the blank background
        GUI.Label(new Rect(0, 0, 320, 480), new GUIContent(m_BackGround));

        //if game as not start, do nothing
        if (m_Network.Board.GetCurrentTurnPlayer() == Board.ePlayer.eNone)
        {
            return;
        }

        //if winner, just render the board as labels, and flash winner line
        if (m_Network.Board.GetWinner() != Board.ePlayer.eNone)
        {
            bool hideflash = m_FlashTime >= m_FlashDelay;
            for (int istate = 0; istate < m_Network.Board.GetBoard().Length; ++istate)
            {
                //compute cell position
                int xPos = m_xOffset + istate % 3 * m_BoardButtonWidth + istate % 3 * m_xSpacing;
                int yPos = m_yOffset + istate / 3 * m_BoardButtonHeight + istate / 3 * m_ySpacing;

                bool hide = false; //show cell by default
                if (istate == m_Network.Board.GetWinningLine()[0] || istate == m_Network.Board.GetWinningLine()[1] || istate == m_Network.Board.GetWinningLine()[2])
                {
                    hide = hideflash; //hide only if this cell is on winner liner, and flashing
                }

                Board.ePlayer state = m_Network.Board.GetBoard()[istate];
                //render cell
                if (state != Board.ePlayer.eNone && !hide)
                {
                    GUI.Label(new Rect(xPos, yPos, m_BoardButtonWidth, m_BoardButtonHeight), m_BoardButtons[(int)state]);
                }
            }
            return;
        }

        ///in game //////////////////////////////////

        //render owner of current turn;
        float smallbtnwidth  = m_BoardButtonWidth / 2;
        float smallbtnheight = m_BoardButtonHeight / 2;

        GUI.Label(new Rect(m_BackGround.width / 2 - smallbtnwidth / 2, 36 - smallbtnheight / 2, smallbtnwidth, smallbtnheight), m_BoardButtons[(int)m_Network.Board.GetCurrentTurnPlayer()]);


        //render board
        for (int istate = 0; istate < m_Network.Board.GetBoard().Length; ++istate)
        {
            //compute cell position
            int xPos = m_xOffset + istate % 3 * m_BoardButtonWidth + istate % 3 * m_xSpacing;
            int yPos = m_yOffset + istate / 3 * m_BoardButtonHeight + istate / 3 * m_ySpacing;

            Board.ePlayer state = m_Network.Board.GetBoard()[istate];
            //render as button if empty
            if (state == Board.ePlayer.eNone)
            {
                //if the current player clic on this cell, mark the cell state as his own, and switch turn
                if (GUI.Button(new Rect(xPos, yPos, m_BoardButtonWidth, m_BoardButtonHeight), GUIContent.none))
                {
                    //HERE >>>.<<<
                    //You probably have to put some code here since clicking does nothing right now
                }
            }
            //or as label
            else
            {
                GUI.Label(new Rect(xPos, yPos, m_BoardButtonWidth, m_BoardButtonHeight), m_BoardButtons[(int)state]);
            }
        }
    }