Exemplo n.º 1
0
        private void IsEight(Player player, Player[] allPlayer, Server server)
        {
            int valid = 0;

            while (valid == 0)
            {
                server.SendMessageToOne(player.Id, "Which color do you choose ?\nHearts ?\tClubs ?\tSpades ?\tDiamonds ?");
                valid = 1;
                server.LastPlayerId = null;
                while (server.LastPlayerId == null || !(player.Id.ConnectionInfo.Equals(server.LastPlayerId.ConnectionInfo)))
                {
                }
                if (server.LastMessaged == "Hearts" || server.LastMessaged == "hearts")
                {
                    lastCard.Color = "Hearts";
                    lastCard.Face  = "";
                }
                else if (server.LastMessaged == "Clubs" || server.LastMessaged == "clubs")
                {
                    lastCard.Color = "Clubs";
                    lastCard.Face  = "";
                }
                else if (server.LastMessaged == "Spades" || server.LastMessaged == "Spades")
                {
                    lastCard.Color = "Spades";
                    lastCard.Face  = "";
                }
                else if (server.LastMessaged == "Diamonds" || server.LastMessaged == "Diamonds")
                {
                    lastCard.Color = "Diamonds";
                    lastCard.Face  = "";
                }
                else
                {
                    valid = 0;
                    server.SendMessageToOne(player.Id, "Unknown color ? (Maybe a Typo Error)");
                }
                System.Threading.Thread.Sleep(2000);
            }
            server.SendMessageToAll("The new color is : " + lastCard.Color);
        }
Exemplo n.º 2
0
        private void YourTurn(Player player, Server server, Player[] allPlayer)
        {
            int valid = 0;
            int pos   = 0;

            Card[] hand = player.hand.GetHand();

            server.SendMessageToOther(turn, "It's Player " + (turn + 1) + " turn.\n");
            while (valid == 0)
            {
                server.SendMessageToOne(player.Id, "clear");
                System.Threading.Thread.Sleep(2000);
                server.SendMessageToOne(player.Id, "It's your turn. The current card is : " + lastCard.SendValue());
                player.hand.ShowHand(player.Id, server, this);
                server.SendMessageToOne(player.Id, "Choose your card by entering the number to the left of the chosen card or draw a card by typing \"draw\"");
                server.LastPlayerId = null;
                while (server.LastPlayerId == null || !(player.Id.ConnectionInfo.Equals(server.LastPlayerId.ConnectionInfo)))
                {
                }
                if (server.LastMessaged == "draw")
                {
                    valid = 2;
                }
                else
                {
                    if (!(IsDigitsOnly(server.LastMessaged)) || (pos = int.Parse(server.LastMessaged)) >= hand.Length)
                    {
                        server.SendMessageToOne(player.Id, "Error : Not a valid number. The answer must be a number between 0 and " + hand.Length.ToString());
                        System.Threading.Thread.Sleep(2000);
                    }
                    else if (IsValidCard(hand[pos]))
                    {
                        valid = 1;
                    }
                    else
                    {
                        server.SendMessageToOne(player.Id, "You can't play this card.");
                        System.Threading.Thread.Sleep(2000);
                    }
                }
            }
            if (valid == 1)
            {
                server.SendMessageToOne(player.Id, "You throw your " + hand[pos].SendValue());
                server.SendMessageToOther(turn, "Player N°" + (turn + 1) + " throw a " + hand[pos].SendValue());
                lastCard = hand[pos];
                player.hand.ThrowCard(pos);
                if (lastCard.Face == "Eight")
                {
                    IsEight(player, allPlayer, server);
                }
                else if (lastCard.Face == "Jack")
                {
                    IsJack(player, allPlayer, server);
                }
                else if (lastCard.Face == "Ace")
                {
                    IsAce(player, allPlayer, server);
                }
                else if (lastCard.Face == "Two")
                {
                    IsTwo(player, allPlayer, server);
                }
                else if (lastCard.Color == "Joker")
                {
                    IsJoker(player, allPlayer, server);
                }
                if (player.hand.NbrCard == 0)
                {
                    end = turn;
                }
            }
            else if (valid == 2)
            {
                server.SendMessageToOne(player.Id, "You draw a card");
                server.SendMessageToOther(turn, "Player N°" + (turn + 1) + " draw a card");
                player.hand.AddInHand(deck, 1, server, player);
            }
            System.Threading.Thread.Sleep(3000);
        }
Exemplo n.º 3
0
 public Rules(Server server, Player[] allPlayers)
 {
     round = 0;
     Help(server);
     sense = '+';
     System.Threading.Thread.Sleep(10000);
     while (round < 3)
     {
         server.SendMessageToAll("clear");
         System.Threading.Thread.Sleep(2000);
         server.SendMessageToAll("Time for another round.\nHere we Go");
         deck = new Deck();
         deck.Shuffle();
         lastCard = deck.Deal();
         InitPlayersHand(deck, allPlayers);
         end  = -1;
         turn = 0;
         System.Threading.Thread.Sleep(1000);
         for (int i = 0; i < 4; i++)
         {
             allPlayers[i].hand.ShowHand(allPlayers[i].Id, server, this);
         }
         System.Threading.Thread.Sleep(1000);
         while (end == -1 && deck.Idx < 54)
         {
             YourTurn(allPlayers[turn], server, allPlayers);
             if (sense == '+')
             {
                 turn = turn + 1;
             }
             else
             {
                 turn = turn - 1;
             }
             if (turn == -1)
             {
                 turn = 3;
             }
             else if (turn == 4)
             {
                 turn = 0;
             }
         }
         server.SendMessageToAll("Player n°" + end + " is the winner of this round.");
         for (int i = 0; i < 4; i++)
         {
             if (i != end)
             {
                 allPlayers[i].Score += GetScore(allPlayers[i].hand);
             }
             server.SendMessageToOne(allPlayers[i].Id, "Your total score is " + allPlayers[i].Score.ToString());
         }
         round = round + 1;
     }
     server.SendMessageToAll("clear");
     server.SendMessageToAll("Here is the final score :\nPlayer n°1 : " + allPlayers[0].Score.ToString() + "\nPlayer n°2 : " + allPlayers[1].Score.ToString() +
                             "\nPlayer n°3 : " + allPlayers[2].Score.ToString() + "\nPlayer n°4 : " + allPlayers[3].Score.ToString());
     winner      = 0;
     winnerScore = allPlayers[0].Score;
     for (int i = 0; i < 4; i++)
     {
         if (allPlayers[i].Score < winnerScore)
         {
             winner      = i;
             winnerScore = allPlayers[i].Score;
         }
     }
     System.Threading.Thread.Sleep(300);
     server.SendMessageToAll("The winner of this game is Player n°" + winner + " with a score of " + allPlayers[winner].Score.ToString()
                             + "\nWell Done. I hope you enjoyed the game.");
     System.Threading.Thread.Sleep(10000);
 }