/// <summary> /// When two cards are revealed, check if they are a match by comparing their ids. /// If the revealed card ids are the same, increment the score and continue the game /// unless all the cards are revealed, which means that the game ended. /// In that case update high score (if higher than previous saved one) and restart game. /// /// If not all the cards are revealed, reset first and second revealed cards so that the game can continue. /// /// If the revealed cards ids are not the same, unreveal cards and reset first and second /// revealed cards values so that the game can continue. /// /// If the current game level is 6 or higher, we keep track of his number of tries, and everytime /// the player chooses two cards that aren't a match and the number of tries goes above the available number /// of tries, the score will start to decrease. /// /// </summary> public IEnumerator CheckCardsMatch() { if (_firstRevealedCard.Id == _secondRevealedCard.Id) { _score++; ScoreLabel.text = "SCORE: " + _score; if (_score == _numberOfCards / 2) { LevelCompleted = true; _levelManager.UpdatePlayedTime(GameName, _timer.TargetTime); _levelManager.UpdateHighScore(GameName, _score); _levelManager.RestartGame(GameName); SetUIControllerSettings(); UIController.Completed(); } } else { if (_levelManager.GameLevel >= LevelManager.ConstantLevel && _numberOfTries >= _triesBeforeScoresDecreases) { _score--; ScoreLabel.text = "SCORE: " + _score; } yield return(new WaitForSeconds(0.5f)); _firstRevealedCard.UnrevealCard(); _secondRevealedCard.UnrevealCard(); } _firstRevealedCard = null; _secondRevealedCard = null; }
/// <summary> /// Set the clicked card as first or second revealed card. /// If the clicked card is the second revealed card check if the revealed cards are a match. /// /// Increase numberOfTries within every click -> used for level 6 and above. /// </summary> /// <param name="card">Revealed Clicked Card.</param> public void CanReveal(OriginalCard card) { _numberOfTries++; if (_firstRevealedCard == null) { _firstRevealedCard = card; } else { _secondRevealedCard = card; StartCoroutine(CheckCardsMatch()); } }