Beispiel #1
0
        public virtual void Awake()
        {
            foreach (Photon.Realtime.Player p in PhotonNetwork.PlayerList)
            {
                if (p.IsLocal)
                {
                    localPlayer            = new MyPlayer();
                    localPlayer.PlayerId   = p.ActorNumber.ToString();
                    localPlayer.PlayerName = p.NickName;
                    localPlayer.Position   = PlayerPositions[0].position;
                }
                else
                {
                    remotePlayer            = new MyPlayer();
                    remotePlayer.PlayerId   = p.ActorNumber.ToString();
                    remotePlayer.PlayerName = p.NickName;
                    remotePlayer.Position   = PlayerPositions[1].position;
                }
                gameDataManager = new GameDataManager(localPlayer, remotePlayer);
            }

            //remotePlayer = new Player();
            //remotePlayer.PlayerId = "offline-bot";
            //remotePlayer.PlayerName = "Bot";
            //remotePlayer.Position = PlayerPositions[1].position;
            //remotePlayer.BookPosition = BookPositions[1].position;
            //remotePlayer.IsAI = true;

            cardAnimator = FindObjectOfType <CardAnimator>();
        }
Beispiel #2
0
        public void SendStackCardsToPlayer(Player receivingPlayer, CardAnimator cardAnimator, List <byte> cardValues, bool isLocalPlayer)
        {
            List <Card> StackCards = cardAnimator.getStack();
            int         playerDisplayingCardsCount = StackCards.Count;

            if (playerDisplayingCardsCount < cardValues.Count)
            {
                Debug.LogError("Not enough stack cards");
                return;
            }

            for (int index = 0; index < cardValues.Count; index++)
            {
                Card card      = null;
                byte cardValue = cardValues[index];

                if (isLocalPlayer)
                {
                    foreach (Card c in StackCards)
                    {
                        if (c.Rank == Card.GetRank(cardValue) && c.Suit == Card.GetSuit(cardValue))
                        {
                            card = c;
                            break;
                        }
                    }
                }
                else
                {
                    card = StackCards[playerDisplayingCardsCount - 1 - index];
                    card.SetCardValue(cardValue);
                    card.SetFaceUp(true);
                }

                if (card != null)
                {
                    card.isInStack   = false;
                    card.isTouchable = true;

                    receivingPlayer.ReceiveDisplayingCard(card);
                    cardAnimator.AddCardAnimation(card, receivingPlayer.NextCardPosition(), index);

                    if (isLocalPlayer)
                    {
                        NumberOfDisplayingCards++;
                    }
                    else
                    {
                        receivingPlayer.NumberOfDisplayingCards++;
                    }
                }
                else
                {
                    Debug.LogError("Unable to find stack card.");
                }
            }
            cardAnimator.clearStack();
            RepositionDisplayingCards(cardAnimator);
        }
Beispiel #3
0
 public void RepositionDroppedCards(CardAnimator cardAnimator)
 {
     for (int i = 0; i < DroppedCards.Count; i++)
     {
         Vector2 newPos = cardAnimator.droppedCardPosition + Vector2.right * Constants.PLAYER_CARD_POSITION_OFFSET * i;
         cardAnimator.AddCardAnimation(DroppedCards[i], newPos);
     }
 }
 public void RepositionDisplayingCards(CardAnimator cardAnimator)
 {
     numberOfDisplayingCards = 0;
     foreach (Card card in DisplayingCards)
     {
         numberOfDisplayingCards++;
         cardAnimator.AddCardAnimation(card, NextCardPosition());
     }
 }
Beispiel #5
0
 public void RepositionDisplayingCards(CardAnimator cardAnimator)
 {
     NumberOfDisplayingCards = 0;
     for (int i = 0; i < DisplayingCards.Count; i++)
     {
         NumberOfDisplayingCards++;
         Vector2 nextPos = Position + Vector2.right * Constants.PLAYER_CARD_POSITION_OFFSET * (i + 1);
         cardAnimator.AddCardAnimation(DisplayingCards[i], nextPos);
     }
 }
Beispiel #6
0
        public void RepositionDisplayingCards(CardAnimator cardAnimator)
        {
            NumberOfDisplayingCards = 0;
            foreach (Card card in DisplayingCards)
            {
                card.transform.rotation = Quaternion.identity;

                NumberOfDisplayingCards++;
                cardAnimator.AddCardAnimation(card, NextCardPosition());
            }
        }
