Exemple #1
0
        private void PlayersOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            ProtocolProcess.RequestGameSettings();
            PlayerListText.Invoke((MethodInvoker)(() => PlayerListText.Text = ""));
            foreach (var item in ProtocolProcess.Players)
            {
                PlayerListText.Invoke((MethodInvoker)(() =>
                {
                    if (PlayerListText.Lines.Length > 0)
                    {
                        PlayerListText.AppendText(Environment.NewLine);
                    }

                    try
                    {
                        PlayerListText.SelectionStart = PlayerListText.TextLength;
                        PlayerListText.SelectedRtf = item.DisplayName;
                    }
                    catch (Exception)
                    {
                        // This is near-impossible to happen as of 05/10/2021, but
                        // if somehow someone in the future manages to break rtf,
                        // this line will send it through directly
                        PlayerListText.AppendText($"{item.DisplayName}");
                    }
                    finally
                    {
                        PlayerListText.AppendText($"({item.Score})");
                    }
                }));
            }
        }
Exemple #2
0
        private void CreateGameButton_Click(object sender, EventArgs e)
        {
            CG_PlayerNameText.Text = CG_PlayerNameText.Text ?? defaultGamerName_Alt;
            CG_GameNameText.Text   = CG_GameNameText.Text ?? $"{CG_PlayerNameText.Text}'s Game";
            try
            {
                ProtocolProcess.SetSettings(
                    Math.Max(int.Parse(CG_GameSizeText.Text) - 1, 0),
                    int.Parse(CG_RefreshTimeText.Text),
                    int.Parse(CG_PointsRedText.Text),
                    int.Parse(CG_PointsBlueText.Text),
                    int.Parse(CG_PointsYellowText.Text),
                    int.Parse(CG_WinPointText.Text),
                    int.Parse(CG_PanelWidthText.Text),
                    int.Parse(CG_PanelHeightText.Text)
                    );
                ProtocolProcess.CreateGame(CG_AddressText.Text, int.Parse(CG_PortText.Text), CG_GameNameText.Text);
                ProtocolProcess.StartServer();
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to create game using desired settings, aborting!");
                return;
            }

            EnterGame(CG_AddressText.Text, int.Parse(CG_PortText.Text), CG_PlayerNameText.Text, true);
        }
Exemple #3
0
 private void SendMessage()
 {
     if (MessageInputText.Text != "")
     {
         ProtocolProcess.SendMessage(MessageInputText.Text, PlayerSetting.Username);
         MessageInputText.Text = "";
     }
 }
Exemple #4
0
        private async void EnterGame(string address, int port, string username, bool isHost)
        {
            StatusLabel.Visible   = true;
            StatusLabel.Text      = "Attempting Connection...";
            StatusLabel.ForeColor = SystemColors.ControlText;
            try
            {
                await ProtocolProcess.CreatePlayer(address, port);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                StatusLabel.Text      = "Unable to connect";
                StatusLabel.ForeColor = Color.Red;
                return;
            }
            ProtocolProcess.StartClient();
            PlayerSetting.Username = username;
            PlayerSetting.IsHost   = isHost;
            // If we are the host, we use RichTextFormatting to append bold-casing to our displayName.
            // This makes it easier for others in the lobby to visually see who is the host and who are the other players.
            //
            // Forseeably, this implementation can be used for nickname support, but would require more checks to prevent abuse.
            RtfBuilder builder = new RtfBuilder();

            if (isHost)
            {
                PlayerSetting.DisplayName = builder.AppendBold(username).ToRtf();
            }
            else
            {
                PlayerSetting.DisplayName = builder.Append(username).ToRtf();
            }
            ProtocolProcess.JoinGame(PlayerSetting.Username, PlayerSetting.DisplayName);

            StatusLabel.Visible = false;
            Hide();
            if (GamePanel == null)
            {
                // TODO: Manual Leaving caused me a lot of stress, and it just wasn't wanting to work with me.
                // Application.Exit() is able to do this job for now, but would need to be fixed later
                //
                // In this case, Manual Leaving requires Show to instead be ShowDialog + returning a dialog result in GamePanel_FormClosing
                // in order to provide the expected behavior. This note is mentioned here in case I decide to try it again.
                GamePanel = new GamePanel();
                GamePanel.Show();
            }
        }
Exemple #5
0
 private void GamePanel_Load(object sender, EventArgs e)
 {
     Text = $"{Text} ({GameServer.GameAddress}:{GameServer.GamePort})";
     PlayerNameLabel.Text       = PlayerSetting.Username + (PlayerSetting.IsHost ? " (Host)" : "");
     MessageInputText.MaxLength = GameServer.SizeLimit / 2;
     ProtocolProcess.RequestGameSettings();
     ProtocolProcess.OnGameSettingsReceivedEvent += delegate(object o, GameSettingsReceivedEvent ev)
     {
         if (ev.GameSettings != null)
         {
             GameNameText.Invoke((MethodInvoker)(() => GameNameText.Text = ev.GameSettings.GameName));
             PlayerCountLabel.Invoke((MethodInvoker)(() => PlayerCountLabel.Text = $"PLAYERS ({ev.GameSettings.CurrentPlayers}/{ev.GameSettings.GameSize})"));
             StartGameButton.Invoke((MethodInvoker)(() => StartGameButton.Visible = PlayerSetting.IsHost && !ev.GameSettings.GameInProgress));
             PointsRedText.Invoke((MethodInvoker)(() => PointsRedText.Text = ev.GameSettings.DefaultPointValues[0].ToString()));
             PointsBlueText.Invoke((MethodInvoker)(() => PointsBlueText.Text = ev.GameSettings.DefaultPointValues[1].ToString()));
             PointsYellowText.Invoke((MethodInvoker)(() => PointsYellowText.Text = ev.GameSettings.DefaultPointValues[2].ToString()));
             RefreshTimeText.Invoke((MethodInvoker)(() => RefreshTimeText.Text = ev.GameSettings.Timer));
             WinPointText.Invoke((MethodInvoker)(() => WinPointText.Text = ev.GameSettings.Win));
             // TODO: This line would allow for dynamic panel sizing, perhaps figure out the best way to implement this someday?
             // Invoke((MethodInvoker)(() => this.Size = new Size(ev.GameSettings.PanelSize.X, ev.GameSettings.PanelSize.Y)));
         }
     };
 }
Exemple #6
0
 private void GP_ViewPort_MouseClick(object sender, MouseEventArgs e)
 {
     ProtocolProcess.SendClickCoords(e.X, e.Y);
 }
Exemple #7
0
 private void StartGameButton_Click(object sender, EventArgs e)
 {
     ProtocolProcess.StartGame();
 }