コード例 #1
0
ファイル: OnCardClick.cs プロジェクト: NeiLip/Arthur-Scripts
    /// <summary>
    /// When clicked on ANY card on the field
    /// </summary>
    public void OnMouseDown()
    {
        if (!gameHandler._waitingForHaltCoroutine && gameHandler.IsGameRunning() && !gameHandler.GetIsGamePaused() && !GetBothCardsCoroutines())   //Makes sure game is running and haltCoroutine is not running
        //    for (int i = 0; i < gameHandler.GetAmountOfCards(); i++) {
        //   string tempCard = i.ToString();// getting wanted card


        {
            if (!gameHandler.GetCard(_cardLocation).GetIsCardFaceUp())   //selecting the card and making sure it is not faced up
            {
                gameHandler._waitingForCardsFlipCoroutine[0] = true;
                StartCoroutine(FlipCardAnimationCoroutine(true, _cardGameSprite, 0));                                                                          //Flip card animation

                _cardGameSprite.GetComponent <SpriteRenderer>().sprite = gameHandler.GetBasicSprite(gameHandler.GetCard(_cardLocation).GetValue() + 1).sprite; //Value + 1 because [0] contains back of a card

                //If it enters it means that there was already one card faced up
                if (gameHandler.GetAmountOfCardsFacedUp() % 2 == 1)
                {
                    if (gameHandler.GetChosenCard().GetValue() == gameHandler.GetCard(_cardLocation).GetValue())   //If same value is already faced-up-card or it is the first card to play

                    {
                        gameHandler.MainGameViewRef.PlayMatchParticles();
                        gameHandler.soundHandler.PlayMatch();

                        PlaceCard(_cardLocation);

                        //Adding 10 POINTS move
                        if (!gameHandler.isSoloGame)
                        {
                            gameHandler.AddScoreToPlayer(gameHandler.GetCurPlayer(), 10);
                            gameHandler.MainGameViewRef.PlayGotScorAnim(true);
                        }
                        else  //adding 1
                        {
                            gameHandler.AddScoreToPlayer(gameHandler.GetCurPlayer(), 1);
                        }

                        gameHandler.UpdateViewRef();

                        if (gameHandler.IsGameWithMissiosQuestions())   //if using Missions
                        {
                            gameHandler.ToggleMissQuesMenu();
                            gameHandler.BringCardToFront();
                        }
                        else
                        {
                            gameHandler.CheckIfWon();
                        }
                    }
                    else  //Flipping back cards
                    {
                        gameHandler.soundHandler.PlayFlipCard();
                        gameHandler._waitingForHaltCoroutine = true;
                        StartCoroutine(FlipCardsBackCoroutine()); //Waits befor flipping cards back
                    }
                }
                else   // There are even cards on field. Place the i'th (odd number) card
                {
                    PlaceCard(_cardLocation);
                }
            }
        }
    }