Beispiel #7
0
        public void SendDisplayingCardToPlayer(Player receivingPlayer, CardAnimator cardAnimator, List <byte> cardValues, bool isLocalPlayer)
        {
            int playerDisplayingCardsCount = DisplayingCards.Count;

            if (playerDisplayingCardsCount < cardValues.Count)
            {
                Debug.LogError("Not enough displaying cards");
                return;
            }

            for (int index = 0; index < cardValues.Count; index++)
            {
                Card card      = null;
                byte cardValue = cardValues[index];

                if (isLocalPlayer)
                {
                    foreach (Card c in DisplayingCards)
                    {
                        if (c.Rank == Card.GetRank(cardValue) && c.Suit == Card.GetSuit(cardValue))
                        {
                            card = c;
                            break;
                        }
                    }
                }
                else
                {
                    card = DisplayingCards[playerDisplayingCardsCount - 1 - index];
                    card.SetCardValue(cardValue);
                    card.SetFaceUp(true);
                }

                if (card != null)
                {
                    Debug.Log("DisplayingCards.Remove(card) " + card);

                    DisplayingCards.Remove(card);
                    receivingPlayer.ReceiveDisplayingCard(card);
                    cardAnimator.AddCardAnimation(card, receivingPlayer.NextCardPosition());
                    NumberOfDisplayingCards--;
                }
                else
                {
                    Debug.LogError("Unable to find displaying card.");
                }
            }

            RepositionDisplayingCards(cardAnimator);
        }
Beispiel #8
0
        public void PutCardInStack(CardAnimator cardAnimator, Card card)
        {
            Debug.Log("DisplayingCards.Remove(card) " + card);
            card.isInStack   = true;
            card.isTouchable = false;
            card.SetFaceUp(true);

            DisplayingCards.Remove(card);
            DisplayingBooks.Remove(card);
            HiddenBooks.Remove(card);

            cardAnimator.AddCardToStack(card);
            NumberOfDisplayingCards--;

            RepositionDisplayingCards(cardAnimator);
        }
Beispiel #9
0
        public virtual void Awake()
        {
            localPlayer              = new MyPlayer();
            localPlayer.PlayerId     = "offline-player";
            localPlayer.PlayerName   = "Player";
            localPlayer.Position     = PlayerPositions[0].position;
            localPlayer.BookPosition = BookPositions[0].position;

            remotePlayer              = new MyPlayer();
            remotePlayer.PlayerId     = "offline-bot";
            remotePlayer.PlayerName   = "Bot";
            remotePlayer.Position     = PlayerPositions[1].position;
            remotePlayer.BookPosition = BookPositions[1].position;
            remotePlayer.IsAI         = true;

            cardAnimator = FindObjectOfType <CardAnimator>();
        }
Beispiel #10
0
        public void CreateBottomBook(byte cardValue, CardAnimator cardAnimator, int index)
        {
            Vector2 targetPosition = GetBookPositionByIndex(index);
            Card    card           = cardAnimator.TakeFirstDisplayingCard();

            card.SetCardValue(cardValue);
            card.SetDisplayingOrder(-1);
            card.OwnerId = PlayerId;
            card.SetFaceUp(false);
            card.isTouchable = false;

            float      randomRotation = UnityEngine.Random.Range(-1 * Constants.BOOK_MAX_RANDOM_ROTATION, Constants.BOOK_MAX_RANDOM_ROTATION);
            Quaternion rotation       = Quaternion.Euler(Vector3.forward * randomRotation);

            cardAnimator.AddCardAnimation(card, targetPosition, rotation);
            HiddenBooks.Add(card);
            NumberOfHiddenBooks++;
        }
Beispiel #11
0
        protected void Awake()
        {
            localPlayer              = new Player();
            localPlayer.PlayerId     = "offline-player";
            localPlayer.PlayerName   = "Player";
            localPlayer.Position     = PlayerPositions[0].position;
            localPlayer.BookPosition = BookPositions[0].position;

            remotePlayer              = new Player();
            remotePlayer.PlayerId     = "offline-bot";
            remotePlayer.PlayerName   = "Bot";
            remotePlayer.Position     = PlayerPositions[1].position;
            remotePlayer.BookPosition = BookPositions[1].position;
            remotePlayer.IsAI         = true;

            cardAnimator = FindObjectOfType <CardAnimator>();
            audioData    = GetComponent <AudioSource>();
        }
