Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(0) || Input.GetMouseButton(0))
        {
            _runUpdate       = true;
            _gatherScoreTime = 0f;
        }

        if (_runUpdate == true)
        {
            _gatherScoreTime += Time.deltaTime;
            if (_gatherScoreTime > _waitTime)
            {
                _gatherScoreTime = 0f;
                _runUpdate       = false;
            }

            if (DetectPossibleMoves.IsGameOver == true)
            {
                // Condenced game update score below for game over text w/o animation
                totalScoreText.text = PlayedScore.ToString();
                int diff             = TotalScore - PlayedScore;
                int loops            = 10;
                int valueToIncrement = diff / loops;
                int temp             = PlayedScore + valueToIncrement;
                totalScoreText.text     = temp.ToString();
                GameOverInfo.totalScore = temp;

                TotalScore = temp;
            }
            else
            {
                if (GamePieces.CountGameBlocksOutsideGrid() != outsidePieces)
                {
                    previous1     = outsidePieces;
                    outsidePieces = GamePieces.CountGameBlocksOutsideGrid();
                }

                if (GamePieces.HasAnGamePieceBeenPlayedToUpdateScore == true)
                {
                    isThereValidMoves = DetectPossibleMoves.IsThereAValidMove();

                    GamePieces.HasAnGamePieceBeenPlayedToUpdateScore = false;

                    previous3 = previous2;
                    previous2 = outsidePieces;
                    if (previous3 != 0)
                    {
                        blockPlayed = Math.Abs(previous2 - previous3);
                        //Debug.Log(blockPlayed);

                        // Adjust score
                        int max = Math.Max(PlayedScore, TotalScore);
                        PlayedScore = max;
                        TotalScore  = max;

                        // Update scores on played & total
                        PlayedScore += blockPlayed;
                        TotalScore  += blockPlayed;

                        // If rows were cleared, add them to total score & played score when complete
                        int clear = GameGrid.howManyRowsColsWereFilled;
                        if (clear > 0)
                        {
                            GetRowsClears(GameGrid.howManyRowsColsWereFilled);
                        }
                        GameGrid.howManyRowsColsWereFilled = 0;

                        //PrintScore();
                        UpdateScore();
                    }

                    //Debug.Log(previous1 + " , " + previous2 + " , " + previous3);


                    //int blocksPlayed =
                }

                if (!isThereValidMoves && !saved)
                {
                    if (TotalScore > HighScore)
                    {
                        SaveData.SetHighScore(TotalScore, HighScore);
                        SavedData data = new SavedData();
                        data.Save(SaveData);
                    }

                    //Debug.Log("Game Over");
                    DetectPossibleMoves.IsGameOver = true;

                    saved = true;
                }
            }
        }
    }
Esempio n. 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;
            }
        }
    }