Example #1
0
        public void ReadyToPlay(Player source)
        {
            ExceptionHelpers.CheckNotNull(source, "source");

            source.ReadyToPlay = true;

            // check to see if everybody is ready!
            int humanPlayers      = 0;
            int humanPlayersReady = 0;

            for (int ctr = 0; ctr < this.players.Count; ctr++)
            {
                Player player = this.players[ctr];

                if (player.ComputerPlayer)
                {
                    continue;
                }

                humanPlayers++;

                if (player.ReadyToPlay)
                {
                    humanPlayersReady++;
                }
            }

            if (humanPlayers == humanPlayersReady && humanPlayers != 0)
            {
                this.StartGame();
            }
        }
Example #2
0
        /// <summary>
        /// Orders the card collection by number.
        /// </summary>
        public void OrderByNumber(GameRules rules)
        {
            ExceptionHelpers.CheckNotNull(rules, "rules");

            CardCollection copy = this.Copy();

            this.Clear();

            int minNum = (int)rules.MinimumCardNumber;
            int maxNum = (int)rules.MaximumCardNumber;
            int minCol = (int)rules.MinimumCardColor;
            int maxCol = (int)rules.MaximumCardColor;

            for (int num = minNum; num <= maxNum; num++)
            {
                for (int col = minCol; col <= maxCol; col++)
                {
                    while (true)
                    {
                        Card c = copy.RemoveCardWithNumberAndColor((CardNumber)num, (CardColor)col);

                        if (c == null)
                        {
                            break;
                        }

                        this.Add(c);
                    }
                }
            }

            this.OnItemsChanged();
        }
Example #3
0
        public Player WhoPlaysNext(Player source)
        {
            ExceptionHelpers.CheckNotNull(source, "source");

            int sourcePos = -1;

            for (int ctr = 0; ctr < this.players.Count; ctr++)
            {
                if (this.players[ctr] == source)
                {
                    sourcePos = ctr;
                    break;
                }
            }

            if (sourcePos == -1)
            {
                throw new ArgumentException("Couldn't find source player in player list.");
            }

            for (int ctr = sourcePos + 1; ctr != sourcePos; ctr++)
            {
                if (ctr == this.players.Count)
                {
                    ctr = 0;
                }

                if (!this.players[ctr].IsSkipped)
                {
                    return(this.players[ctr]);
                }
            }

            return(source);
        }
Example #4
0
        /// <summary>
        /// Skips this player. Skip came from player p.
        /// </summary>
        /// <param name="player">Player who skipped this player</param>
        public void SkippedBy(Player player)
        {
            ExceptionHelpers.CheckNotNull(player, "player");

            // get current session
            this.Scoreboard.CurrentSession.AddSkippedBy(player.PlayerID);
            this.SkipsLeft++;
        }
Example #5
0
        public void Discard(Card card, Player source)
        {
            Debug.WriteLine("Discarding...");
            ExceptionHelpers.CheckNotNull(card, "card");
            ExceptionHelpers.CheckNotNull(source, "source");

            this.discard.AddTopCard(card);

            this.OnPutDiscard(source, card);
        }
Example #6
0
        public void GetDiscard(Player source)
        {
            ExceptionHelpers.CheckNotNull(source, "source");

            Card c = this.discard.RemoveTopCard();

            source.Hand.Add(c.CarbonCopy());

            this.OnTookDiscard(source, c.CarbonCopy());
        }
Example #7
0
        public Client(NetworkSettings networkSettings, PlayerSettings playerSettings, GameRules gameRules)
        {
            ExceptionHelpers.CheckNotNull(networkSettings, "networkSettings");
            ExceptionHelpers.CheckNotNull(playerSettings, "playerSettings");
            ExceptionHelpers.CheckNotNull(gameRules, "gameRules");

            this.networkSettings = networkSettings;
            this.playerSettings  = playerSettings;
            this.GameRules       = gameRules;
        }
Example #8
0
        public void GetDeckCard(Player source)
        {
            ExceptionHelpers.CheckNotNull(source, "source");

            source.Hand.Add(this.deck.RemoveCard());

            if (this.deck.IsTopCardNull())
            {
                this.deck.ShuffleAndAddUnused(this.discard.RemoveAllButTopCard());
            }

            this.OnTookDeckCard(source, this.discard.ReadTopCard().CarbonCopy());
        }
