コード例 #1
0
 private void whisper_Click(object sender, RoutedEventArgs e)
 {
     this.Game = BL.getGameByID(Game.GameID);
     if (Game.spectators.Count > 0)
     {
         spectatorMessage SM = new spectatorMessage(BL, Game.GameID, user.ID, Game.spectators);
         SM.Show();
     }
     else
     {
         MessageBox.Show("there isn't avilable spectator in the game for chat");
     }
 }
コード例 #2
0
        private void updateGame()
        {
            this.Game = BL.getGameByID(Game.GameID);
            this.Dispatcher.Invoke((Action)(() =>
            {//this refer to form in WPF application
                if (this.Game.isThereWinners)
                {
                    string messageWinner = "";
                    int i = 1;
                    foreach (KeyValuePair <player, int> p in Game.winnersToAmount)
                    {
                        messageWinner += i + ": " + p.Key.user.UserName + " Got: " + p.Value + "$\n";
                        i++;
                    }
                    MessageBox.Show(messageWinner, "We Have Winners", MessageBoxButton.OK, MessageBoxImage.Information);
                    Game.isThereWinners = false;
                    Game.winnersToAmount = new Dictionary <player, int>();
                }
                updateTableCards();
                updatePlayers();
                cashOnTheTable.Text = "cash: " + this.Game.cashOnTheTable + "$";
                updateChat();

                foreach (player currentPlayer in this.Game.activePlayers)
                {
                    if (currentPlayer.user.ID == this.Game.CurrentPlayer)
                    {
                        if (currentPlayer.user.ID != user.ID)
                        {
                            now_playing.Text = "now playing: " + currentPlayer.user.UserName;
                        }
                        else
                        {
                            now_playing.Text = "now playing: Me";
                        }
                        break;
                    }
                }

                my_first_card.Background = new ImageBrush();
                my_second_card.Background = new ImageBrush();
                foreach (player myPlayer in this.Game.activePlayers)
                {
                    if (myPlayer.user.ID == this.user.ID)
                    {
                        updateMyCards(myPlayer);
                        break;
                    }
                }
            }));
        }
コード例 #3
0
 public game(businessLayer bl, BL.game Game, User user)
 {
     InitializeComponent();
     this.BL   = bl;
     this.Game = Game;
     this.user = user;
     isMaked   = false;
     InitializeAvatrsImages();
     InitializeCardsImages();
     InitializePlayersComponents();
     this.labelName.Content = this.user.UserName;
     newThread = new Thread(new ThreadStart(Run));
     newThread.Start();
 }
コード例 #4
0
        /**
         * PLAYERS = "*PLAYER USER NAME* "{0,n}
         * CARDS = "*CARD NUMBER* *CARD TYPE* "{0,n}
         * GAME FULL DETAILS= "GameID=*ID*&players=*PLAYERS*&activePlayers=*PLAYERS*&blindBit=*NUMBER*&CurrentPlayer=*PLAYER USER NAME*&
         * table=*CARDS*&MaxPlayers=*NUMBER*&activePlayersNumber=*NUMBER*&cashOnTheTable=*NUMBER*&CurrentBet=*NUMBER*"
         * GAME PREF = gameTypePolicy=*GAME TYPE POLICY*&potLimit=*POT LIMIT*&buyInPolicy=*BUY IN POLICY*&chipPolicy=*CHIP POLICY*&minBet=*MIN BET*&minPlayersNum=*MIN PLAY NUM*&maxPlayersNum=*MAX PLAYER NUMBER*&spectatable=*T/F*&leaguable=*T/F*&league=*NUNBER*
         * @param request is string that has this format: "CREATEGAME *USER NAME* *GAME PREF*"
         * @return "CREATEGAME *USER NAME* DONE *GAME FULL DETAILS*", "CREATEGAME FAILED" else
         */
        public void createdGame(string msg)
        {
            msg = msg.Substring(0, msg.Length - 2);
            if (msg.Contains("CREATEGAME") && msg.Contains("DONE"))
            {
                String   part2   = msg.Substring(msg.IndexOf("DONE ") + "DONE ".Length);
                string[] msgs    = part2.Split('&');
                game     newGame = new game();
                //    Console.WriteLine(extractString(part2, "players="));
                //    Console.WriteLine(extractString2(msgs, "players="));
                string players = extractString2(msgs, "players=");
                LinkedList <player> playerss = extractPlayers(players);
                players = extractString2(msgs, "activePlayers=");
                LinkedList <player> activePlayers = extractPlayers(players);
                card[] table = extractCards(extractString2(msgs, "table="));

                newGame.GameID        = extractString2(msgs, "GameID=");
                newGame.players       = playerss;
                newGame.activePlayers = activePlayers;
                string blindBitS = extractString2(msgs, "blindBit=");
                newGame.blindBit      = Int32.Parse(extractString2(msgs, "blindBit="));
                newGame.CurrentPlayer = extractString2(msgs, "CurrentPlayer=");
                newGame.table         = table;
                if (table != null)
                {
                    newGame.cardsOnTable = table.Length;
                }
                else
                {
                    newGame.cardsOnTable = 0;
                }
                blindBitS              = extractString2(msgs, "MaxPlayers=");
                newGame.MaxPlayers     = Int32.Parse(extractString2(msgs, "MaxPlayers="));
                blindBitS              = extractString2(msgs, "cashOnTheTable=");
                newGame.cashOnTheTable = Int32.Parse(extractString2(msgs, "cashOnTheTable="));
                blindBitS              = extractString2(msgs, "CurrentBet=");
                newGame.CurrentBet     = Int32.Parse(extractString2(msgs, "CurrentBet="));
                this.games.AddFirst(newGame);
                this.recived = newGame.GameID;
                isDone       = 1;
            }

            else
            {
                isDone = 2;
            }
        }
コード例 #5
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");
            }
        }
コード例 #6
0
 /**
  *
  * @param request is string that has this format: "LEAVEGAME *GAME ID* *USER NAME*"
  * @return "LEAVEGAME *GAME ID* *USER NAME* DONE" if succeed to leave, "LEAVEGAME *GAME ID* *USER NAME* FAILED *MSG*" else
  */
 public bool leaveGame(String GameID, String UserID)
 {
     getGameByID(GameID).isWaitingForLeaving = 0;
     if (CL.send("LEAVEGAME " + GameID + " " + UserID + "\n"))
     {
         game currentGame = getGameByID(GameID);
         while (currentGame.isWaitingForLeaving == 0)
         {
             ;
         }
         if (currentGame.isWaitingForLeaving == 1)
         {
             return(true);
         }
         return(false);
     }
     return(false);
 }
コード例 #7
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");
                }
            }
        }
コード例 #8
0
        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();
            }
        }