Example #1
0
    private void UpdateScore()
    {
        // Init score play update

        totalScoreText.text     = PlayedScore.ToString();
        GameOverInfo.totalScore = PlayedScore;


        // 10 updates to get total score

        int diff = TotalScore - PlayedScore;

        //TotalScore = PlayedScore;

        // Run total score animation if row is cleared
        if (diff > 0)
        {
            StartCoroutine(Delay(diff).GetEnumerator());
        }
    }
Example #2
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;
                }
            }
        }
    }