Example #9
0
        public void AddPlayer(Player player)
        {
            ExceptionHelpers.CheckNotNull(player, "player");

            player.PlayerID = this.unusedPlayerID;
            this.unusedPlayerID++;
            this.players.Add(player);

            if (this.players.Count == this.Rules.MaximumPlayers)
            {
                PhazeXLog.LogInformation("Reached player limit, starting game.");
                this.StartGame();
            }
        }
Example #10
0
        /// <summary>
        /// Note: This function currently is stubbed out.
        /// This function is passed a linked list of cards, shuffles them
        /// randomly, and adds them back to the bottom of the deck. This
        /// should be called by the server whenever we run out of cards.
        /// It will take them from the discard pile (leaving the top one or
        /// two) and shuffle them back into the deck.
        /// </summary>
        /// <param name="cards">Linked list of cards to shuffle back into the deck</param>
        public void ShuffleAndAddUnused(List <Card> cards)
        {
            ExceptionHelpers.CheckNotNull(cards, "cards");

            // this is used when we run out of cards
            // or a player disconnects
            // or something
            for (int ctr = 0; ctr < cards.Count; ctr++)
            {
                // determine where to add cards in deck
                this.deck.Insert(
                    this.rand.Next(this.deck.Count),
                    cards[ctr]);
            }

            return;
        }
Example #11
0
        public void Discard(Card card, Player skipped, Player source)
        {
            Debug.WriteLine("Discarding skip...");
            ExceptionHelpers.CheckNotNull(card, "card");
            ExceptionHelpers.CheckNotNull(skipped, "skipped");
            ExceptionHelpers.CheckNotNull(source, "source");
            ExceptionHelpers.CheckCurrentPlayer(source, this.currentPlayer);

            if (card.Number != CardNumber.Skip)
            {
                throw new ArgumentException("Card is not a skip card!");
            }

            this.discard.AddTopCard(card);
            skipped.SkippedBy(source);

            this.OnPutDiscard(source, card);
            this.OnSkipped(skipped, source);
        }
Example #12
0
        public GameRulesMessage(GameRules gr) : base()
        {
            ExceptionHelpers.CheckNotNull(gr, "gr");

            short length = 20;

            for (int i = 0; i < gr.PhazeRules.Count(); i++)
            {
                length += 1; //group kind
                length += (short)(gr.PhazeRules.Phaze(i).Count() * 2);
            }
            length += (short)(gr.CardPoints.Length * 2); //2 for each card

            msg     = new byte[length];
            msg[0]  = (byte)pxMessages.GameRules;
            msg[1]  = (byte)(gr.MinimumPlayers);
            msg[2]  = (byte)(gr.MaximumPlayers);
            msg[3]  = (byte)(gr.HandCards);
            msg[4]  = (byte)(gr.DeckCards);
            msg[5]  = (byte)(gr.MinimumCardNumber);
            msg[6]  = (byte)(gr.MaximumCardNumber);
            msg[7]  = (byte)(gr.MinimumCardColor);
            msg[8]  = (byte)(gr.MaximumCardColor);
            msg[9]  = (byte)(gr.MinimumGroupType);
            msg[10] = (byte)(gr.MaximumGroupType);

            if (gr.SkipCardsEnabled)
            {
                msg[11] = (byte)1;
            }
            else
            {
                msg[11] = (byte)0;
            }
            if (gr.DrawCardsEnabled)
            {
                msg[12] = (byte)1;
            }
            else
            {
                msg[12] = (byte)0;
            }
            if (gr.ReverseCardsEnabled)
            {
                msg[13] = (byte)1;
            }
            else
            {
                msg[13] = (byte)0;
            }
            if (gr.WildCardsEnabled)
            {
                msg[14] = (byte)1;
            }
            else
            {
                msg[14] = (byte)0;
            }
            if (gr.ExtraSetPlayable)
            {
                msg[15] = (byte)1;
            }
            else
            {
                msg[15] = (byte)0;
            }
            if (gr.AllowWildColor)
            {
                msg[16] = (byte)1;
            }
            else
            {
                msg[16] = (byte)0;
            }
            if (gr.SkipAnybody)
            {
                msg[17] = (byte)1;
            }
            else
            {
                msg[17] = (byte)0;
            }
            if (gr.SkipOncePerHand)
            {
                msg[18] = (byte)1;
            }
            else
            {
                msg[18] = (byte)0;
            }

            msg[19] = (byte)gr.PhazeRules.Count();

            short ptr = 20;

            for (int ctr = 0; ctr < gr.PhazeRules.Count(); ctr++)
            {
                PhazeRule pr = gr.PhazeRules.Phaze(ctr);
                msg[ptr] = (byte)pr.Count();
                ptr     += 1;
                for (int ctr2 = 0; ctr2 < pr.Count(); ctr2++)
                {
                    Group g = pr.GetGroup(ctr2);
                    msg[ptr]     = (byte)g.GroupType;
                    msg[ptr + 1] = (byte)g.CardsRequired;
                    ptr         += 2;
                }
            }

            foreach (int i in gr.CardPoints)
            {
                msg[ptr]     = (byte)(i >> 8);
                msg[ptr + 1] = (byte)(i);
                ptr         += 2;
            }
        }
