Exemple #1
0
 /// <summary>
 /// Plaies the check.
 /// </summary>
 /// <returns><c>true</c>, if check was played, <c>false</c> otherwise.</returns>
 /// <param name="board">Board.</param>
 /// <param name="n">N.</param>
 /// <param name="contract">Contract.</param>
 private bool playCheck(List <Card> board, int n, Contract contract)
 {
     try
     {
         cards.ElementAt(n);
         if (board.Count == 0)
         {
             return(true);
         }
         if (cards.ElementAt(n).getColor() == board.ElementAt(0).getColor())
         {
             return(true);
         }
         if (board.ElementAt(0).doYouHaveSuit(cards))
         {
             return(false);
         }
         if (cards.ElementAt(n).getColor() == contract.getColor())
         {
             return(true);
         }
         Card card = new Card(contract.getColor(), Value.ACE);
         return(!card.doYouHaveSuit(cards));
     }
     catch (Exception)
     {
         GameManager.SendPrivate(this, "Out of range!");
         return(false);
     }
 }
Exemple #2
0
        /// <summary>
        /// Play the specified board and contract.
        /// </summary>
        /// <returns>The play.</returns>
        /// <param name="board">Board.</param>
        /// <param name="contract">Contract.</param>
        public Card play(List <Card> board, Contract contract)
        {
            if (board.Count != 0)
            {
                GameManager.SendPrivate(this, "The current board is composed of :");
            }
            foreach (Card i in board)
            {
                GameManager.SendPrivate(this, " - " + i.getValue() + " of " + i.getColor());
            }
            GameManager.SendPrivate(this, "Player " + this.id + "! Your turn! The asset's suit is " + contract.getColor() + ".");
            GameManager.SendPrivate(this, "Your current cards:");
            for (int j = 0; j != cards.Count; j += 1)
            {
                GameManager.SendPrivate(this, j + " -> " + cards.ElementAt(j).getValue() + " of " + cards.ElementAt(j).getColor());
            }
            GameManager.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, contract)))
                {
                    GameManager.SendPrivate(this, "Wait... You can't play this card!");
                }
            }
            GameManager.SendPrivate(this, "Great !");
            Card res = cards.ElementAt(n);

            cards.Remove(cards.ElementAt(n));
            return(res);
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Server.Game"/> class.
 /// </summary>
 /// <param name="id">Identifier.</param>
 /// <param name="users">Users.</param>
 public Game(int id, List <UserManager> users)
 {
     this.id = id;
     deck    = new List <Card>();
     players = new List <Player>();
     foreach (UserManager n in users)
     {
         players.Add(new Player(players.Count, (players.Count % 2 == 0 ? Team.FIRST : Team.SECOND), n));
         GameManager.SendPrivate(players.Last(), "You are player " + (players.Count - 1) + " and you are in the " + ((players.Count - 1) % 2 == 0 ? Team.FIRST : Team.SECOND) + " team.");
         GameManager.SendAll(players, "Player " + (players.Count - 1) + " is joining in the " + ((players.Count - 1) % 2 == 0 ? Team.FIRST : Team.SECOND) + " team.");
     }
     contract = new Contract();
 }
Exemple #4
0
        /// <summary>
        /// Waits for message.
        /// </summary>
        /// <returns>The for message.</returns>
        public int WaitForMessage()
        {
            string answer = null;
            int    res    = 0;

            while (true)
            {
                answer = userManager.GetReader().ReadLine();
                if (Int32.TryParse(answer, out res))
                {
                    break;
                }
                GameManager.SendPrivate(this, "What are you trying to do?");
            }
            return(res);
        }