示例#1
0
        public override void OnInit(string gameStarter, string[] userlist, string[] param)
        {
            _super = param[0] == "superuno"; // Check if playing Uno or SuperUno

            _state = new State(
                delegate(string tx) { SendOut(tx); },
                delegate(string tg, string tx) { SendOut(tg, tx); },
                _super
            );

            _inState = InputState.Recruit;
            _timeoutState = TimeoutState.InactiveWarn1;

            _top = _state.DrawDeck.Draw();
            _state.DiscardPile.Add(_top);

            Player ps = _state.Players.Add(gameStarter);

            SetTopic(Messages.TopicRecruit);
            SendOut(String.Format(Messages.OutGameStart, ps, Name));
        }
示例#2
0
        private void PlayerPlayCardProcess(Player p, Card c, bool wtf)
        {
            bool showUno = p.Hand.Count != 1; // to avoid showing "__ has uno!" twice

            // Preparing to call play effect
            _state.NextInState = InputState.Turn;
            _state.NextTopCard = c;
            _state.NextTurnPush = 1;

            if (c is WtfCard) {
                Card wtfc;
                Random r = new Random();
                int pick = r.Next(6);
                if (pick == 0) {
                    // 1/48 chance (1/6 * 1/8) of the card becoming ASDF
                    wtfc = AsdfCard.FromWtf();
                    if (wtfc == null) pick = r.Next(5) + 1; // Didn't happen - go for another card
                }
                if (pick == 1) wtfc = WildCard.FromWtf();
                else if (pick == 2) wtfc = WildDrawFourCard.FromWtf();
                else if (pick == 3) wtfc = WildMassDrawThreeCard.FromWtf();
                else if (pick == 4) wtfc = SuperWildDrawFourCard.FromWtf();
                else wtfc = ReverseWildDrawFourCard.FromWtf();

                PlayerPlayCardProcess(p, wtfc, true);
                return;
            } else {
                c.OnPlay(_state, p);
            }

            // Check if player won
            if (HasPlayerWon(p, showUno)) return;

            // Check and apply results
            _inState = _state.NextInState;
            if (_state.NextTopCard != null) _top = _state.NextTopCard;
            if (_state.NextTurnPush > 0) {
                _disableDraw = false;
                _state.Players.PushTurn(_state.NextTurnPush);
                DisplayTurn(true);
            }
        }
示例#3
0
        private void PlayerPlayCommand(Player p, Card c)
        {
            if (!p.Hand.Contains(c)) {
                SendOut(p + ": " + Messages.PlayFailHand);
                return;
            }

            if (!c.Matches(_top)) {
                SendOut(p + ": " + Messages.PlayFailMatch);
                return;
            }

            // Card in parameter is a placeholder - get the actual object
            c = p.Hand.FirstOrDefault(hc => hc == c);

            p.Score += c.Score;
            p.Hand.Remove(c);

            // With some exceptions, make the card available again
            if (!(c.Face == CardFace._E || c.Face == CardFace._D || c.Face == CardFace.DH))
                _state.DiscardPile.Add(c);

            // Check if player won
            if (HasPlayerWon(p)) return;

            // Move on to card processing
            PlayerPlayCardProcess(p, c, false);
            ResetTick();
        }
示例#4
0
        private void PlayerDrawCommand(Player p)
        {
            if (_disableDraw) {
                SendOut(p + ": " + Messages.DrawFail);
                return;
            }
            _disableDraw = true;

            bool effect;
            Card c;

            // Determine which deck to draw from
            effect = ((new Random()).Next(_state.DrawDeck.Count + _state.DrawEffectDeck.Count) + 1) > _state.DrawDeck.Count;

            if (effect) {
                // Effect card
                c = _state.DrawEffectDeck.Draw();
            } else {
                // Normal card
                c = _state.DrawDeck.Draw(1, _state.DiscardPile)[0];
            }

            p.Hand.Add(c); // card may remove itself if it must
            if (!effect) SendOut(p.Nick, String.Format(Messages.DealCard, c));
            else {
                // Preparing to call draw effect
                _state.NextInState = InputState.Turn;
                _state.NextTopCard = null;
                _state.NextTurnPush = 0;

                c.OnDraw(_state, p);

                // Check if player won
                if (HasPlayerWon(p)) return;

                // Check and apply results
                _inState = _state.NextInState;
                if (_state.NextTopCard != null) _top = _state.NextTopCard;
                if (_state.NextTurnPush > 0) {
                    _disableDraw = false;
                    _state.Players.PushTurn(_state.NextTurnPush);
                    DisplayTurn(true);
                }
            }
        }