Beispiel #1
0
 public GameState()
 {
     players     = new List <PlayerState>();
     deck        = UNOCard.Shuffle(UNOCard.GetDeck());
     currentCard = deck[0];
     deck        = UNOCard.RemoveCard(deck, currentCard);
 }
Beispiel #2
0
        public static UNOCard[] GetValidCards(UNOCard currentCard, UNOCard[] playerCards)
        {
            int            currentCardColor  = currentCard.GetColor();
            int            currentCardNumber = currentCard.GetNumber();
            List <UNOCard> validCards        = playerCards.ToList();

            foreach (UNOCard card in validCards)
            {
                int number = card.GetNumber();
                int power  = card.GetPower();
                int color  = card.GetColor();
                if (number != -1)
                {
                    if (number != currentCardNumber || color != currentCardColor)
                    {
                        validCards.Remove(card);
                    }
                }
                else
                {
                    if (power != 3 || power != 4)                     //Plus 4 or wild
                    {
                        if (color != currentCardColor)
                        {
                            validCards.Remove(card);
                        }
                    }
                }
            }
            return(validCards.ToArray());
        }
Beispiel #3
0
 public void setCurrentCard(UNOCard currentcard)
 {
     if (currentcard == null)
     {
         return;
     }
     this.currentCard = currentcard;
 }
Beispiel #4
0
        private void UpdateCurrentCard(int receivedSize)
        {
            Debug.WriteLine("Updating CurrentCard");
            string  data = Encoding.ASCII.GetString(clientState.buffer, 0, receivedSize);
            UNOCard card = JsonConvert.DeserializeObject <UNOCard>(data);

            clientState.currentCard = card;
        }
Beispiel #5
0
 public static UNOCard[] GetDeck()
 {
     UNOCard[] cards       = new UNOCard[Constants.TOTAL_CARDS];
     UNOCard[] numberCards = GetNumberCards();
     UNOCard[] powerCards  = GetPowerCards();
     numberCards.CopyTo(cards, 0);
     powerCards.CopyTo(cards, numberCards.Length);
     return(cards);
 }
Beispiel #6
0
        public void Initialize()
        {
            Debug.WriteLine("Deck size: " + deck.Length);
            int count = 1;

            foreach (PlayerState player in players)
            {
                player.currentCard = currentCard;
                player.playerCards = SubArray(deck, count, Constants.START_CARDS);
                player.noOfCards   = Constants.START_CARDS;
                player.validCards  = UNOCard.GetValidCards(currentCard, player.playerCards);
                count += Constants.START_CARDS;
            }
        }
Beispiel #7
0
        public static UNOCard[] Shuffle(UNOCard[] cards)
        {
            Random random = new Random();
            int    length = cards.Length;
            int    k;

            while (length > 1)
            {
                k = random.Next(length--);
                UNOCard temp = cards[length];
                cards[length] = cards[k];
                cards[k]      = temp;
            }
            return(cards);
        }
Beispiel #8
0
 public void AddPlayer(PlayerState playerState)
 {
     playerState.currentCard = currentCard;
     playerState.noOfCards   = Constants.START_CARDS;
     UNOCard[] playerCards = new UNOCard[Constants.START_CARDS];
     for (int i = 0; i < Constants.START_CARDS; i++)
     {
         UNOCard card = deck[0];
         playerCards[i] = card;
         deck           = UNOCard.RemoveCard(deck, card);
     }
     playerState.playerCards = playerCards;
     players.Add(playerState);
     Debug.WriteLine("Player properly added!");
 }
Beispiel #9
0
        public void Initialize()
        {
            deck        = UNOCard.Shuffle(UNOCard.GetDeck());
            currentCard = deck[0];
            int count = 1;

            foreach (PlayerState player in players)
            {
                player.currentCard = currentCard;
                player.playerCards = SubArray(deck, count, Constants.START_CARDS);
                player.noOfCards   = Constants.START_CARDS;
                player.validCards  = UNOCard.GetValidCards(currentCard, player.playerCards);
                count += Constants.START_CARDS;
            }
        }
Beispiel #10
0
        private void SendCurrentCard(Socket clientSocket)
        {
            PlayerState player = GetPlayerStateFromSocket(clientSocket);

            if (player != null)
            {
                UNOCard currentCard = gameState.getCurrentCard();
                byte[]  data        = ConvertObjectToByte(currentCard);
                Debug.WriteLine("Sending currentCard, type UNOCard");
                Send(player, data);
            }
            else
            {
                Debug.WriteLine("Corresponding Player for socket not found!");
            }
        }
Beispiel #11
0
        private static UNOCard[] GetNumberCards()
        {
            UNOCard[] numberCards = new UNOCard[80];
            int       index       = 0;

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        numberCards[index] = new UNOCard(i, j, -1);
                        index += 1;
                    }
                }
            }
            return(numberCards);
        }
Beispiel #12
0
        public static UNOCard[] RemoveCard(UNOCard[] cards, UNOCard removalCard)
        {
            int index = Array.IndexOf(cards, removalCard);

            if (index == -1)
            {
                return(cards);
            }
            UNOCard[] newCards = new UNOCard[cards.Length - 1];
            int       count    = 0;

            for (int i = 0; i < cards.Length; i++)
            {
                if (i == index)
                {
                    continue;
                }
                newCards[count++] = cards[i];
            }
            return(newCards);
        }
Beispiel #13
0
 public static UNOCard GetRandomCard()
 {
     UNOCard[] deck = new UNOCard[144];
     deck = UNOCard.GetDeck();
     return(GetRandomCard(deck));
 }