예제 #1
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 { }
     });
 }
예제 #2
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 { }
     });
 }