Beispiel #12
0
        protected void Awake()
        {
            Debug.Log("base awake");
            localPlayer              = new Player();
            localPlayer.PlayerId     = "offline-player";
            localPlayer.PlayerName   = "Player";
            localPlayer.Position     = PlayerPositions[0].position;
            localPlayer.BookPosition = BookPositions[0].position;

            remotePlayer              = new Player();
            remotePlayer.PlayerId     = "offline-bot";
            remotePlayer.PlayerName   = "Bot";
            remotePlayer.Position     = PlayerPositions[1].position;
            remotePlayer.BookPosition = BookPositions[1].position;
            remotePlayer.IsAI         = true;

            cardAnimator = FindObjectOfType <CardAnimator>();
        }
        public void ReceiveBook(Ranks rank, CardAnimator cardAnimator)
        {
            Vector2     targetPosition          = NextBookPosition();
            List <Card> displayingCardsToRemove = new List <Card>();

            foreach (Card card in DisplayingCards)
            {
                if (card.Rank == rank)
                {
                    card.SetFaceUp(true);
                    float randomRotation = UnityEngine.Random.Range(-1 * Constants.BOOK_MAX_RANDOM_ROTATION, Constants.BOOK_MAX_RANDOM_ROTATION);
                    cardAnimator.AddCardAnimation(card, targetPosition, Quaternion.Euler(Vector3.forward * randomRotation));
                    displayingCardsToRemove.Add(card);
                }
            }

            DisplayingCards.RemoveAll(card => displayingCardsToRemove.Contains(card));
            RepositionDisplayingCards(cardAnimator);
            numberOfBooks++;
        }
        public void RestoreBook(Ranks rank, CardAnimator cardAnimator)
        {
            Vector2 targetPosition = NextBookPosition();

            for (int i = 0; i < 4; i++)
            {
                Card card = cardAnimator.TakeFirstDisplayingCard();

                int intRankValue = (int)rank;
                int cardValue    = (intRankValue - 1) * 4 + i;

                card.SetCardValue((byte)cardValue);
                card.SetFaceUp(true);
                float randomRotation = UnityEngine.Random.Range(-1 * Constants.BOOK_MAX_RANDOM_ROTATION, Constants.BOOK_MAX_RANDOM_ROTATION);
                card.transform.position = targetPosition;
                card.transform.rotation = Quaternion.Euler(Vector3.forward * randomRotation);
            }

            numberOfBooks++;
        }
Beispiel #15
0
        protected void Awake()
        {
            localPlayer              = new Player();
            localPlayer.PlayerId     = "offline-player";
            localPlayer.PlayerName   = "Player";
            localPlayer.Position     = PlayerPositions[0].position;
            localPlayer.BookPosition = BookPositions[0].position;

            remotePlayer = new Player[3];

            remotePlayer[0]              = new Player();
            remotePlayer[0].PlayerId     = "offline-bot1";
            remotePlayer[0].PlayerName   = "Bot1";
            remotePlayer[0].Position     = PlayerPositions[1].position;
            remotePlayer[0].BookPosition = BookPositions[1].position;
            remotePlayer[0].IsAI         = true;

            remotePlayer[1]              = new Player();
            remotePlayer[1].PlayerId     = "offline-bot2";
            remotePlayer[1].PlayerName   = "Bot2";
            remotePlayer[1].Position     = PlayerPositions[2].position;
            remotePlayer[1].BookPosition = BookPositions[2].position;
            remotePlayer[1].IsAI         = true;

            remotePlayer[2]              = new Player();
            remotePlayer[2].PlayerId     = "offline-bot3";
            remotePlayer[2].PlayerName   = "Bot3";
            remotePlayer[2].Position     = PlayerPositions[3].position;
            remotePlayer[2].BookPosition = BookPositions[3].position;
            remotePlayer[2].IsAI         = true;

            ChoseThePlayerCardButtonPanel.GetComponent <ButtonPlayerConfiguration>().AsignPlayersToButtons(remotePlayer[0].PlayerName, remotePlayer[1].PlayerName, remotePlayer[2].PlayerName);

            cardAnimator = FindObjectOfType <CardAnimator>();
            ChoseThePlayerCardButtonPanel.SetActive(false);

            currentTurnPlayer       = null;
            currentTurnTargetPlayer = null;
            nextTurnPlayer          = null; //popravljanje sp igre
        }
