Ejemplo n.º 1
0
        private void StartGame(object state)
        {
            try
            {
                CreateClientThreadArguments args   = (CreateClientThreadArguments)state;
                ClientHelperBridge          client = args.client;

                BaseWcfClient wcfClient = new BaseWcfClient(client);
                ServerDetails result    = wcfClient.Initialize(args.address, args.port);
                if (result.CanConnect || args.spectate)
                {
                    if (result.Game != args.game)
                    {
                        args.game = result.Game;

                        Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action <CreateClientThreadArguments>(UpdateClient), args);
                    }
                    GuiHelper guiHelper = ((ClientHelperDecorator)wcfClient.ConcreteClient).FindWrappedHelper <GuiHelper>();
                    // don't pass the server wait handle when the player plays alone
                    if (args.isSinglePlayer)
                    {
                        guiHelper.Initialize(wcfClient, !args.spectate, null);
                    }
                    else
                    {
                        guiHelper.Initialize(wcfClient, !args.spectate, waitHandle);
                    }

                    if (args.spectate)
                    {
                        if (!wcfClient.RequestSpectation())
                        {
                            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(CantSpectate));
                        }
                    }
                    else
                    {
                        wcfClient.Connect();
                    }

                    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action <CreateClientThreadArguments>(DidConnect), args);
                    //wcfClient.Run();
                    //wcfClient.Disconnect();
                }
                else
                {
                    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(GameInProgress));
                }
            }
            catch (Exception e)
            {
                Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action <Exception>(NotifyError), e);
            }
        }
Ejemplo n.º 2
0
        private void DidConnect(CreateClientThreadArguments threadArgs)
        {
            ConfigurationAccess.Current.ServerConfiguration.Port    = ServerPort;
            ConfigurationAccess.Current.ServerConfiguration.Address = ServerAddress;


            if (singlePlayer.IsChecked.Value || (!create.IsChecked.Value))
            {
                setTimer          = new DispatcherTimer();
                setTimer.Interval = TimeSpan.FromSeconds(1);
                setTimer.Tick    += new EventHandler(setTimer_Tick);
                setTimer.Start();
            }
        }
Ejemplo n.º 3
0
        private void UpdateClient(CreateClientThreadArguments args)
        {
            switch (args.game)
            {
            case ServerGame.FiveCardDraw: args.client.FiveCardHelper = new FiveGameDrawClient(new FiveCardGuiHelper(new FiveCardDrawGuiClient(args.rulesBridge))); break;

            case ServerGame.OmahaHoldem: args.client.ClientHelper = new OmahaHoldemClient(new GuiHelper(new TexasHoldemGuiClient(args.rulesBridge, 4))); break;

            case ServerGame.SevenCardStud: args.client.ClientHelper = new GameClient <SevenCardStudGame>(new GuiHelper(new ConcreteHelper(args.rulesBridge))); break;
            }
            args.rulesBridge.Interpreter = (IRulesInterpreter)args.client.ClientHelper;
            args.client.NotifyConnectedToServer(null);
            args.client.NotifyRunningGame(args.game, 0);
        }
Ejemplo n.º 4
0
        internal void Connect()
        {
            //prev.IsEnabled = false;
            //finish.IsEnabled = false;

            CreateClientThreadArguments args        = new CreateClientThreadArguments();
            ClientHelperBridge          bridge      = new ClientHelperBridge();
            RulesInterpreterBridge      rulesBridge = new RulesInterpreterBridge();

            bridge.ClientHelper     = new GameClient <TexasHoldem>(new GuiHelper(new TexasHoldemGuiClient(rulesBridge, 2)));
            rulesBridge.Interpreter = (IRulesInterpreter)bridge.ClientHelper;

            args.address        = ServerAddress;
            args.port           = ServerPort;
            args.client         = bridge;
            args.rulesBridge    = rulesBridge;
            args.game           = ServerGame.TexasHoldem;
            args.spectate       = spectate.IsChecked.Value && multiplayer.IsChecked.Value;
            args.isSinglePlayer = singlePlayer.IsChecked.Value;

            ThreadPool.QueueUserWorkItem(StartGame, args);
        }