예제 #1
0
    private void PickAndSetCard(HandDeck playerHandDeck)
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);

            if (hit.collider != null)
            {
                var card      = hit.collider.gameObject;
                var cardName  = card.name.Split(' ')[0];
                var cardPower = GetCardPower(card);

                var oldPos = card.transform.position;
                playerCard = card;
                card.transform.position = new Vector2(2.5f, -1);

                playerHandDeck.cards.Remove(card);

                if (CheckIfHaveTwenty(playerHandDeck, cardName, cardPower))
                {
                    playerScoreSum += 20;
                }

                CardGenerator.GenerateCard(playerHandDeck, oldPos);
            }
            isPlayerTurn = false;
        }
    }
예제 #2
0
    private void GiveFirstPlayerCards(IList<GameObject> dealerDeck, HandDeck firstPlayerHandDeck)
    {
        for (int i = 0; i < 6; i++)
        {
            int randomIndex = Random.Range(0, dealerDeck.Count);

            var cardToAdd = dealerDeck[randomIndex];

            firstPlayerHandDeck.cards.Add(cardToAdd);

            dealerDeck.Remove(cardToAdd);
        }
    }
예제 #3
0
    private static bool CheckIfHaveTwenty(HandDeck playerHandDeck, string cardName, int cardPower)
    {
        var pairCard = playerHandDeck.cards.Where(pc => pc.name.Split(' ')[0] == cardName).ToArray();

        foreach (var pc in pairCard)
        {
            var pairPower = int.Parse(pc.name.Split(' ')[1]);
            if (pairPower == 3 || pairPower == 4)
            {
                return(true);
            }
        }
        return(false);
    }
예제 #4
0
    public static void GenerateCard(HandDeck handDeck, Vector2 position)
    {
        var dealerDeck = Dealer.instance.dealerDeck;

        //Check if dealer has any cards in his deck
        if (!dealerDeck.Any())
        {
            Debug.Log("No more cards left!");
            return;
        }

        //Generate random index and card
        int randomIndex = Random.Range(0, dealerDeck.Count);

        var cardToGenerate = dealerDeck[randomIndex];

        if (dealerDeck.Count != 1)
        {
            if (cardToGenerate == Dealer.instance.trumpCard)
            {
                randomIndex = Random.Range(0, dealerDeck.Count);

                cardToGenerate = dealerDeck[randomIndex];
            }
            //Add generated card to the player hand deck
            handDeck.cards.Add(cardToGenerate);

            //Remove the card from dealer's deck
            dealerDeck.Remove(cardToGenerate);

            //Instantiate generated card
            Instantiate(cardToGenerate, position, Quaternion.identity);
        }
        else
        {
            //Add generated card to the player hand deck
            handDeck.cards.Add(cardToGenerate);

            //Remove the card from dealer's deck
            dealerDeck.Remove(cardToGenerate);

            //Instantiate generated card
            Instantiate(cardToGenerate, position, Quaternion.identity);
        }
    }
예제 #5
0
 private void GenerateCards(HandDeck firstPlayerHandDeck, HandDeck secondPlayerHandDeck)
 {
     //Instantiate player cards
     for (int i = 0; i < firstPlayerHandDeck.cards.Count; i++)
     {
         Instantiate(firstPlayerHandDeck.cards[i], new Vector2(firstPlayerHandDeck.gameObject.transform.
                                                               position.x + i, firstPlayerHandDeck.gameObject.transform.
                                                               position.y), Quaternion.identity);
     }
     //Instantiate computer cards
     for (int i = 0; i < secondPlayerHandDeck.cards.Count; i++)
     {
         Instantiate(secondPlayerHandDeck.cards[i], new Vector2(secondPlayerHandDeck.gameObject.transform.
                                                                position.x + i, secondPlayerHandDeck.gameObject.transform.
                                                                position.y), Quaternion.identity);
         secondPlayerHandDeck.cards[i].transform.position = new Vector2(secondPlayerHandDeck.gameObject.transform.
                                                                        position.x + i, secondPlayerHandDeck.gameObject.transform.
                                                                        position.y);
     }
     areCardsGenerated = true;
 }
예제 #6
0
 public void SetHand(HandDeck hand)
 {
     this.hand = hand;
 }
예제 #7
0
 public void SetHandDeck(HandDeck handDeck)
 {
     this.handDeck = handDeck;
 }
예제 #8
0
    private void ComputerPickAndSetCard(HandDeck computerHandDeck)
    {
        if (playerCard != null && computerHandDeck.ContainsCard(playerCard.name.Split(' ')[0]))
        {
            GameObject card = computerHandDeck.cards.Where(c => c.gameObject.name.Split(' ')[0] == playerCard.gameObject.name.Split(' ')[0]).FirstOrDefault();

            var oldPos = card.transform.position;
            computerCard = GameObject.Find(card.gameObject.name + "(Clone)");

            computerCard.transform.position = new Vector2(2.5f, 1);

            computerHandDeck.cards.Remove(card);
            var cardName  = computerCard.name.Split(' ')[0];
            var cardPower = GetCardPower(computerCard);
            if (CheckIfHaveTwenty(playerHandDeck, cardName, cardPower))
            {
                computerScoreSum += 20;
            }
            CardGenerator.GenerateCard(computerHandDeck, oldPos);
        }
        else
        {
            if (computerHandDeck.ContainsCard(Dealer.instance.trumpCard.name.Split(' ')[0]))
            {
                GameObject card = computerHandDeck.cards.Where(c => c.gameObject.name.Split(' ')[0] == Dealer.instance.trumpCard.name.Split(' ')[0]).FirstOrDefault();

                var oldPos = card.transform.position;
                computerCard = GameObject.Find(card.gameObject.name + "(Clone)");

                computerCard.transform.position = new Vector2(2.5f, 1);

                computerHandDeck.cards.Remove(card);
                var cardName  = computerCard.name.Split(' ')[0];
                var cardPower = GetCardPower(computerCard);
                if (CheckIfHaveTwenty(playerHandDeck, cardName, cardPower))
                {
                    computerScoreSum += 20;
                }
                CardGenerator.GenerateCard(computerHandDeck, oldPos);
                isPlayerTurn = true;
            }
            else
            {
                int        random = Random.Range(0, computerHandDeck.cards.Count);
                GameObject card   = computerHandDeck.cards[random];

                var oldPos = card.transform.position;
                computerCard = GameObject.Find(card.gameObject.name + "(Clone)");

                computerCard.transform.position = new Vector2(2.5f, 1);

                computerHandDeck.cards.Remove(card);

                var cardName  = computerCard.name.Split(' ')[0];
                var cardPower = GetCardPower(computerCard);
                if (CheckIfHaveTwenty(playerHandDeck, cardName, cardPower))
                {
                    computerScoreSum += 20;
                }
                CardGenerator.GenerateCard(computerHandDeck, oldPos);
                isPlayerTurn = true;
            }
        }
    }