Beispiel #16
0
        public Card DropCardFromPlayer(CardAnimator cardAnimator, byte cardValue, bool isLocalPlayer)
        {
            int playerDisplayingCardsCount = DisplayingCards.Count;

            Card card = null;

            if (isLocalPlayer)
            {
                foreach (Card c in DisplayingCards)
                {
                    if (c.Rank == Card.GetRank(cardValue) && c.Suit == Card.GetSuit(cardValue))
                    {
                        card = c;
                        break;
                    }
                }
            }
            else
            {
                //computer di rasesatppudu ra
                card = DisplayingCards[playerDisplayingCardsCount - 1];
                card.SetCardValue(cardValue);
                card.SetFaceUp(true);
            }

            if (card != null)
            {
                DisplayingCards.Remove(card);
                //cardAnimator.AddCardAnimation(card, receivingPlayer.NextCardPosition());
                NumberOfDisplayingCards--;
            }
            else
            {
                Debug.LogError("Unable to find displaying card.");
            }
            RepositionDisplayingCards(cardAnimator);

            return(card);
        }
Beispiel #17
0
 private void Awake()
 {
     foreach (Player p in PhotonNetwork.PlayerList)
     {
         if (p.IsLocal)
         {
             localPlayer            = new MyPlayer();
             localPlayer.PlayerId   = p.ActorNumber.ToString();
             localPlayer.PlayerName = p.NickName;
             localPlayer.Position   = PlayerPositions[0].position;
         }
         else
         {
             remotePlayer            = new MyPlayer();
             remotePlayer.PlayerId   = p.ActorNumber.ToString();
             remotePlayer.PlayerName = p.NickName;
             remotePlayer.Position   = PlayerPositions[1].position;
         }
     }
     leastCountManager = new LeastCountManager(localPlayer, remotePlayer);
     cardAnimator      = FindObjectOfType <CardAnimator>();
 }
Beispiel #18
0
        public void CreateTopBook(byte rank, CardAnimator cardAnimator, int index)
        {
            Vector2 targetPosition = GetBookPositionByIndex(index);

            Card card = cardAnimator.TakeFirstDisplayingCard();

            //card.Suit = (Suits)UnityEngine.Random.Range(0, 3);
            //card.Rank = rank;

            card.SetCardValue(rank);

            card.SetDisplayingOrder(0);
            card.OwnerId = PlayerId;
            //card.SetFaceUp(true);
            card.isTouchable = false;

            float      randomRotation = UnityEngine.Random.Range(-1 * Constants.BOOK_MAX_RANDOM_ROTATION, Constants.BOOK_MAX_RANDOM_ROTATION);
            Quaternion rotation       = Quaternion.Euler(Vector3.forward * randomRotation);

            cardAnimator.AddCardAnimation(card, targetPosition, rotation);
            DisplayingBooks.Add(card);

            NumberOfBooks++;
        }
Beispiel #19
0
        public string SendDisplayingCardToStack(CardAnimator cardAnimator, List <byte> cardValues, bool isLocalPlayer)
        {
            string result = "";

            List <Card> allPossibleCards = new List <Card>();

            allPossibleCards.AddRange(DisplayingCards);

            if (DisplayingCards.Count == 0 && isFinishedHandCards())
            {
                allPossibleCards.AddRange(DisplayingBooks);
                foreach (Card card in DisplayingBooks)
                {
                    card.isTouchable = true;
                }
            }
            else
            {
                foreach (Card card in DisplayingBooks)
                {
                    card.isTouchable = false;
                }
            }
            if (DisplayingBooks.Count == 0 && allPossibleCards.Count == 0 && isFinishedDisplayingBooks())
            {
                allPossibleCards.AddRange(HiddenBooks);
                foreach (Card card in HiddenBooks)
                {
                    card.isTouchable = true;
                }
            }
            else
            {
                foreach (Card card in HiddenBooks)
                {
                    card.isTouchable = false;
                }
            }

            for (int i = 0; i < cardValues.Count; i++)
            {
                byte cardValue = cardValues[i];
                Card card      = null;

                if (isLocalPlayer)
                {
                    foreach (Card c in allPossibleCards)
                    {
                        if ((c.Rank == Card.GetRank(cardValue) && c.Suit == Card.GetSuit(cardValue)) || isFinishedDisplayingBooks())
                        {
                            card = c;
                            card.SetCardValue(cardValue);
                            break;
                        }
                    }
                }
                else
                {
                    card = allPossibleCards[i];           //[i] ??
                    card.SetCardValue(cardValue);
                    //result = false;
                }

                result = isCardOkToThrow(cardAnimator, card);
            }
            return(result);
        }
