Example #1
0
    void LoadBoardFromID(string id)
    {
        currentBoardMaxWidth  = boardWidth;
        currentBoardMaxHeight = boardHeight;
        currentBoardMinWidth  = 0;
        currentBoardMinHeight = 0;

        scoreCount = 0;
        panelCurrentScore.SetActive(true);
        UpdateGUI_MovesCount();

        int x = 0;
        int y = 0;

        for (int i = 0; i < id.Length; ++i)
        {
            cards[x, y].ResetCard();
            if (id[i] == '0')
            {
                cards[x, y].SetBlack();
            }
            else
            {
                cards[x, y].SetWhite();
            }

            x++;

            if (x >= boardWidth)
            {
                x = 0;
                y++;
            }
        }

        UpdateGUI_BoardID();

        GameDataWWW.GetBoardInfo(id, true);

        GameLog.StartGame(id, boardWidth, boardHeight);

        gameEnded = false;
        isBusy    = false;

        panelScore.SetActive(false);
        panelBottom.SetActive(true);
        textBoardID.gameObject.SetActive(true);

        StartCoroutine(ResizeBorders(.5f));
    }
Example #2
0
    void Awake()
    {
        // if the singleton hasn't been initialized yet
        if (instance != null)
        {
            Destroy(this.gameObject);
            return;//Avoid doing anything else
        }

        if (instance == this)
        {
            return;
        }

        instance = this;
        DontDestroyOnLoad(this.gameObject);
    }
Example #3
0
    void Awake()
    {
        // if the singleton hasn't been initialized yet
        if (instance != null) {
            Destroy(this.gameObject);
            return;//Avoid doing anything else
        }

        if (instance == this) {
            return;
        }

        instance = this;
        DontDestroyOnLoad(this.gameObject);
    }
Example #4
0
    IEnumerator ResizeBorders(float waitTime = 0)
    {
        yield return(new WaitForSeconds(waitTime));

Init:
        for (int i = currentBoardMinWidth; i < currentBoardMaxWidth; ++i)
        {
            for (int j = currentBoardMinHeight; j < currentBoardMaxHeight; ++j)
            {
                if (cards[i, j].isBusy)
                {
                    yield return(new WaitForSeconds(waitTimeStep));

                    goto Init;
                }
            }
        }

        int ac;

        if (currentBoardMinHeight >= currentBoardMaxHeight || currentBoardMinWidth >= currentBoardMaxWidth)
        {
            goto EndGame;
        }

InitBottom:
        ac = 0;
        //BOTTOM LINE
        for (int i = currentBoardMinWidth; i < currentBoardMaxWidth; ++i)
        {
            if (!cards[i, currentBoardMinHeight].isBack)
            {
                break;
            }
            else
            {
                ac++;
            }
        }
        if (ac == (currentBoardMaxWidth - currentBoardMinWidth))
        {
            for (int i = currentBoardMinWidth; i < currentBoardMaxWidth; ++i)
            {
                cards[i, currentBoardMinHeight].HideCard();
            }
            currentBoardMinHeight++;
            if (currentBoardMinHeight >= currentBoardMaxHeight)
            {
                goto EndGame;
            }
            else
            {
                goto InitBottom;
            }
        }


InitTop:
        ac = 0;
        //TOP LINE
        for (int i = currentBoardMinWidth; i < currentBoardMaxWidth; ++i)
        {
            if (!cards[i, currentBoardMaxHeight - 1].isBack)
            {
                break;
            }
            else
            {
                ac++;
            }
        }
        if (ac == (currentBoardMaxWidth - currentBoardMinWidth))
        {
            for (int i = currentBoardMinWidth; i < currentBoardMaxWidth; ++i)
            {
                cards[i, currentBoardMaxHeight - 1].HideCard();
            }
            currentBoardMaxHeight--;
            if (currentBoardMaxHeight <= currentBoardMinHeight)
            {
                goto EndGame;
            }
            else
            {
                goto InitTop;
            }
        }

InitLeft:
        ac = 0;
        //LEFT COLUMN
        for (int i = currentBoardMinHeight; i < currentBoardMaxHeight; ++i)
        {
            if (!cards[currentBoardMinWidth, i].isBack)
            {
                break;
            }
            else
            {
                ac++;
            }
        }
        if (ac == (currentBoardMaxHeight - currentBoardMinHeight))
        {
            for (int i = currentBoardMinHeight; i < currentBoardMaxHeight; ++i)
            {
                cards[currentBoardMinWidth, i].HideCard();
            }
            currentBoardMinWidth++;
            if (currentBoardMinWidth >= currentBoardMaxWidth)
            {
                goto EndGame;
            }
            else
            {
                goto InitLeft;
            }
        }

InitRight:
        //RIGHT COLUMN
        ac = 0;
        for (int i = currentBoardMinHeight; i < currentBoardMaxHeight; ++i)
        {
            if (!cards[currentBoardMaxWidth - 1, i].isBack)
            {
                break;
            }
            else
            {
                ac++;
            }
        }
        if (ac == (currentBoardMaxHeight - currentBoardMinHeight))
        {
            for (int i = currentBoardMinHeight; i < currentBoardMaxHeight; ++i)
            {
                cards[currentBoardMaxWidth - 1, i].HideCard();
            }
            currentBoardMaxWidth--;
            if (currentBoardMaxWidth <= currentBoardMinWidth)
            {
                goto EndGame;
            }
            else
            {
                goto InitRight;
            }
        }

//		GameObject.Find("Text_Moves").GetComponent<Text>().text = "" +
//			 "Width[" + currentBoardMinWidth  + "," + currentBoardMaxWidth  + "]\n" +
//			"Height[" + currentBoardMinHeight + "," + currentBoardMaxHeight + "]\n";

        yield break;

EndGame:
        gameEnded = true;

        EndGame();

        GameLog.EndGame();
        GameDataWWW.UpdateBoardInfo(
            boardMatrix,
            scoreCount,
            GameLog.GetTime(),
            GameLog.GetMoves()
            );

        GameData.SaveBoard(boardLevel, boardID);


        textTimerCountdown.text = "Next In 5";
        if (retry)
        {
            goto EndFunc;
        }
        yield return(new WaitForSeconds(1));

        if (retry)
        {
            goto EndFunc;
        }
        textTimerCountdown.text = "Next In 4";
        yield return(new WaitForSeconds(1));

        if (retry)
        {
            goto EndFunc;
        }
        textTimerCountdown.text = "Next In 3";
        yield return(new WaitForSeconds(1));

        if (retry)
        {
            goto EndFunc;
        }
        textTimerCountdown.text = "Next In 2";
        yield return(new WaitForSeconds(1));

        if (retry)
        {
            goto EndFunc;
        }
        textTimerCountdown.text = "Next In 1";
        yield return(new WaitForSeconds(1));

        if (retry)
        {
            goto EndFunc;
        }
        textTimerCountdown.text = "Next\nIn 0";
        yield return(new WaitForSeconds(.2f));


        if (retry)
        {
            goto EndFunc;
        }
        else
        {
            if (isRandom)
            {
                GenerateRandomMatrix();
            }
            else
            {
                GenerateNextMatrix();
            }
        }

EndFunc:
        retry = false;
        yield break;
    }