private void btnPick_Click(object sender, RoutedEventArgs e)
        {
            var selectedOponent = lbUsers.SelectedItem;

            if (selectedOponent == null)
            {
                MessageBox.Show("you need to pick opponent to play with!");
                return;
            }
            string selectedOponentString = (string)selectedOponent;

            try
            {
                bool gameRequestResult = sendRequestForGame(selectedOponentString, currentUser);
                setUsersTextBoxAndPickButtonEnable(false);
                if (gameRequestResult == true)
                {
                    InitGameResult game = initGame(currentUser, selectedOponentString);
                    initGameWindow(GameWindow.Color.Red, game);
                }
                else
                {
                    MessageBox.Show("Player: " + selectedOponentString + " refused to play with you.. :(");
                    setUsersTextBoxAndPickButtonEnable(true);
                }
            }
            catch (FaultException <UserNotFoundFault> ex)
            {
                MessageBox.Show(ex.Detail.Message);
            }
        }
        private InitGameResult initGame(string currentUser, string selectedOponentString)
        {
            Thread         t    = null;
            InitGameResult game = null;

            t = new Thread(() => game = client.InitGame(currentUser, selectedOponentString));
            t.Start();
            t.Join();
            return(game);
        }
        private void initGameWindow(GameWindow.Color Side, InitGameResult game)
        {
            GameWindow gWindow = new GameWindow(Side);

            gWindow.client      = this.client;
            gWindow.Callback    = this.Callback;
            gWindow.currentUser = this.currentUser;
            gWindow.gameId      = game.gameId;
            gWindow.playersInfo = "[ " + game.Player1 + " vs " + game.Player2 + " ]";
            gWindow.Show();
            isClosingFromGui = true;
            this.Close();
        }
 public void sendGameInfo(InitGameResult game)
 {
     SendGameInfoFunc(game);
 }
 // When the player2 accepts the game, wait player1 to init the game and to create game Id
 // and to send it to player2
 // when player2 recieves gameId, Player2 inits the game
 private void RecieveGameInfo(InitGameResult game)
 {
     initGameWindow(GameWindow.Color.Black, game);
 }