Пример #1
0
        public GameForm(User user, StartGameResponse teams)
        {
            InitializeComponent();

            this.user  = user;
            Text       = user.username;
            chosedWord = null;
            board      = new List <List <CardLabel> >();
            for (int r = 0; r < 5; r++)
            {
                board.Add(new List <CardLabel>());
                for (int c = 0; c < 5; c++)
                {
                    CardLabel cardLabel = new CardLabel(r, c)
                    {
                        BorderStyle = BorderStyle.FixedSingle,
                        Margin      = new Padding(3),
                        Size        = new Size(104, 61),
                        TextAlign   = ContentAlignment.MiddleCenter,
                        Location    = new Point(202 + 110 * c, 13 + 67 * r)
                    };
                    cardLabel.Click += CardLabel_Click;
                    board[r].Add(cardLabel);
                    Game_Panel.Controls.Add(cardLabel);
                }
            }
            Utils.AddTextsToPanel(RedPlayers_Panel, teams.reds);
            Utils.AddTextsToPanel(BluePlayers_Panel, teams.blues);
            team    = teams.reds.Contains(user.username) ? CardType.RED : CardType.BLUE;
            manager = (team == CardType.RED ? teams.reds : teams.blues)[0] == user.username;
        }
Пример #2
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;
                }
            });
        }