Esempio n. 1
0
        private void SendWord_Button_Click(object sender, EventArgs e)
        {
            SendWordRequest request = new SendWordRequest(Utils.Base64Encode(CurrWord_TextBox.Text), Convert.ToInt32(CurrAmount_NumericUpDown.Value));
            Message         res     = new Message();

            try
            {
                res = StreamHelper.Communicate(user.clientStream, RequestCodes.SEND_WORD, request);
            }
            catch (IOException)
            {
                Utils.ConnectionAbortMessageBox();
                Close();
            }
            switch (res.code)
            {
            case ResponseCodes.SEND_WORD_SUCCESS:
                SendWord_Button.Visible = false;
                break;

            case ResponseCodes.INVALID_WORD:
                Utils.ErrorMessageBox("מילה לא חוקית!");
                break;

            case ResponseCodes.INVALID_CARDS_AMOUNT:
                Utils.ErrorMessageBox("כמות לא חוקית!");
                break;

            default:
                break;
            }
        }
Esempio n. 2
0
        private void JoinLobby(string host, int maxPlayers)
        {
            Message res = new Message();

            try
            {
                res = StreamHelper.Communicate(user.clientStream, RequestCodes.JOIN_ROOM, new JoinRoomRequest(host));
            }
            catch (IOException)
            {
                Utils.ConnectionAbortMessageBox();
                Close();
            }
            switch (res.code)
            {
            case ResponseCodes.JOIN_ROOM_SUCCESS:
                OpenLobby(host, maxPlayers);
                break;

            case ResponseCodes.JOIN_ROOM_FAILED:
                ReloadLobbies();
                break;

            default:
                break;
            }
        }
Esempio n. 3
0
        private void ReloadPlayersList()
        {
            Task.Run(() =>
            {
                Message res = new Message();
                try
                {
                    res = StreamHelper.Communicate(user.clientStream, RequestCodes.LOBBY_UPDATES);
                }
                catch (IOException)
                {
                    try
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            Utils.ConnectionAbortMessageBox();
                            Close();
                        });
                    }
                    catch { }
                }
                switch (res.code)
                {
                case ResponseCodes.LOBBY_DELETED:
                    Invoke((MethodInvoker) delegate
                    {
                        Close();
                    });
                    break;

                case ResponseCodes.LOBBY_STARTED:
                    enterGame = true;
                    teams     = JsonConvert.DeserializeObject <StartGameResponse>(res.data);
                    Invoke((MethodInvoker) delegate
                    {
                        Close();
                    });
                    break;

                case ResponseCodes.LOBBY_UPDATE:
                    List <string> players = JsonConvert.DeserializeObject <List <string> >(res.data);
                    try
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            UpdatePlayersPanel(players);
                            PlayersListReload_Timer.Enabled = true;
                        });
                    }
                    catch { }
                    break;

                default:
                    break;
                }
            });
        }
Esempio n. 4
0
 private void DeleteUser()
 {
     try
     {
         StreamHelper.Communicate(user.clientStream, RequestCodes.DELETE_USER);
     }
     catch (IOException)
     {
         Utils.ConnectionAbortMessageBox();
         Close();
     }
 }
Esempio n. 5
0
 private void Logout()
 {
     try
     {
         StreamHelper.Communicate(user.clientStream, RequestCodes.LOGOUT);
     }
     catch (IOException)
     {
         Utils.ConnectionAbortMessageBox();
         Close();
     }
 }
Esempio n. 6
0
 private void StartGame_Button_Click(object sender, EventArgs e)
 {
     StartGame_Button.Enabled = false;
     try
     {
         StreamHelper.Communicate(user.clientStream, RequestCodes.START_GAME);
     }
     catch (IOException)
     {
         Utils.ConnectionAbortMessageBox();
         Close();
     }
 }
Esempio n. 7
0
        private void GameForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            GameUpdates_Timer.Enabled = false;

            try
            {
                StreamHelper.Communicate(user.clientStream, RequestCodes.LEAVE_ROOM);
            }
            catch (IOException)
            {
                Utils.ConnectionAbortMessageBox();
                Close();
            }
        }
