public void OnTouchEndDrag() { // TODO: Check if the card is using. if (card.stateTouched != Enums.StateTouch.Drag && card.stateTouched != Enums.StateTouch.BeginDrag) { // TODO: Break the function. return; } // TODO: Reset the state of touching. card.stateTouched = Enums.StateTouch.None; // TODO: Check the Playing zone. if (DoCheckPlayingZone()) { // TODO: Break the functions. return; } // TODO: Back to the current position. card.Moving(card.TargetPosition, card.parentTransform, () => { // TODO: Distribute the follow cards. card.DistributeTheFollowCards(); // TODO: Failed Collect; card.AnimationFailedCollect(); }); }
public bool DoCheckPlayingZone(bool IsMoving = true) { // TODO: Check the condition null. if (object.ReferenceEquals(GamePlay.Instance.cardSaveCache, null)) { // TODO: Break the function. return(false); } // TODO: Get the cache of card. var cardSave = GamePlay.Instance.cardSaveCache; bool IsReadyAnotherCondition = true; bool IsReadyKingCondition = false; if (card.GetEnumsCard() == Enums.CardVariables.King && cardSave.GetEnumsCard() == Enums.CardVariables.One || card.GetEnumsCard() == Enums.CardVariables.One && cardSave.GetEnumsCard() == Enums.CardVariables.King) { // TODO: Set the another condition. IsReadyKingCondition = true; } switch (GameManager.Instance.GetModeGame()) { case Enums.ModeGame.Hard: if (card.GetTypeCards() != cardSave.GetTypeCards()) { // TODO: Set the another condition. IsReadyAnotherCondition = false; } break; case Enums.ModeGame.Medium: if (!card.IsSameColorCard(cardSave.GetTypeCards())) { // TODO: Set the another condition. IsReadyAnotherCondition = false; } break; } if ((cardSave.GetValue() + 1 == card.GetValue() || cardSave.GetValue() - 1 == card.GetValue()) && IsReadyAnotherCondition || IsReadyKingCondition && IsReadyAnotherCondition) { Enums.IdTransformCard previousId = PlayingZone.Instance.GetIdTransform(card); // TODO: Record undo. UndoSystem.Instance.Record(Enums.Zone.Play, PlayingZone.Instance.GetIdTransform(card), card, card.IsUnlocked()); // TODO: Get the dafult transform from zone. Transform parentTransform = ResultZone.Instance.GetTransformCards(Enums.IdTransformCard.TransformCards_A); // TODO: Get the position of card from zone. var position = Helper.GetPositionInTheResultZone(Enums.IdTransformCard.TransformCards_A, Enums.Direction.None, true); // TODO: Set the target position x for the card. card.TargetPosition.x = position.x; // TODO: Set the target position y for the card. card.TargetPosition.y = position.y; // TODO: Set the target position z for the card. card.TargetPosition.z = position.z; //Debug.Log("--card.POSITION: " + card.transform.position); //Debug.Log("--card.TargetPosition: " + card.TargetPosition); // TODO: Moving the card to new position. card.Moving(card.TargetPosition, parentTransform, () => { if (PlayingZone.Instance.IsEmptyCards(previousId)) { Vector3 positionFind = PlayingZone.Instance.GetDefaultPosition(previousId); // TODO: Get the pool. var objectEmptyThing = PoolSystem.Instance.GetFromPool(Enums.PoolType.PExploise); if (!object.ReferenceEquals(objectEmptyThing, null)) { // TODO: Enable the gameobject. objectEmptyThing.gameObject.SetActive(true); // TODO: Set the position. objectEmptyThing.transform.position = positionFind; } var textEmptyThing = PoolSystem.Instance.GetFromPool(Enums.PoolType.TColorText); if (!object.ReferenceEquals(textEmptyThing, null)) { // TODO: Set the position. textEmptyThing.transform.position = positionFind; // TODO: Get the script. var scriptEmptyFind = textEmptyThing.GetComponent <TScoreDisplay>(); // TODO: Check the condition to show. if (!object.ReferenceEquals(scriptEmptyFind, null)) { // TODO: Display the score. scriptEmptyFind.Show(Contains._ScoreResultClear); // TODO: Enable the gameobject. textEmptyThing.gameObject.SetActive(true); } } // TODO: Update the score. Contains.Score += Contains.ScoreResultClear; // TODO: Play the completed sound. SoundSystems.Instance.PlaySound(Enums.SoundIndex.Completed); } // TODO: Play the correct sound. SoundSystems.Instance.PlaySound(Enums.SoundIndex.Correct); // TODO: Get the pool. var objectThing = PoolSystem.Instance.GetFromPool(Enums.PoolType.PExploise); if (!object.ReferenceEquals(objectThing, null)) { // TODO: Enable the gameobject. objectThing.gameObject.SetActive(true); // TODO: Set the position. objectThing.transform.position = card.TargetPosition; } var textThing = PoolSystem.Instance.GetFromPool(Enums.PoolType.TColorText); if (!object.ReferenceEquals(textThing, null)) { // TODO: Set the position. textThing.transform.position = card.TargetPosition; // TODO: Get the script. var scriptFind = textThing.GetComponent <TScoreDisplay>(); // TODO: Check the condition to show. if (!object.ReferenceEquals(scriptFind, null)) { // TODO: Display the score. scriptFind.Show(Contains._ScoreResultCards); // TODO: Enable the gameobject. textThing.gameObject.SetActive(true); } } // TODO: Unlock the last card. PlayingZone.Instance.UnlockLastCard(); // TODO: Update the state of card. PlayingZone.Instance.UpdateTheStateCardsInZone(); // TODO: Update the score. Contains.Score += Contains.ScoreResultCards; // TODO: Update the display score. UIBehaviours.Instance.UpdateScore(); //GamePlay.Instance.checkAutoWin(); if (GamePlay.Instance.IsConditionWining()) { // TODO: Update the state of GameOver. GameManager.Instance.UpdateState(Enums.StateGame.GameOver); // TODO: Showing the wining dialog. DialogSystem.Instance.ShowDialogWining(); var fireworks = PoolSystem.Instance.GetFromPool(Enums.PoolType.Fireworks); if (!object.ReferenceEquals(fireworks, null)) { fireworks.transform.SetParent(GamePlay.Instance.transform); fireworks.transform.localPosition = Contains.Vector3Zero; fireworks.gameObject.SetActive(true); } // TODO: Save the score. PlayerData.BestScore = Contains.Score; // TODO: Save the best move. PlayerData.BestMove = Contains.Moves; // TODO: Save the best time. PlayerData.BestTime = Contains.Time; // TODO: Play wining music. SoundSystems.Instance.PlayerMusic(Enums.MusicIndex.WinMusic); } }); // TODO: Remove the card from list. PlayingZone.Instance.RemoveTheCard(card); // TODO: Add the card to the list result. ResultZone.Instance.AddTheCard(Enums.IdTransformCard.TransformCards_A, card); // TODO: Set the card save. GamePlay.Instance.cardSaveCache = card; return(true); } return(false); }
/// <summary> /// Drawings the game handle. /// </summary> /// <returns>The game handle.</returns> IEnumerator <float> DrawingGameHandle() { // TODO: Create the default card. CardBehaviour cardCache = null; // TODO: Create the default position. Vector3 position = Contains.Vector3Zero; // TODO: Create the start transform. Enums.IdTransformCard idTransform = Enums.IdTransformCard.TransformCards_A; // TODO: Get the count increase. int countIncrease = 0; // TODO: Get the lenght of cards. int lenght = cardsGet.Count - 1; // TODO: Loop 28 times to draw the cards. for (int i = 0; i < 28; i++) { // TODO: Check don't enough cards to use. if (lenght <= i) { // TODO: Throw the exception and stop the game. throw new UnityException(Contains.NullExceptions); } // TODO: Set value of card. cardCache = cardsGet [i]; // TODO: Check if this card is null. if (cardCache == null) { // TODO: Throw the exception and stop the game. throw new UnityException(Contains.NullExceptions); } // TODO: Get the dafult transform from zone. Transform parentTransform = PlayingZone.Instance.GetTransformCards(idTransform); // TODO: Get the position of card from zone. position = Helper.GetPositionInThePlayingZone(idTransform, Enums.Direction.Down); // TODO: Set the target position x for the card. cardCache.TargetPosition.x = position.x; // TODO: Set the target position y for the card. cardCache.TargetPosition.y = position.y; // TODO: Set the target position z for the card. cardCache.TargetPosition.z = position.z; // TODO: Moving the card to new position. cardCache.Moving(cardCache.TargetPosition, parentTransform); //Debug.Log("cardCache1 -- " + cardCache.TargetPosition); // TODO: Adding the card to the list of cards. PlayingZone.Instance.AddTheCard(idTransform, cardCache); // TODO: Playing the sound. SoundSystems.Instance.PlaySound(Enums.SoundIndex.Draw); // TODO: Waiting until next draw. yield return(Timing.WaitForSeconds(Contains.DurationDraw)); // TODO: Get the next id of transform. idTransform = PlayingZone.Instance.GetNextIDTransform(idTransform); if (idTransform == Enums.IdTransformCard.TransformCards_A) { if (countIncrease == PlayingZone.Instance.GetLenghtZone()) { // TODO: Break the loop. break; } countIncrease++; for (int j = 0; j < countIncrease; j++) { idTransform = PlayingZone.Instance.GetNextIDTransform(idTransform); } } } // TODO: Get the next id of transform. idTransform = Enums.IdTransformCard.TransformCards_A; // TODO: Get the dafult transform from zone. Transform defaulTransform = HintZone.Instance.GetTransformCards(idTransform); // TODO: Get the position of card from zone. position = Helper.GetPositionInTheHintZone(idTransform, Enums.Direction.Left); for (int i = 28; i <= lenght; i++) { // TODO: Check don't enough cards to use. if (lenght < i) { // TODO: Throw the exception and stop the game. throw new UnityException(Contains.NullExceptions); } // TODO: Set value of card. cardCache = cardsGet [i]; // TODO: Check if this card is null. if (cardCache == null) { // TODO: Throw the exception and stop the game. throw new UnityException(Contains.NullExceptions); } // TODO: Set the target position x for the card. cardCache.TargetPosition.x = position.x; // TODO: Set the target position y for the card. cardCache.TargetPosition.y = position.y; // TODO: Set the target position z for the card. cardCache.TargetPosition.z = position.z; // TODO: Moving the card to new position. cardCache.Moving(cardCache.TargetPosition, defaulTransform, null, true); //Debug.Log("cardCache2 -- " + cardCache.TargetPosition); // TODO: Adding the card to the list of cards. HintZone.Instance.AddTheCard(idTransform, cardCache); // TODO: Play the sound. SoundSystems.Instance.PlaySound(Enums.SoundIndex.Draw); // TODO: Waiting until next draw. yield return(Timing.WaitForSeconds(Contains.DurationDraw)); } // TODO: Waiting until next draw. yield return(Timing.WaitForSeconds(Contains.DurationDraw * 2)); // TODO: Get the next id of transform. idTransform = HintZone.Instance.GetNextIDTransform(idTransform); // TODO: Unlocking the last cards in each arrays. PlayingZone.Instance.UnlockLastCard(); yield return(0f); }
/// <summary> /// Draws the cards. /// </summary> IEnumerator <float> _DrawCards(int numberCards) { // TODO: Get the list Cards from the zone. cardCache = HintZone.Instance.GetTheLastCard(Enums.IdTransformCard.TransformCards_A); // TODO: Check time ready to next card. bool IsReady = false; // TODO: Check the condition. if (!object.ReferenceEquals(cardCache, null)) { // TODO: Record undo. UndoSystem.Instance.Record(Enums.Zone.Hint, Enums.IdTransformCard.TransformCards_A, cardCache, cardCache.IsUnlocked()); // TODO: Add the arrays. var arrayCards = HintZone.Instance.GetTheListCards(Enums.IdTransformCard.TransformCards_B); // TODO: Sort the cards. Helper.SortCards(arrayCards, Enums.Direction.Right, HintZone.Instance.GetDefaultPosition(Enums.IdTransformCard.TransformCards_B)); // TODO: Get the dafult transform from zone. Transform parentTransform = HintZone.Instance.GetTransformCards(Enums.IdTransformCard.TransformCards_B); // TODO: Get the position of card from zone. var position = Helper.GetPositionInTheHintZone(Enums.IdTransformCard.TransformCards_B, Enums.Direction.Right, true); // TODO: Set the target position x for the card. cardCache.TargetPosition.x = position.x; // TODO: Set the target position y for the card. cardCache.TargetPosition.y = position.y; // TODO: Set the target position z for the card. cardCache.TargetPosition.z = position.z; // TODO: Moving the card to new position. cardCache.Moving(cardCache.TargetPosition, parentTransform, () => { // TODO: play the sounds. SoundSystems.Instance.PlaySound(Enums.SoundIndex.Draw); cardCache.Unlock(true, () => { // TODO: Ready to draw another cards. IsReady = true; }); }); // TODO: Remove the cards from the list. HintZone.Instance.RemoveTheCard(cardCache); // TODO: Add the new card. HintZone.Instance.AddTheCard(Enums.IdTransformCard.TransformCards_B, cardCache); // TODO: Set the card unlocked. GamePlay.Instance.cardSaveCache = cardCache; } else { // TODO: Get the arrays. var arrayCards = new List <CardBehaviour> (HintZone.Instance.GetTheListCards(Enums.IdTransformCard.TransformCards_B)); if (!object.ReferenceEquals(arrayCards, null)) { // TODO: Get the trasnform A. var transformA = HintZone.Instance.GetTransformCards(Enums.IdTransformCard.TransformCards_A); for (int i = arrayCards.Count - 1; i > -1; i--) { UndoSystem.Instance.Record(Enums.Zone.Hint, Enums.IdTransformCard.TransformCards_B, arrayCards [i], arrayCards [i].IsUnlocked(), i != arrayCards.Count - 1, false); arrayCards [i].TargetPosition = HintZone.Instance.GetDefaultPosition(Enums.IdTransformCard.TransformCards_A); // TODO: Lock the cards. arrayCards [i].Lock(); // TODO: Get the arrayCards [i].Moving(arrayCards [i].TargetPosition, HintZone.Instance.GetTransformCards(Enums.IdTransformCard.TransformCards_A), null, true); // TODO: Remove the old cards. HintZone.Instance.RemoveTheCard(Enums.IdTransformCard.TransformCards_B, arrayCards [i]); // TODO: Set the default list card. HintZone.Instance.AddTheCard(Enums.IdTransformCard.TransformCards_A, arrayCards [i]); } // TODO: Return waiting time. yield return(Timing.WaitForSeconds(1f)); IsReady = true; } else { IsReady = true; } } while (IsReady == false) { yield return(0f); } // TODO: Check the current state of game. if (GameManager.Instance.GetStateGame() == Enums.StateGame.Drawing) { // TODO: Update the current state. GameManager.Instance.UpdateState(Enums.StateGame.Playing); } }
/// <summary> /// Draws the cards. /// </summary> IEnumerator <float> _DrawCards(int numberCards) { // TODO: Get the list Cards from the zone. cardCache = HintZone.Instance.GetTheLastCard(Enums.IdTransformCard.TransformCards_A); // TODO: Check time ready to next card. bool IsReady = false; // TODO: Check the condition. if (!object.ReferenceEquals(cardCache, null)) { // TODO: Record undo. UndoSystem.Instance.Record(Enums.Zone.Hint, Enums.IdTransformCard.TransformCards_A, cardCache, cardCache.IsUnlocked()); // TODO: Get the dafult transform from zone. Transform parentTransform = ResultZone.Instance.GetTransformCards(Enums.IdTransformCard.TransformCards_A); // TODO: Get the position of card from zone. var position = Helper.GetPositionInTheResultZone(Enums.IdTransformCard.TransformCards_A, Enums.Direction.None, true); // TODO: Set the target position x for the card. cardCache.TargetPosition.x = position.x; // TODO: Set the target position y for the card. cardCache.TargetPosition.y = position.y; // TODO: Set the target position z for the card. cardCache.TargetPosition.z = position.z; //Debug.Log("cardCache -- " + cardCache.TargetPosition); // TODO: Moving the card to new position. cardCache.Moving(cardCache.TargetPosition, parentTransform, () => { // TODO: play the sounds. SoundSystems.Instance.PlaySound(Enums.SoundIndex.Draw); cardCache.Unlock(true, () => { // TODO: Ready to draw another cards. IsReady = true; }); }); // TODO: Remove the cards from the list. HintZone.Instance.RemoveTheCard(cardCache); // TODO: Add the new card. ResultZone.Instance.AddTheCard(Enums.IdTransformCard.TransformCards_A, cardCache); // TODO: Set the card unlocked. GamePlay.Instance.cardSaveCache = cardCache; } else { IsReady = true; } while (IsReady == false) { yield return(0f); } // TODO: Check the current state of game. if (GameManager.Instance.GetStateGame() == Enums.StateGame.Drawing) { // TODO: Update the current state. GameManager.Instance.UpdateState(Enums.StateGame.Playing); } }