Ejemplo n.º 1
0
        private void spectate_button_Click(object sender, RoutedEventArgs e)
        {
            Boolean isSpectable = BL.spectateGame(this.user.ID, game_box.Text);

            BL.game choosenGame = BL.getGameByID(game_box.Text);
            if (choosenGame != null && isSpectable)
            {
                game g = new game(BL, choosenGame, user);
                g.Show();

                this.Close();
            }
            else
            {
                MessageBox.Show("Can't join this game");
            }
        }
Ejemplo n.º 2
0
        private void ok_button_Click(object sender, RoutedEventArgs e)
        {
            if (ok_button.Content.Equals("search"))
            {
                games_table.ItemsSource = null;
                games_table.Visibility  = System.Windows.Visibility.Visible;

                LinkedList <string> can_join = new LinkedList <string>();
                DataTable           dt       = new DataTable();

                //create table dynamically
                dt.Columns.Add("game id", typeof(string));
                dt.Columns.Add("buy in", typeof(string));
                dt.Columns.Add("avilable sets", typeof(string));


                if (search_by_pot_size.IsSelected)
                {
                    int pot_size;
                    pot_size = int.Parse(game_box.Text);
                    can_join = BL.searchGamesByPotSize(pot_size);
                }
                else if (search_by_player_name.IsSelected)
                {
                    can_join = BL.searchGamesByPlayerName(game_box.Text);
                }
                else if (search_by_prefs.IsSelected)
                {
                    can_join = null;
                }
                else if (joinable_list.IsSelected)
                {
                    can_join = BL.listOfJoinableGames(this.user.ID);
                }
                else if (spectatable_list.IsSelected)
                {
                    can_join = BL.listOfSpectatableGames();
                }

                if (can_join == null)
                {
                    MessageBox.Show("Can't find any games");
                }
                else
                {
                    string[] oneRow = new string[3];
                    int      index  = 0;
                    //add rows
                    foreach (string i_game in can_join)
                    {
                        oneRow[index] = i_game;
                        index++;
                        if (index > 2)
                        {
                            index = 0;
                            dt.Rows.Add(oneRow[0], oneRow[1], oneRow[2]);
                        }
                    }
                }

                games_table.ItemsSource = dt.DefaultView;
            }
            else if (ok_button.Content.Equals("join"))
            {
                bool    canJoin     = BL.joinGame(game_box.Text, this.user.ID);
                BL.game choosenGame = BL.getGameByID(game_box.Text);
                if (choosenGame != null && canJoin)
                {
                    game g = new game(BL, choosenGame, user);
                    g.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Can't join this game");
                }
            }
        }
        private void create_button_Click(object sender, RoutedEventArgs e)
        {
            String   gameID = "";
            int      limit, buyIN, chipPolicy, minBet, minPlayers, MaxPlayers;
            bool     spectatable = false, leaguable = false;
            GameType type = GameType.POT_LIMIT;

            try
            { limit = int.Parse(limit_textBox.Text); }
            catch { limit = 0; }
            try
            { buyIN = int.Parse(buyIn_textBox.Text); }
            catch { buyIN = 0; }
            try
            { chipPolicy = int.Parse(chipPolicy_textBox.Text); }
            catch { chipPolicy = 0; }
            try
            { minBet = int.Parse(minBet_textBox.Text); }
            catch { minBet = 0; }
            try
            { minPlayers = int.Parse(minPlayers_textBox.Text); }
            catch { minPlayers = 2; }
            try
            { MaxPlayers = int.Parse(maxPlayers_textBox.Text); }
            catch { MaxPlayers = 8; }
            if (spectatable_comboBox.SelectedIndex == 0)
            {
                spectatable = true;
            }
            if (leaguable_comboBox.SelectedIndex == 0)
            {
                leaguable = true;
            }
            if (comboBox.SelectedIndex == 0)
            {
                type = GameType.LIMIT;
            }
            if (comboBox.SelectedIndex == 1)
            {
                type = GameType.NO_LIMIT;
            }

            if (isCreate)
            {
                gameID = BL.createGame(user.ID, type, limit, buyIN, chipPolicy, minBet, minPlayers, MaxPlayers, spectatable, leaguable, this.user.league);
                if (gameID == null)
                {
                    MessageBox.Show("error \n one or more of the parameters is invalid");
                }

                BL.game game = BL.getGameByID(gameID);
                game    g    = new game(BL, game, user);
                g.Show();
                this.Close();
            }
            else
            {
                LinkedList <string> prefsGames;
                prefsGames = BL.searchGameByPrefs(type, limit, buyIN, chipPolicy, minBet, minPlayers, MaxPlayers, spectatable, leaguable, this.user.league);
                if (prefsGames == null)
                {
                    prefsGames = new LinkedList <string>();
                    prefsGames.AddLast("none");
                }
                gameCenter GC = new gameCenter(BL, user, prefsGames);
                GC.Show();
                this.Close();
            }
        }