public static List <int> UpdateGameGrid(GameGridModel grid) { var cardsFacingUp = grid.cards.FindAll(x => (x.state == ECardState.FaceUp)); var updatedCardsIndex = new List <int>(); if (cardsFacingUp.Count < 2) { cardsFacingUp.Clear(); return(updatedCardsIndex); } bool match = true; for (int i = 0; i < cardsFacingUp.Count - 1; i++) { if (cardsFacingUp[i].content != cardsFacingUp[i + 1].content) { match = false; break; } } for (int i = 0; i < cardsFacingUp.Count; i++) { cardsFacingUp[i].state = (match) ? ECardState.Eliminated : ECardState.FaceDown; updatedCardsIndex.Add(grid.cards.IndexOf(cardsFacingUp[i])); } return(updatedCardsIndex); }
private void VictoryConditionMetHandler() { _timer.StopCountdown(); Popup.Instance.ShowPopup("Victory!", "Congratulations! You have Won!", "Play Again", delegate { gridModel = GameGridModel.GenerateRandomGrid(); Popup.Instance.HidePopup(); Start(); }); }
private IEnumerator GameTick(float waitTime) { _onGameTickScheduled.Invoke(); yield return(new WaitForSeconds(waitTime)); List <int> updatedCards = GameGridModel.UpdateGameGrid(gridModel); for (int i = 0; i < updatedCards.Count; i++) { ECardState newState = gridModel.cards[updatedCards[i]].state; gridView.SetCardState(updatedCards[i], newState); if (newState == ECardState.Eliminated) { _score += setting.eliminationScorePoints; } } _onGameTickPerformed.Invoke(); _tickRoutine = null; }