Example #1
0
        public bool SetCall(Call c)
        {
            if (c == null)
            {
                return(false);
            }
            if (c.bids < 4)
            {
                return(false);
            }
            if (c.bids < this.bids)
            {
                return(false);
            }
            if (c.trump < this.trump && c.bids <= this.bids)
            {
                return(false);
            }

            if (c.bids == this.bids && this.trump == c.trump)
            {
                return(false);
            }
            this.bids  = c.bids;
            this.trump = c.trump;
            return(true);
        }
Example #2
0
        /// <summary>
        /// Takes a number(id) and returns a card for that specific number
        /// </summary>
        /// <param name="counter">This will be the ID of the card</param>
        /// <returns>Generated Card object</returns>
        public static Card GenerateCard(int counter)
        {
            int value = (counter % 13) + 1; // gets the value from 1 to 13

            GameC.Suites suite;
            switch (counter / 13) // divide the deck to 4 suites
            {
            case 0:
                suite = 0;
                break;

            case 1:
                suite = (GameC.Suites) 1;
                break;

            case 2:
                suite = (GameC.Suites) 2;
                break;

            default:
                suite = (GameC.Suites) 3;
                break;
            }
            return(new Card(counter, value, suite));
        }
Example #3
0
        public bool CouldPlay(GameC.Suites openSuite, Card cardToPlay)
        {
            DetermineAvoidness();

            if (openSuite == cardToPlay.Suite || openSuite == GameC.Suites.Null)
            {
                return(true);
            }
            if (openSuite == GameC.Suites.Spades && avoidSpades)
            {
                return(true);
            }
            if (openSuite == GameC.Suites.hearts && avoidHearts)
            {
                return(true);
            }
            if (openSuite == GameC.Suites.diamonds && avoidDiamonds)
            {
                return(true);
            }
            if (openSuite == GameC.Suites.clubs && avoidClubs)
            {
                return(true);
            }

            return(false);
        }
Example #4
0
 public Round(Player[] players, GameC.Suites trump)
 {
     this.players = players;
     this.trump   = trump;
     //for (int i = 0; i < 4; i++)
     //{
     //    players[i].IsCall = true;
     //}
 }
Example #5
0
        private void CallForm_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 14; i++)
            {
                if ((Label)sender == lblArr[i])
                {
                    stringBids = lblArr[i].Text;

                    if (!title.Equals("Place your call", StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (Convert.ToInt32(stringBids) > Convert.ToInt32(title.Split(' ')[0]))
                        {
                            return; // to unable the user to make bids more than the call bids
                        }
                    }
                    if (stringSuite != null)
                    {
                        stringSuite = GameC.GetSuiteShape(stringSuite);
                    }
                    lblArr[18].Text = "Current Call: " + stringBids + stringSuite;
                    return;
                }
            }
            for (int i = 14; i < 18; i++)
            {
                if ((Label)sender == lblArr[i])
                {
                    stringSuite = GameC.GetSuiteShape(lblArr[i].Text);

                    lblArr[18].Text = "Current Call: " + stringBids + stringSuite;
                    lblNumber       = i;
                    return;
                }
            }
            if ((Label)sender == lblArr[19])
            {
                if (!title.Equals("Place your call", StringComparison.CurrentCultureIgnoreCase))
                {
                    SendBids(Convert.ToInt32(stringBids));
                    Close();
                    return;
                }

                GameC.Suites suite = (GameC.Suites)lblNumber - 14;
                int          bids  = Convert.ToInt32(stringBids);
                call = new Call(suite, bids);
                SendCall(call);
                return;
            }

            if ((Label)sender == lblArr[20])
            {
                SendCall(new Call());
            }
        }
Example #6
0
        public void PlayHand(Card[] PlayedCards)
        {
            GameC.Suites OpenSuite = (GameC.Suites) 5;
            for (int j = 0; j < players.Length; j++)
            {
                players[j].ListCards();
                Console.WriteLine("{0} select a card.", players[j].Name);
                int  position = Convert.ToInt32(Console.ReadLine());
                Card played   = players[j].PlayCard(position);
                if (j == 0)
                {
                    OpenSuite = played.Suite;
                }
                PlayedCards[j] = played;
            }
            Hand hand   = new Hand(PlayedCards, OpenSuite, trump);
            int  winner = hand.ReturnWinningIndex();

            players[winner].CollectedHands++;
            Console.WriteLine("{0} won the round.", players[winner].Name);
            UpdatePlayers(winner);
        }
