/// <summary>
        /// Action of Undo all decks/cards states.
        /// </summary>
        public void Undo()
        {
            if (StatesData.States.Count > 0)
            {
                //if undos are countable and there are undos to be used, subtract the undo and update the text
                if (IsCountable && _availableUndoCounts > 0)
                {
                    _availableUndoCounts--;
                    gameUndoCount++;
                    _undoAvailableCountsText.text = _availableUndoCounts.ToString();
                }
                //else if undos are countable and there are no remaining undos, trigger an ad to reset the undo count
                else if (IsCountable && _availableUndoCounts == 0)
                {
                    //_gameMgrComponent.OnClickGetUndoAdsBtn();

                    //if the Player doesn't have any more undos, trigger an ad to get more
                    if (_adsComponent.adsActive == true)
                    {
                        _adsComponent.ShowAd("refillUndos");

                        return;
                    }
                    else
                    {
                        return;
                    }
                }

                _hintComponent.IsHintWasUsed        = false;
                _cardLogicComponent.IsNeedResetPack = false;

                //go through each card in the alldeckarray(master of all cards)
                for (int i = 0; i < _cardLogicComponent.AllDeckArray.Length; i++)
                {
                    //_cardLogicComponent.faceDownCardsCount = 0;

                    //assign deck to the all deck array, so all cards
                    Deck deck = _cardLogicComponent.AllDeckArray[i];
                    //assign the deck record to the current state -1, so the previous state
                    DeckRecord deckRecord = StatesData.States[StatesData.States.Count - 1].DecksRecord[i];
                    //assign deck's card list to the deckRecord cards list of the previous state
                    deck.CardsArray = new List <Card>(deckRecord.Cards);

                    for (int j = 0; j < deckRecord.CardsRecord.Count; j++)
                    {
                        Card       card       = deck.CardsArray[j];
                        CardRecord cardRecord = deckRecord.CardsRecord[j];

                        card.CardType                = cardRecord.CardType;
                        card.CardNumber              = cardRecord.CardNumber;
                        card.Number                  = cardRecord.Number;
                        card.CardStatus              = cardRecord.CardStatus;
                        card.CardColor               = cardRecord.CardColor;
                        card.IsDraggable             = cardRecord.IsDraggable;
                        card.IndexZ                  = cardRecord.IndexZ;
                        card.Deck                    = cardRecord.Deck;
                        card.transform.localPosition = cardRecord.Position;
                        card.transform.SetSiblingIndex(cardRecord.SiblingIndex);
                        card.isFaceDown = cardRecord.IsFaceDown;

                        //if (card.isFaceDown == true)
                        //{
                        //	_cardLogicComponent.faceDownCardsCount++;
                        //}
                    }
                    //_cardLogicComponent.faceDownCardsCount =  deckRecord.faceDownCardsCount;

                    deck.UpdateCardsPosition(false);
                }

                _cardLogicComponent.faceDownCardsCount = 0;
                for (int k = 0; k < _cardLogicComponent.CardsArray.Length; k++)
                {
                    Card card = _cardLogicComponent.CardsArray[k];
                    if (card.isFaceDown == true)
                    {
                        _cardLogicComponent.faceDownCardsCount++;
                    }
                }
                //_gameMgrComponent._scoreCount = StatesData.States[StatesData.States.Count - 1].Score;
                _hintComponent.UpdateAvailableForDragCards();
                _cardLogicComponent.GameManagerComponent.CardMove();
                StatesData.States.RemoveAt(StatesData.States.Count - 1);
                ActivateUndoButton();
            }
        }
        /// <summary>
        /// Load game if it exist.
        /// </summary>
        public void LoadGame()
        {
            //if a lastGameKey exists, the Player has played a last game
            if (PlayerPrefs.HasKey(_lastGameKey))
            {
                //load the lastGame from the Json utility
                string lastGameData = PlayerPrefs.GetString(_lastGameKey);
                StatesData = JsonUtility.FromJson <UndoData>(lastGameData);

                //if StateData contains data, continue
                if (StatesData.States.Count > 0)
                {
                    _hintComponent.IsHintWasUsed        = false;
                    _cardLogicComponent.IsNeedResetPack = false;
                    IsCountable          = StatesData.IsCountable;
                    _availableUndoCounts = StatesData.AvailableUndoCounts;

                    InitCardsNumberArray();
                    for (int i = 0; i < _cardLogicComponent.AllDeckArray.Length; i++)
                    {
                        Deck       deck       = _cardLogicComponent.AllDeckArray[i];
                        DeckRecord deckRecord = StatesData.States[StatesData.States.Count - 1].DecksRecord[i];
                        deck.CardsArray = new List <Card>(deckRecord.Cards);

                        if (deck.CardsArray.Count > 0)
                        {
                            for (int j = 0; j < deckRecord.CardsRecord.Count; j++)
                            {
                                Card       card       = deck.CardsArray[j];
                                CardRecord cardRecord = deckRecord.CardsRecord[j];

                                card.CardType                = cardRecord.CardType;
                                card.CardNumber              = cardRecord.CardNumber;
                                card.Number                  = cardRecord.Number;
                                card.CardStatus              = cardRecord.CardStatus;
                                card.CardColor               = cardRecord.CardColor;
                                card.IsDraggable             = cardRecord.IsDraggable;
                                card.IndexZ                  = cardRecord.IndexZ;
                                card.isFaceDown              = cardRecord.IsFaceDown;
                                card.Deck                    = cardRecord.Deck;
                                card.transform.localPosition = cardRecord.Position;
                                card.transform.SetSiblingIndex(cardRecord.SiblingIndex);
                                card.isFaceDown = cardRecord.IsFaceDown;

                                //TEMP ----------------------------------------------------------------------------------------------------------
                                //if(card.isFaceDown == true)
                                //{
                                //	_cardLogicComponent.faceDownCardsCount--;
                                //}
                                //----------------------------------------------------------------------------------------------------------------
                            }
                            //PERMANENT ------------------------------------------------------------------------------------------------------------
                            //_cardLogicComponent.faceDownCardsCount = deckRecord.faceDownCardsCount;
                        }
                        //deck.UpdateCardsPosition(false);
                        deck.UpdateCardsPosition(true);
                    }

                    _cardLogicComponent.faceDownCardsCount = 0;
                    for (int i = 0; i < _cardLogicComponent.CardsArray.Length; i++)
                    {
                        Card card = _cardLogicComponent.CardsArray[i];
                        if (card.isFaceDown == true)
                        {
                            _cardLogicComponent.faceDownCardsCount++;
                        }
                    }

                    StatesData.States.RemoveAt(StatesData.States.Count - 1);
                    _hintComponent.UpdateAvailableForDragCards();
                    ActivateUndoButton();
                }
            }
        }