Esempio n. 8
0
        private void CreateLobby()
        {
            int maxPlayers = Convert.ToInt32(MaxPlayers_NumericUpDown.Value);

            try
            {
                StreamHelper.Communicate(user.clientStream, RequestCodes.CREATE_ROOM, new CreateRoomRequest(maxPlayers));
            }
            catch (IOException)
            {
                Utils.ConnectionAbortMessageBox();
                Close();
            }
            OpenLobby(user.username, maxPlayers);
        }
Esempio n. 9
0
 private void LobbyForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     PlayersListReload_Timer.Enabled = false;
     if (!enterGame)
     {
         try
         {
             StreamHelper.Communicate(user.clientStream, RequestCodes.LEAVE_ROOM);
         }
         catch (IOException)
         {
             Utils.ConnectionAbortMessageBox();
             Close();
         }
     }
 }
Esempio n. 10
0
        private void GuessWord_Button_Click(object sender, EventArgs e)
        {
            GuessWordRequest request = new GuessWordRequest(chosedWord.r, chosedWord.c);

            chosedWord.BorderStyle   = BorderStyle.FixedSingle;
            ChosenWord_Label.Text    = "";
            GuessWord_Panel.Visible  = false;
            GuessWord_Button.Visible = false;
            chosedWord = null;
            try
            {
                StreamHelper.Communicate(user.clientStream, RequestCodes.REVEAL_CARD, request);
            }
            catch (IOException)
            {
                Utils.ConnectionAbortMessageBox();
                Close();
            }
        }
Esempio n. 11
0
        private void Signup()
        {
            string        username       = SignupUsername_TextBox.Text;
            string        password       = SignupPassword_TextBox.Text;
            SignupMessage signup         = new SignupMessage(username, password);
            Message       signupResponse = new Message();

            try
            {
                signupResponse = StreamHelper.Communicate(clientStream, RequestCodes.SIGNUP, signup);
            }
            catch (IOException)
            {
                Utils.ConnectionAbortMessageBox();
                Close();
            }

            switch (signupResponse.code)
            {
            case ResponseCodes.SIGNUP_SUCCESS:
                LoginToApp(username);
                break;

            case ResponseCodes.SIGNUP_USERNAME_EXISTS:
                SignupErrorMessage_Label.Text = Properties.Resources.USERNAME_ALREADY_EXISTS;
                break;

            case ResponseCodes.SIGNUP_INVALID_USERNAME:
                SignupErrorMessage_Label.Text = Properties.Resources.INVALID_USERNAME;
                break;

            case ResponseCodes.SIGNUP_INVALID_PASSWORD:
                SignupErrorMessage_Label.Text = Properties.Resources.INVALID_PASSWORD;
                break;

            default:
                break;
            }
        }
Esempio n. 12
0
        private void Login()
        {
            string       username      = LoginUsername_TextBox.Text;
            string       password      = LoginPassword_TextBox.Text;
            LoginMessage login         = new LoginMessage(username, password);
            Message      loginResponse = new Message();

            try
            {
                loginResponse = StreamHelper.Communicate(clientStream, RequestCodes.LOGIN, login);
            }
            catch (IOException)
            {
                Utils.ConnectionAbortMessageBox();
                Close();
            }
            switch (loginResponse.code)
            {
            case ResponseCodes.LOGIN_SUCCESS:
                LoginToApp(username);
                break;

            case ResponseCodes.LOGIN_USERNAME_DOESNT_EXISTS:
                LoginErrorMessage_Label.Text = Properties.Resources.USERNAME_DOESNT_EXISTS;
                break;

            case ResponseCodes.LOGIN_WRONG_PASSWORD:
                LoginErrorMessage_Label.Text = Properties.Resources.WRONG_PASSWORD;
                break;

            case ResponseCodes.LOGIN_USER_ACTIVE:
                LoginErrorMessage_Label.Text = Properties.Resources.LOGIN_USER_ACTIVE;
                break;

            default:
                break;
            }
        }