Example #7
0
 public static Card Compare(GameC.Suites openSuite, GameC.Suites trump, Card c1, Card c2)
 {
     if (c1.suite == trump && c2.suite != trump)
     {
         return(c1);
     }
     else if (c2.suite == trump && c1.suite != trump)
     {
         return(c2);
     }
     else if (c2.suite == openSuite && c1.suite != openSuite)
     {
         return(c2);
     }
     else if (c1.suite == openSuite && c2.suite != openSuite)
     {
         return(c1);
     }
     else
     {
         return((c1.value > c2.value) ? c1 : c2);
     }
 }
Example #8
0
 private Card(int number, int value, GameC.Suites suite)
 {
     this.number = number;
     this.value  = value;
     this.suite  = suite;
 }
Example #9
0
        static void Main(string[] args)
        {
            ConnectForm connectForm = new ConnectForm();

            Application.Run(connectForm);
            //IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000);

            players = new Player[4];
            //TcpListener listener = new TcpListener(endPoint);
            TcpListener listener = connectForm.Listener;

            clients = new TcpClient[4];
            List <Card> playerCards = new List <Card>(13);

            ConnectClients(listener);
            InitializeNames();

            for (int l = 0; l < 18; l++)
            {
                #region Intialize player
                Deck deck = new Deck();
                for (int i = 0; i < players.Length; i++)
                {
                    playerCards = deck.GetPlayerCards();
                    int clientIndex = players[i].ClientIndex;
                    ns = clients[clientIndex].GetStream();
                    players[i].PlayerCards = playerCards;
                    bf.Serialize(ns, players[i]);
                    ns.Flush();
                }
                #endregion
                #region call logic
                int caller = 0;
                for (int i = 0; i < players.Length; i++)
                {
                    int             clientIndex = players[i].ClientIndex;
                    NetworkStream   ns          = clients[clientIndex].GetStream();
                    BinaryFormatter bf          = new BinaryFormatter();
                    Call            tempCall    = (Call)bf.Deserialize(ns);

                    if (call.SetCall(tempCall))
                    {
                        players[caller].IsCall = false;
                        caller = i;
                        players[caller].IsCall = true;
                    }
                    Console.WriteLine(call);
                }
                SendCallToPlayers();

                for (int i = 0; i < players.Length; i++)
                {
                    if (players[i].IsCall)
                    {
                        players[i].RequiredHands = call.Bids;
                        continue;
                    }

                    int             clientIndex = players[i].ClientIndex;
                    NetworkStream   ns          = clients[clientIndex].GetStream();
                    BinaryFormatter bf          = new BinaryFormatter();
                    players[i].RequiredHands = (int)bf.Deserialize(ns);
                }
                #endregion

                #region round logic
                Round round = new Round(players, call.Trump);
                round.ArrangePlayers();
                for (int j = 0; j < 13; j++)
                {
                    Card[]       playedCards = new Card[4];
                    GameC.Suites openSuite   = GameC.Suites.Null;
                    for (int i = 0; i < players.Length; i++)
                    {
                        int clientIndex = players[i].ClientIndex;
                        ns = clients[clientIndex].GetStream();
                        SendTurns(i);
                        Card tempCard = (Card)bf.Deserialize(ns);
                        if (i == 0)
                        {
                            openSuite = tempCard.Suite;
                        }
                        SendCardToPlayers(tempCard, i);
                        Console.WriteLine(tempCard.ToString());
                        playedCards[i] = tempCard;
                    }
                    Hand hand       = new Hand(playedCards, openSuite, call.Trump);
                    int  handWinner = hand.ReturnWinningIndex();
                    players[handWinner].CollectedHands++;
                    //SendWinnerToPlayers(handWinner); // send the client index of the winner player to the players
                    // to update his collected hands


                    round.UpdatePlayers(handWinner);
                }
                round.CalculateScore();

                #endregion
            }
        }
Example #10
0
 public Call(GameC.Suites t, int b)
 {
     this.trump = t;
     this.bids  = b;
 }
Example #11
0
 public Hand(Card[] cardArr, GameC.Suites openSuit, GameC.Suites trumpSuit)
 {
     this.cardArr   = cardArr;
     this.trumpSuit = trumpSuit;
     this.openSuit  = openSuit;
 }