예제 #1
0
 void Debugging()
 {
     DetectPossibleMoves.AnalyzeGrid();
 }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(0) || Input.GetMouseButton(0))
        {
            _canUpdateColor  = true;
            _canUpdateGrid   = true;
            _gatherColorTime = 0f;
        }

        // Set the color of the grid
        if (AnimateGrid.setGrid == false && _updateOnce == true)
        {
            //_gatherGridTime += Time.deltaTime;
            //if (_gatherGridTime > _waitTime)
            //_canUpdateGrid = false;

            AnimateGrid.SetGrid();
            AnimateGrid.setGrid = true;

            // Changel Text on Labels
            GameObject[] textLabels = GameObject.FindGameObjectsWithTag("ScoreText");
            // Set UI Text to objects to access
            //Debug.Log(objs.Length);
            foreach (var i in textLabels)
            {
                var t = i.GetComponent <Text>();
                if (t.name.Equals("HighScore"))
                {
                    if (SetColor.GetDarkMode() == true)
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                    else
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                }
                if (t.name.Equals("CurrentScore"))
                {
                    if (SetColor.GetDarkMode() == true)
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                    else
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                }
            }

            _updateOnce = false;
        }

        // Change colors to Light / Dark mode
        if (SetColor.WillChangeColor == true && _canUpdateColor == true)
        {
            _gatherColorTime += Time.deltaTime;
            if (_gatherColorTime > _waitTime)
            {
                _canUpdateColor = false;
            }

            UpdateColor();


            SetColor.WillChangeColor = false;
        }

        // Restart game
        if (GameOverInfo.RestartGame == true)
        {
            gameOverCanvas.SetActive(false);
            restartButton.SetActive(false);
            background.SetActive(false);
            GameOverInfo.RestartGame = false;
            AnimateGrid.setGrid      = false;
            SetColor.WillChangeColor = true;
            _updateOnce = true;

            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }

        // Check if Game Over
        if (DetectPossibleMoves.IsGameOver == true)
        {
            if (triggerOnce == true)
            {
                GameOver();

                //Debug.Log("Game Over");
                triggerOnce = false;
            }
        }
        else
        {
            if (!checkedAvaliablePieces || DetectPossibleMoves.DidNewBlocksSpawn)
            {
                DetectPossibleMoves.SetBooleans();

                DetectPossibleMoves.AnalyzeGrid();

                DetectPossibleMoves.IsThereAValidMove();

                checkedAvaliablePieces = true;
                GamePieces.HasAnGamePieceBeenPlayedToUpdateScore = true;
            }

            // Logic for the grid
            GamePieces.FindGameBlocks();
            GamePieces.FindGamePieces();
            GamePieces.WhereAreGamePiecesToPlay();
            AnimateGrid.FindBackgroundBlocks();

            /* If the left (main) mouse click is released
             * remove cleared blocks */
            if (Input.GetMouseButtonUp(0) || isMouseReleased)
            {
                if (GamePieces.isAPlayValid)
                {
                    GameGrid.UpdatePlayedPiecesOnGrid(this);
                }

                UpdateGameLogic();

                getRefresh      = true;
                isMouseReleased = false;

                UpdateAnimation();
            }

            if (GamePieces.isAPlayValid)
            {
                if (GamePieces.isAPlayValid)
                {
                    GameGrid.UpdatePlayedPiecesOnGrid(this);
                }

                checkedAvaliablePieces = false;
            }
        }
    }