Beispiel #20
0
        private string isCardOkToThrow(CardAnimator cardAnimator, Card card)
        {
            if (card != null)
            {
                bool doIhaveAluckyCard = card.Rank == Ranks.Two || card.Rank == Ranks.Three || card.Rank == Ranks.Ten;
                Card topStackCard      = cardAnimator.GetStackTopCard();
                Card previousStackCard = cardAnimator.GetStackPreviousTopCard();

                if (topStackCard != null)
                {
                    if (topStackCard.Rank == Ranks.Ace)
                    {
                        if (card.Rank == Ranks.Ace || doIhaveAluckyCard)
                        {
                            if (card.Rank == Ranks.Ten)
                            {
                                Put10CardInStack(cardAnimator, card);
                                return("");
                            }
                            else
                            {
                                PutCardInStack(cardAnimator, card);
                                return("");
                            }
                        }
                        else
                        {
                            return("You need an Ace, or a lucky card");
                        }
                    }
                    else if (topStackCard.Rank == Ranks.Seven)
                    {
                        if (card.Rank <= Ranks.Seven && card.Rank != Ranks.Ace)
                        {
                            PutCardInStack(cardAnimator, card);
                            return("");
                        }
                        else if (doIhaveAluckyCard)
                        {
                            if (card.Rank == Ranks.Ten)
                            {
                                Put10CardInStack(cardAnimator, card);
                                return("");
                            }
                            else
                            {
                                PutCardInStack(cardAnimator, card);
                                return("");
                            }
                        }
                        else
                        {
                            return("You need smaller or equal card than 7, or a lucky card");
                        }
                    }
                    else if (topStackCard.Rank == Ranks.Two || card.Rank == Ranks.Ace || doIhaveAluckyCard)
                    {
                        if (card.Rank == Ranks.Ten)
                        {
                            Put10CardInStack(cardAnimator, card);
                            return("");
                        }
                        else
                        {
                            PutCardInStack(cardAnimator, card);
                            return("");
                        }
                    }
                    else if (topStackCard.Rank == Ranks.Three)
                    {
                        if (previousStackCard != null)
                        {
                            if (card.Rank >= previousStackCard.Rank && previousStackCard.Rank != Ranks.Ace)
                            {
                                PutCardInStack(cardAnimator, card);
                                return("");
                            }
                            else if (previousStackCard.Rank == Ranks.Ace && (card.Rank == Ranks.Ace || doIhaveAluckyCard))
                            {
                                if (card.Rank == Ranks.Ten)
                                {
                                    Put10CardInStack(cardAnimator, card);
                                    return("");
                                }
                                else
                                {
                                    PutCardInStack(cardAnimator, card);
                                    return("");
                                }
                            }
                            else
                            {
                                return("You need bigger card than " + previousStackCard.Rank + ", or a lucky card");
                            }
                        }
                        else
                        {
                            if (card.Rank >= Ranks.Three || (card.Rank == Ranks.Ace || doIhaveAluckyCard))
                            {
                                if (card.Rank == Ranks.Ten)
                                {
                                    Put10CardInStack(cardAnimator, card);
                                    return("");
                                }
                                else
                                {
                                    PutCardInStack(cardAnimator, card);
                                    return("");
                                }
                            }
                            else
                            {
                                return("You need bigger card than 3, or a lucky card");
                            }
                        }
                    }
                    else if (card.Rank >= topStackCard.Rank)
                    {
                        PutCardInStack(cardAnimator, card);
                        return("");
                    }
                    else
                    {
                        return("You need bigger card than " + topStackCard.Rank);
                    }
                }
                else
                {
                    PutCardInStack(cardAnimator, card);
                    return("");
                }
            }
            else
            {
                return("Unable to find displaying card.");
            }
        }