예제 #1
0
    private void OnMoveCompleted(MoveEvent _Move)
    {
        if (_Move.getSender() != GlobalVariables.userId)
        {
            Dictionary <string, object> _data = (Dictionary <string, object>)MiniJSON.Json.Deserialize(_Move.getMoveData());
            if (_data != null && _data.ContainsKey("Index"))
            {
                string _index = _data["Index"].ToString();
                GlobalEnums.MatchState _currentState = PlacementLogic(_index);
                if (_currentState == GlobalEnums.MatchState.Tie || _currentState == GlobalEnums.MatchState.Winner)
                {
                    WarpClient.GetInstance().stopGame();
                }
            }
        }

        startTime = Time.time;
        if (_Move.getNextTurn() == GlobalVariables.userId)
        {
            isMyTurn = true;
        }
        else
        {
            isMyTurn = false;
        }
    }
예제 #2
0
    private GlobalEnums.MatchState PlacementLogic(string _Index)
    {
        int row = (int)Char.GetNumericValue(_Index, 0);
        int col = (int)Char.GetNumericValue(_Index, 1);

        GlobalEnums.MatchState _currentState = GlobalEnums.MatchState.NoWinner;

        if (currBoard[row, col] == GlobalEnums.SlotState.Empty)
        {
            moveCounter++;
            currBoard[row, col] = currState;
            int tmp = row * 10 + col;
            unityObjects["Btn_Slot" + tmp].GetComponent <SC_Slot>().ChangeSlotState(currState);
            unityObjects["Btn_Slot" + tmp].GetComponent <Button>().interactable = false;
            if (row < 5)
            {
                unityObjects["Btn_Slot" + ((row + 1) * 10 + col)].GetComponent <Button>().interactable = true;
            }

            _currentState = IsMatchOver();
            if (_currentState == GlobalEnums.MatchState.Tie || _currentState == GlobalEnums.MatchState.Winner)
            {
                ChangeInteraction(false);
                unityObjects["PopUp_GameOver"].SetActive(true);
                unityObjects["Btn_PopUp_Restart"].GetComponent <Button>().interactable = false;
                if (_currentState == GlobalEnums.MatchState.Winner)
                {
                    if (currState == GlobalEnums.SlotState.Red)
                    {
                        unityObjects["Img_PopUp_Winner_CurrState"].GetComponent <Image>().sprite = Red;
                    }
                    else
                    {
                        unityObjects["Img_PopUp_Winner_CurrState"].GetComponent <Image>().sprite = Yellow;
                    }

                    unityObjects["Img_PopUp_Winner_CurrState"].GetComponent <Image>().enabled = true;
                    unityObjects["Txt_PopUp_Winner"].GetComponent <Text>().text = "The Winner is: ";
                }
                else
                {
                    unityObjects["Img_PopUp_Winner_CurrState"].GetComponent <Image>().enabled = false;
                    unityObjects["Txt_PopUp_Winner"].GetComponent <Text>().text = "The game is Tied";
                }
                gameStarted = false;
            }
            else
            {
                PassTurn();
            }

            if (GlobalVariables.curOpponent == GlobalEnums.Opponent.AI &&
                currState == GlobalEnums.SlotState.Red && _currentState == GlobalEnums.MatchState.NoWinner)
            {
                StartCoroutine(PlayAI());
            }
        }
        return(_currentState);
    }
예제 #3
0
    private GlobalEnums.MatchState PlacementLogic(int _Number)
    {
        GlobalEnums.MatchState _isOver = GlobalEnums.MatchState.NoWinner;
        Debug.Log("Btn_" + _Number);
        Debug.Log(curBoard[_Number - 1]);
        if (curBoard[_Number - 1] == GlobalEnums.SloState.Empty)
        {
            curBoard[_Number - 1] = curState;
            buttonObjects["Btn_" + _Number].GetComponent <SC_Slot>().ChangeSlotState(curState);
            clickedObjects.Add(_Number, buttonObjects["Btn_" + _Number]);
            buttonObjects["Btn_" + _Number].GetComponent <Button>().interactable = false;
            ChangeCircles(_Number);
            _isOver = IsMatchOver();
            textCounterObjects["Text_CounterBlack"].GetComponent <Text>().text = (blackCounter < 10) ? "0" + blackCounter : blackCounter.ToString();
            textCounterObjects["Text_CounterWhite"].GetComponent <Text>().text = (whiteCounter < 10) ? "0" + whiteCounter : whiteCounter.ToString();
            if (_isOver != GlobalEnums.MatchState.NoWinner)
            {
                Debug.Log("_isOver = " + _isOver);
                ChangeInteration();
                gameover["Screen_GameOver"].SetActive(true);
                if (_isOver == GlobalEnums.MatchState.Winner)
                {
                    if (blackCounter > whiteCounter)
                    {
                        gameover["Img_Winner"].GetComponent <Image>().sprite = tokenObjectBlack;
                    }
                    else
                    {
                        gameover["Img_Winner"].GetComponent <Image>().sprite = tokenObjectWhite;
                    }
                }
                else
                {
                    gameover["Img_Winner"].SetActive(false);
                    gameover["Text_Winner"].GetComponent <Text>().text = "No Winner / Tie";
                }
                gameStarted = false;
                textCounterObjects["Text_TurnTimer"].GetComponent <Text>().text = string.Empty;
            }
            OpenArea();
            PassTurn();

            if (GlobalVariables.curOpponent == GlobalEnums.Opponent.AI &&
                curState == GlobalEnums.SloState.White && _isOver == GlobalEnums.MatchState.NoWinner)
            {
                StartCoroutine(PlayAI());
            }
        }
        return(_isOver);
    }
예제 #4
0
    private void OnMoveCompleted(MoveEvent _Move)
    {
        startTimer = Time.time;
        if (_Move.getSender() != GlobalVariables.userID)
        {
            Dictionary <string, object> _data = (Dictionary <string, object>)MiniJSON.Json.Deserialize(_Move.getMoveData());

            if (_data != null && _data.ContainsKey("Index"))
            {
                if (_data.ContainsKey("Index"))
                {
                    int _index = int.Parse(_data["Index"].ToString());
                    if (_index > 0 && gameStarted)
                    {
                        GlobalEnums.MatchState _currState = PlacementLogic(_index);
                        if (_currState != GlobalEnums.MatchState.NoWinner)
                        {
                            gameStarted = false;
                        }
                    }
                    else if (_index < 0)
                    {
                        gameover["Screen_RestartQ"].SetActive(true);
                        WarpClient.GetInstance().stopGame();
                    }
                }
            }
            if (_Move.getNextTurn() == GlobalVariables.userID)
            {
                isMyTurn = true;
            }
            else
            {
                isMyTurn = false;
            }
        }
    }