Esempio n. 13
0
 private void ReloadGameState()
 {
     Task.Run(() =>
     {
         GameState gameState = new GameState();
         try
         {
             gameState = StreamHelper.Communicate <GameState>(user.clientStream, RequestCodes.GAME_STATE);
         }
         catch (IOException)
         {
             try
             {
                 Invoke((MethodInvoker) delegate
                 {
                     Utils.ConnectionAbortMessageBox();
                     Close();
                 });
             }
             catch { }
         }
         if (gameState.winner != CardType.NONE)
         {
             GameUpdates_Timer.Enabled = false;
             Utils.RtlMessageBox("המשחק הסתיים! הקבוצה ה" + (gameState.winner == CardType.RED ? "אדומה" : "כחולה") + " ניצחה!", "סוף המשחק", MessageBoxIcon.Information);
             Game_Panel.Enabled = false;
         }
         else if (gameState.deleted)
         {
             GameUpdates_Timer.Enabled = false;
             MessageBox.Show("המשחק נמחק");
             Game_Panel.Enabled = false;
         }
         try
         {
             Invoke((MethodInvoker) delegate
             {
                 if (gameState.turn == CardType.RED)
                 {
                     CurrTurn_Label.Text      = "אדום";
                     CurrTurn_Label.ForeColor = CardColor.REVEALED_RED;
                 }
                 else
                 {
                     CurrTurn_Label.Text      = "כחול";
                     CurrTurn_Label.ForeColor = CardColor.REVEALED_BLUE;
                 }
                 CurrWord_Label.Text   = Utils.Base64Decode(gameState.curr_word);
                 CurrAmount_Label.Text = gameState.curr_revealed.ToString() + "/" + gameState.curr_cards.ToString();
                 for (int r = 0; r < gameState.board.Count; r++)
                 {
                     for (int c = 0; c < gameState.board[r].Count; c++)
                     {
                         board[r][c].Text      = Utils.Base64Decode(gameState.board[r][c].word);
                         board[r][c].revealed  = gameState.board[r][c].revealed;
                         board[r][c].BackColor = CardColor.GetColor(gameState.board[r][c].type, gameState.board[r][c].revealed);
                     }
                 }
                 CurrWord_TextBox.Visible         = gameState.turn == team && gameState.curr_word == "" && manager;
                 CurrWord_Label.Visible           = !CurrWord_TextBox.Visible;
                 CurrAmount_NumericUpDown.Visible = CurrWord_TextBox.Visible;
                 CurrAmount_Label.Visible         = !CurrAmount_NumericUpDown.Visible;
                 SendWord_Button.Visible          = CurrWord_TextBox.Visible;
                 GuessWord_Panel.Visible          = gameState.turn == team && gameState.curr_word != "" && !manager;
                 if (!CurrWord_TextBox.Visible)
                 {
                     CurrWord_TextBox.Text          = "";
                     CurrAmount_NumericUpDown.Value = 1;
                 }
             });
         }
         catch { }
     });
 }
Esempio n. 14
0
 private void ReloadLobbies()
 {
     ReloadLobbies_Button.Enabled = false;
     Lobbies_Panel.AutoScroll     = false;
     Lobbies_Panel.Controls.Clear();
     Task.Run(() =>
     {
         List <GameRoom> lobbies = new List <GameRoom>();
         try
         {
             lobbies = StreamHelper.Communicate <List <GameRoom> >(user.clientStream, RequestCodes.LIST_ROOMS);
         }
         catch (IOException)
         {
             try
             {
                 Invoke((MethodInvoker) delegate
                 {
                     Utils.ConnectionAbortMessageBox();
                     Close();
                 });
             }
             catch { }
         }
         int y = 20;
         foreach (GameRoom room in lobbies)
         {
             Label host_TextBox = new Label()
             {
                 Text = room.host, Location = new Point(20, y)
             };
             Label players_TextBox = new Label()
             {
                 Text = room.curr_players.ToString() + "/" + room.max_players.ToString(), Location = new Point(150, y)
             };
             JoinGameButton joinRoom_Button = new JoinGameButton(room.host, room.max_players)
             {
                 Text = "Join", Location = new Point(290, y)
             };
             joinRoom_Button.Click += JoinRoom_Button_Click;
             try
             {
                 Invoke((MethodInvoker) delegate
                 {
                     Lobbies_Panel.Controls.Add(host_TextBox);
                     Lobbies_Panel.Controls.Add(players_TextBox);
                     Lobbies_Panel.Controls.Add(joinRoom_Button);
                 });
             }
             catch { }
             y += 40;
         }
         try
         {
             Invoke((MethodInvoker) delegate
             {
                 Lobbies_Panel.AutoScroll     = true;
                 ReloadLobbies_Button.Enabled = true;
             });
         }
         catch { }
     });
 }