Esempio n. 1
0
        public Card play(List <Card> board, Bid bid)
        {
            if (board.Count != 0)
            {
                Network.SendPrivate(this, "The current board is composed of :");
            }
            foreach (Card i in board)
            {
                Network.SendPrivate(this, " - " + i.getValue() + " of " + i.getSuit());
            }
            Network.SendPrivate(this, "Player " + this.id + "! Your turn! The asset's suit is " + bid.getSuit() + ".");
            Network.SendPrivate(this, "Your current cards:");
            for (int j = 0; j != cards.Count; j += 1)
            {
                Network.SendPrivate(this, j + " -> " + cards.ElementAt(j).getValue() + " of " + cards.ElementAt(j).getSuit());
            }
            Network.SendPrivate(this, "What is the number of the card you want to play?");
            int  n   = 0;
            bool end = false;

            while (!end)
            {
                n = WaitForMessage();
                if (!(end = playCheck(board, n, bid)))
                {
                    Network.SendPrivate(this, "Wait... You can't play this card!");
                }
            }
            Network.SendPrivate(this, "Great!");
            Card res = cards.ElementAt(n);

            cards.Remove(cards.ElementAt(n));
            return(res);
        }
Esempio n. 2
0
 private bool playCheck(List <Card> board, int n, Bid bid)
 {
     try
     {
         cards.ElementAt(n);
         if (board.Count == 0)
         {
             return(true);
         }
         if (cards.ElementAt(n).getSuit() == board.ElementAt(0).getSuit())
         {
             return(true);
         }
         if (board.ElementAt(0).doYouHaveSuit(cards))
         {
             return(false);
         }
         if (cards.ElementAt(n).getSuit() == bid.getSuit())
         {
             /*if (cards.elementAt(n).isItBiggest(board, true))
              *  return true;
              * else
              *  return (!cards.elementAt(n).isItBiggest(cards, true));*/
             return(true);
         }
         Card card = new Card(bid.getSuit(), Value.ACE);
         return(!card.doYouHaveSuit(cards));
     }
     catch (Exception)
     {
         Network.SendPrivate(this, "Out of range!");
         return(false);
     }
 }
Esempio n. 3
0
 public Game(int id, List <NetworkUser> users)
 {
     this.id = id;
     deck    = new List <Card>();
     players = new List <Player>();
     foreach (NetworkUser n in users)
     {
         players.Add(new Player(players.Count, (players.Count % 2 == 0 ? Team.FIRST : Team.SECOND), n));
         Network.SendPrivate(players.Last(), "Hello there! You are player " + (players.Count - 1) + " and you are in the " + ((players.Count - 1) % 2 == 0 ? Team.FIRST : Team.SECOND) + " team.");
         Network.SendAll(players, "Player " + (players.Count - 1) + " joined and he is in the " + ((players.Count - 1) % 2 == 0 ? Team.FIRST : Team.SECOND) + " team.");
     }
     bid = new Bid();
 }
Esempio n. 4
0
        public int WaitForMessage()
        {
            string answer = null;
            int    res    = 0;

            while (true)
            {
                answer = networkUser.GetReader().ReadLine();
                if (Int32.TryParse(answer, out res))
                {
                    break;
                }
                Network.SendPrivate(this, "What are you trying to do?");
            }
            return(res);
        }
Esempio n. 5
0
        public Bid auction(Bid bid)
        {
            int  n;
            bool end = false;

            if (bid.getAmount() != 0)
            {
                Network.SendPrivate(this, "The actual bill is " + bid.getAmount() + " " + bid.getSuit() + " from " + bid.getTeam() + " team.\n");
            }
            else
            {
                Network.SendPrivate(this, "You are the first one to bid!");
            }
            Network.SendPrivate(this, "Player " + id + " turn to bid:");
            while (!end)
            {
                string str = "What do you want to do? ";
                switch (bid.getStatus())
                {
                case Status.AMOUNT:
                    str += "1->bid ";
                    goto case Status.CAPOT;

                case Status.CAPOT:
                    str += "2->coinche ";
                    goto case Status.COINCH;

                case Status.COINCH:
                    if (bid.getStatus() == Status.COINCH)
                    {
                        str += "3->surcoinche ";
                    }
                    break;

                case Status.SURCOINCH:
                    Network.SendPrivate(this, "You can't bid anymore.");
                    passed = true;
                    return(bid);
                }
                if (bid.getStatus() == Status.AMOUNT)
                {
                    str += "4->capot ";
                }
                Network.SendPrivate(this, str + "5->pass");
                n   = WaitForMessage();
                end = true;
                switch (n)
                {
                case 1:
                    Network.SendPrivate(this, "What is the amount of your bid ? (>= " + (bid.getAmount() == 0 ? 80 : bid.getAmount() + 10) + ")");
                    if (!bid.setAmount(WaitForMessage()) || bid.getStatus() != Status.AMOUNT)
                    {
                        Network.SendPrivate(this, "Incorrect input");
                        end = false;
                        break;
                    }
                    Network.SendPrivate(this, "What is the suit ? (0->CLUB | 1->DIAMOND | 2->HEART | 3->SPADE)");
                    n = WaitForMessage();
                    if (n < 0 || n > 3)
                    {
                        Network.SendPrivate(this, "Incorrect input");
                        end = false;
                        break;
                    }
                    bid.setSuit(n);
                    bid.setTeam(this.team);
                    passed = false;
                    break;

                case 2:
                    if (bid.getStatus() != Status.AMOUNT && bid.getStatus() != Status.CAPOT)
                    {
                        Network.SendPrivate(this, "Incorrect input");
                        end = false;
                        break;
                    }
                    bid.setStatus(Status.COINCH);
                    passed = false;
                    break;

                case 3:
                    if (bid.getStatus() != Status.COINCH)
                    {
                        Network.SendPrivate(this, "Incorrect input");
                        end = false;
                        break;
                    }
                    bid.setStatus(Status.SURCOINCH);
                    passed = false;
                    break;

                case 4:
                    if (bid.getStatus() == Status.COINCH || bid.getStatus() == Status.SURCOINCH || bid.getStatus() == Status.CAPOT)
                    {
                        Network.SendPrivate(this, "Incorrect input");
                        end = false;
                        break;
                    }
                    bid.setStatus(Status.CAPOT);
                    bid.setTeam(team);
                    passed = false;
                    break;

                case 5:
                    passed = true;
                    break;

                default:
                    Network.SendPrivate(this, "Incorrect input");
                    end = false;
                    break;
                }
            }
            Network.SendPrivate(this, "Great!");
            return(bid);
        }