コード例 #1
0
        private async void btnJoinGame_Click(object sender, RoutedEventArgs e)
        {
            List <KeyValuePair <string, int> > preferenceList = new List <KeyValuePair <string, int> >();
            KeyValuePair <string, int>         gameType       = new KeyValuePair <string, int>("gameType", GetGameType());
            KeyValuePair <string, int>         minPlayers     = new KeyValuePair <string, int>("minPlayers", GetMinPlayers());
            KeyValuePair <string, int>         maxPlayers     = new KeyValuePair <string, int>("maxPlayers", GetMaxPlayers());
            KeyValuePair <string, int>         minBet         = new KeyValuePair <string, int>("minBet", GetMinBet());
            KeyValuePair <string, int>         chipPolicy     = new KeyValuePair <string, int>("chipPolicy", GetChipPolicy());
            KeyValuePair <string, int>         spectateGame   = new KeyValuePair <string, int>("spectateGame", GetSpectateGame());
            KeyValuePair <string, int>         buyIn          = new KeyValuePair <string, int>("buyIn", GetBuyIn());

            preferenceList.Add(gameType);
            preferenceList.Add(minPlayers);
            preferenceList.Add(maxPlayers);
            preferenceList.Add(minBet);
            preferenceList.Add(chipPolicy);
            preferenceList.Add(spectateGame);
            preferenceList.Add(buyIn);

            ReplyInt accept;

            try
            {
                accept = await Client.CreateGame(preferenceList);

                if (!accept.Sucsses)
                {
                    MessageBox.Show(accept.ErrorMessage, "Warning");
                }
                else
                {
                    int gameID   = accept.IntContent;
                    int playerID = 1;
                    if (!UserControlTabs.firstInitiate)
                    {
                        (UserControlTabs.userControlTabs.tabControl.SelectedItem as TabItem).Header = "Active Game";
                        TabItem newTabItem = new TabItem();
                        newTabItem.Header = "Menu";
                        Menu newMenu = new Menu();
                        newMenu.btnLogout.Visibility = Visibility.Hidden;
                        newTabItem.Content           = newMenu;
                        UserControlTabs.userControlTabs.tabControl.Items.Add(newTabItem);
                        UserControlGame game = new UserControlGame(gameID, playerID);
                        this.Content = game;
                    }
                    else
                    {
                        UserControlTabs.firstInitiate   = false;
                        UserControlTabs.userControlTabs = new UserControlTabs();
                        UserControlTabs.userControlTabs.firstTab.Content = new UserControlGame(gameID, playerID);
                        UserControlTabs.userControlTabs.firstTab.Header  = "Active Game";
                        this.Content = UserControlTabs.userControlTabs;
                    }
                }
            }
            catch (HttpRequestException exception)
            {
                MessageBox.Show(exception.Message, "Warning");
            }
        }
コード例 #2
0
        private async void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row    = sender as DataGridRow;
            int         i      = row.GetIndex();
            int         gameID = results[i].GameID;
            int         playerID;
            ReplyInt    accept;

            try
            {
                accept = await Client.JoinGame(gameID);

                if (!accept.Sucsses)
                {
                    MessageBox.Show(accept.ErrorMessage, "Warning");
                }
                else
                {
                    playerID = accept.IntContent;
                    if (!UserControlTabs.firstInitiate)
                    {
                        (UserControlTabs.userControlTabs.tabControl.SelectedItem as TabItem).Header = "Active Game";
                        TabItem newTabItem = new TabItem();
                        newTabItem.Header = "Menu";
                        Menu newMenu = new Menu();
                        newMenu.btnLogout.Visibility = Visibility.Hidden;
                        newTabItem.Content           = newMenu;
                        UserControlTabs.userControlTabs.tabControl.Items.Add(newTabItem);
                        UserControlGame game = new UserControlGame(gameID, playerID);
                        this.Content = game;
                    }
                    else
                    {
                        UserControlTabs.firstInitiate   = false;
                        UserControlTabs.userControlTabs = new UserControlTabs();
                        UserControlTabs.userControlTabs.firstTab.Content = new UserControlGame(gameID, playerID);
                        UserControlTabs.userControlTabs.firstTab.Header  = "Active Game";
                        this.Content = UserControlTabs.userControlTabs;
                    }
                }
            }
            catch (HttpRequestException exception)
            {
                MessageBox.Show(exception.Message, "Warning");
            }
        }