Example #13
0
        /// <summary>
        /// This player skipped player p. Update the scoreboard
        /// </summary>
        /// <param name="player">Player who this player skipped</param>
        public void Skip(Player player)
        {
            ExceptionHelpers.CheckNotNull(player, "player");

            this.Scoreboard.CurrentSession.AddPlayerSkipped(player.PlayerID);
        }
Example #14
0
 /// <summary>
 /// Adds the card to the top of the discard pile
 /// </summary>
 /// <param name="card">Card to add to the top of the discard pile</param>
 public void AddTopCard(Card card)
 {
     ExceptionHelpers.CheckNotNull(card, "card");
     this.discard.Insert(0, card);
 }
Example #15
0
        /// <summary>
        /// Finds the first card found that has the number and color of the card passed. If null,
        /// returns null. This function actually uses the overloaded function num,col.
        /// </summary>
        /// <param name="card">Card to check</param>
        /// <returns>The card that was found.</returns>
        public Card FindCardWithNumberAndColor(Card card)
        {
            ExceptionHelpers.CheckNotNull(card, "card");

            return(this.FindCardWithNumberAndColor(card.Number, card.Color));
        }
Example #16
0
 public Game(Player player, int computerPlayers)
     : this(computerPlayers)
 {
     ExceptionHelpers.CheckNotNull(player, "player");
     this.AddPlayer(player);
 }
Example #17
0
        public void Validate(GameRules rules)
        {
            ExceptionHelpers.CheckNotNull(rules, "rules");
            if (msg[0] != (byte)pxMessages.Table)
            {
                throw new BadMessageException("Table Message : Message length is invalid");
            }
            if (msg.Length < 2)
            {
                throw new BadMessageException("Table Message : Message does not start with the proper type");
            }

            int tmp;

            tmp = (int)msg[1];
            if (tmp < 0)
            {
                throw new BadMessageException("Table Message : Number of groups field is invalid");
            }
            int num_groups = tmp;
            int pos        = 2;

            for (int ctr = 0; ctr < num_groups; ctr++)
            {
                tmp = (int)msg[pos + 1];
                if ((tmp < rules.MinimumGroupType) || (tmp > rules.MaximumGroupType))
                {
                    throw new BadMessageException("Table Message : Group type field is invalid");
                }
                tmp = (int)msg[pos + 2];
                if ((tmp < 0) || (tmp > rules.HandCards))
                {
                    throw new BadMessageException("Table Message : Cards required field is invalid");
                }
                tmp = (int)msg[pos + 3];
                if ((tmp < 0) || (tmp > rules.DeckCards))
                {
                    throw new BadMessageException("Table Message : Cards in group field is invalid");
                }
                int num_cards = tmp;
                pos += 4;
                for (int ctr2 = 0; ctr2 < num_cards; ctr2++)
                {
                    tmp   = (int)msg[pos];
                    tmp <<= 8;
                    tmp  += (int)msg[pos + 1];
                    if ((tmp < 0) || (tmp > rules.DeckCards))
                    {
                        throw new BadMessageException("Table Message : Card ID field is invalid");
                    }
                    tmp = (int)msg[pos + 2];
                    if ((tmp < (int)rules.MinimumCardColor) || (tmp > (int)rules.MaximumCardColor))
                    {
                        throw new BadMessageException("Table Message : Card color field is invalid");
                    }
                    tmp = (int)msg[pos + 3];
                    if ((tmp < (int)rules.MinimumCardNumber) || (tmp > (int)rules.MaximumCardNumber))
                    {
                        throw new BadMessageException("Table Message : Card number field is invalid");
                    }
                    tmp = (int)msg[pos + 4];
                    if ((tmp != 0) && (tmp != 1))
                    {
                        throw new BadMessageException("Table Message : Card wild field is invalid");
                    }
                    pos += 5;
                }
            }
        }