Exemple #1
0
        void Cmd_Draw(string nick, string message)
        {
            Channel    channel = p_manager.GetChannel();
            UnoChannel uno     = GetUnoChannel(channel.GetName());
            UnoPlayer  player  = uno != null?uno.GetPlayer(nick) : null;

            if (player == null || !uno.is_active)
            {
                E.Notice(nick, "You are not part of an UNO game.");
                return;
            }

            if (uno.current_player != nick && !uno.CheckMode(UnoMode.LIGRETTO))
            {
                E.Notice(nick, "It is not your turn (current: " + uno.current_player + ").");
                return;
            }

            var drawn = player.DrawCards(Math.Max(1, uno.draw_count));

            uno.draw_count = 0;
            E.Notice(nick, "You drew following cards: " + FormatCards(drawn));

            uno.TurnNext();
            TellGameStatus(channel);
        }
Exemple #2
0
        void Cmd_Put(string nick, string message)
        {
            Channel    channel = p_manager.GetChannel();
            UnoChannel uno     = GetUnoChannel(channel.GetName());
            UnoPlayer  player  = uno != null?uno.GetPlayer(nick) : null;

            if (player == null || !uno.is_active)
            {
                E.Notice(nick, "huh?? You don't have any cards.");
                return;
            }

            if (uno.current_player != nick && !uno.CheckMode(UnoMode.LIGRETTO))
            {
                E.Notice(nick, "It is not your turn (current: " + uno.current_player + ").");
                return;
            }
            uno.current_player = nick;             // UnoMode.LIGRETTO

            string    put_color_s = Chatcommand.GetNext(ref message).ToUpper();
            CardColor put_color   = CardColor.NONE;
            string    put_face    = Chatcommand.GetNext(ref message).ToUpper();

            if (put_color_s.Length >= 2)
            {
                // The following format: "gwd4", "g4"
                put_face    = put_color_s.Substring(1);
                put_color_s = put_color_s.Remove(1);
            }

            // Convert user input to internal format
            switch (put_color_s)
            {
            case "B": put_color = CardColor.BLUE; break;

            case "R": put_color = CardColor.RED; break;

            case "G": put_color = CardColor.GREEN; break;

            case "Y": put_color = CardColor.YELLOW; break;
            }

            bool change_face = false;

            if (put_face.Contains("W"))
            {
                // Convert/validate W and WD4
                change_face = true;
            }
            if (put_color == CardColor.NONE ||
                !card_faces.Contains(put_face))
            {
                E.Notice(nick, "Invalid input. Syntax: $uno p <color> <face>, $p <color><face>.");
                return;
            }

            // Check whether color of face matches
            if (put_color != uno.top_card.Key &&
                put_face != uno.top_card.Value &&
                !change_face)
            {
                E.Notice(nick, "This card cannot be played. Please check color and face.");
                return;
            }

            int card_index = -1;

            if (change_face)
            {
                card_index = player.cards.FindIndex(item => item.Value == put_face);
            }
            else
            {
                card_index = player.cards.FindIndex(
                    item => item.Key == put_color && item.Value == put_face);
            }

            if (card_index < 0)
            {
                E.Notice(nick, "You don't have this card.");
                return;
            }

            if (uno.draw_count > 0)
            {
                bool ok = false;
                if (put_face == "D2" &&
                    put_face == uno.top_card.Value &&                             // No downgrade
                    uno.CheckMode(UnoMode.STACK_D2))
                {
                    ok = true;
                }
                else if (put_face == "WD4" &&
                         put_face == uno.top_card.Value &&
                         uno.CheckMode(UnoMode.STACK_WD4))
                {
                    ok = true;
                }
                else if (put_face == "WD4" &&
                         uno.top_card.Value == "D2" &&
                         uno.CheckMode(UnoMode.UPGRADE))
                {
                    ok = true;
                }

                if (!ok)
                {
                    E.Notice(nick, "You cannot play this card due to the top card.");
                    return;
                }
            }

            // All OK. Put the card on top
            uno.top_card = new Card(put_color, put_face);
            player.cards.RemoveAt(card_index);

            bool pending_autodraw = false;

            switch (put_face)
            {
            case "D2":
                uno.draw_count  += 2;
                pending_autodraw = !uno.CheckMode(UnoMode.STACK_D2);
                break;

            case "WD4":
                uno.draw_count  += 4;
                pending_autodraw = !uno.CheckMode(UnoMode.STACK_WD4);
                break;

            case "R":
                if (uno.players.Count > 2)
                {
                    uno.players.Reverse();
                }
                else
                {
                    uno.TurnNext();                     // Acts as Skip for 2 players
                }
                break;

            case "S": uno.TurnNext(); break;
            }

            uno.TurnNext();

            // Player won, except when it's again their turn (last card = skip)
            if (player.cards.Count == 0 && uno.current_player != player.name)
            {
                uno.RemovePlayer(channel, player.name);
            }

            if (CheckGameEndDelete(channel.GetName()))
            {
                return;                 // Game ended
            }
            if (pending_autodraw)
            {
                Cmd_Draw(uno.current_player, "");
            }
            else
            {
                TellGameStatus(channel);
            }
        }