예제 #1
0
        protected virtual void DealGame()
        {
            // shuffle the draw pile
            DrawPile.Shuffle(Randomizer);

            if (Config.ShufflePlayerList)
            {
                Pile <Player> .Shuffle(Players, Randomizer);
            }

            // distribute the cards
            foreach (var player in Players)
            {
                var drawnCards = DrawCards(Config.InitialDealSize);
                player.Hand.UnionWith(drawnCards);
            }

            // draw one card and discard it; this will be our top card
            var newTopCard = DrawCard();

            if (newTopCard.Color == CardColor.Wild)
            {
                // it's a wild card; give it a fixed color at random
                newTopCard = new Card((CardColor)Randomizer.Next(0, 4), newTopCard.Value);
            }
            DiscardPile.Push(newTopCard);

            CurrentGameState = GameState.InProgress;

            // we're getting ready to start!
            BroadcastAnchorCardsDealtEvent();

            // start a new turn!
            StartNewTurn();
        }
예제 #2
0
        public UnoGameMasterPlugin(IConnectionManager connMgr, JObject config)
        {
            ConnectionManager = connMgr;
            Config            = new GameMasterConfig(config);

            AttackMode           = false;
            ExtremeMode          = false;
            DrawPile             = new Pile <Card>();
            DiscardPile          = new Pile <Card>();
            Players              = new List <Player>();
            CurrentPlayerIndex   = 0;
            PlayerOrderReversed  = false;
            DrewLast             = true;
            CurrentGameState     = GameState.NoGame;
            TurnStartedUtc       = null;
            TurnTickTimer        = new Timer(TurnTickTimerElapsed, null, TimeSpan.Zero, TimeSpan.FromSeconds(1));
            TurnLock             = new object();
            Randomizer           = new Random();
            BotTestCount         = 0;
            BotTestJoinRequested = null;

            ConnectionManager.NickChange      += HandleNickChange;
            ConnectionManager.UserLeftChannel += HandleUserLeftChannel;
            ConnectionManager.UserQuitServer  += HandleUserQuitServer;

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("uno"),
                    CommandUtil.MakeOptions(
                        CommandUtil.MakeFlag("+a"),
                        CommandUtil.MakeFlag("+e")
                        ),
                    CommandUtil.NoArguments,
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleUnoCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("play", "p"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker, // color or wildcard value
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker  // value or change-to-color
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandlePlayCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("bottest"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        new LongMatcher().ToRequiredWordTaker() // number of rounds
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleBotTestCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("join", "botjoin"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleJoinCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("leave"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleLeaveCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("deal"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleDealCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("draw"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleDrawCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("pass"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandlePassCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("endgame"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleEndGameCommand
                );
        }