diff --git a/.vs/Slovo/v16/.suo b/.vs/Slovo/v16/.suo index b8d0f6a..3833054 100644 Binary files a/.vs/Slovo/v16/.suo and b/.vs/Slovo/v16/.suo differ diff --git a/Slovo/Form1.Designer.cs b/Slovo/Form1.Designer.cs index ea2b104..407f1ae 100644 --- a/Slovo/Form1.Designer.cs +++ b/Slovo/Form1.Designer.cs @@ -127,7 +127,7 @@ private void InitializeComponent() // ClientsList // this.ClientsList.FormattingEnabled = true; - this.ClientsList.Location = new System.Drawing.Point(12, 144); + this.ClientsList.Location = new System.Drawing.Point(12, 146); this.ClientsList.Name = "ClientsList"; this.ClientsList.Size = new System.Drawing.Size(196, 290); this.ClientsList.TabIndex = 9; @@ -137,17 +137,19 @@ private void InitializeComponent() // this.MessageTextBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.MessageTextBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource; - this.MessageTextBox.Location = new System.Drawing.Point(214, 414); + this.MessageTextBox.Location = new System.Drawing.Point(214, 416); this.MessageTextBox.Name = "MessageTextBox"; this.MessageTextBox.Size = new System.Drawing.Size(411, 20); this.MessageTextBox.TabIndex = 10; + this.MessageTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MessageTextBox_KeyDown); + this.MessageTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MessageTextBox_KeyPress); // // SendButton // this.SendButton.Enabled = false; - this.SendButton.Location = new System.Drawing.Point(714, 412); + this.SendButton.Location = new System.Drawing.Point(714, 415); this.SendButton.Name = "SendButton"; - this.SendButton.Size = new System.Drawing.Size(75, 23); + this.SendButton.Size = new System.Drawing.Size(75, 22); this.SendButton.TabIndex = 11; this.SendButton.Text = "Send"; this.SendButton.UseVisualStyleBackColor = true; @@ -156,9 +158,9 @@ private void InitializeComponent() // AcceptButton // this.AcceptButton.Enabled = false; - this.AcceptButton.Location = new System.Drawing.Point(631, 382); + this.AcceptButton.Location = new System.Drawing.Point(631, 386); this.AcceptButton.Name = "AcceptButton"; - this.AcceptButton.Size = new System.Drawing.Size(75, 23); + this.AcceptButton.Size = new System.Drawing.Size(75, 22); this.AcceptButton.TabIndex = 12; this.AcceptButton.Text = "Accept"; this.AcceptButton.UseVisualStyleBackColor = true; @@ -167,9 +169,9 @@ private void InitializeComponent() // DeclineButton // this.DeclineButton.Enabled = false; - this.DeclineButton.Location = new System.Drawing.Point(714, 382); + this.DeclineButton.Location = new System.Drawing.Point(714, 386); this.DeclineButton.Name = "DeclineButton"; - this.DeclineButton.Size = new System.Drawing.Size(75, 23); + this.DeclineButton.Size = new System.Drawing.Size(75, 22); this.DeclineButton.TabIndex = 13; this.DeclineButton.Text = "Decline"; this.DeclineButton.UseVisualStyleBackColor = true; @@ -178,7 +180,7 @@ private void InitializeComponent() // WordTextBox // this.WordTextBox.BackColor = System.Drawing.SystemColors.Control; - this.WordTextBox.Location = new System.Drawing.Point(632, 356); + this.WordTextBox.Location = new System.Drawing.Point(632, 359); this.WordTextBox.Name = "WordTextBox"; this.WordTextBox.ReadOnly = true; this.WordTextBox.Size = new System.Drawing.Size(156, 20); @@ -186,7 +188,7 @@ private void InitializeComponent() // // pictureBox1 // - this.pictureBox1.Location = new System.Drawing.Point(632, 350); + this.pictureBox1.Location = new System.Drawing.Point(632, 353); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(156, 6); this.pictureBox1.TabIndex = 15; @@ -251,18 +253,18 @@ private void InitializeComponent() // this.AutoAcceptCheckBox.AutoSize = true; this.AutoAcceptCheckBox.Enabled = false; - this.AutoAcceptCheckBox.Location = new System.Drawing.Point(632, 327); + this.AutoAcceptCheckBox.Location = new System.Drawing.Point(632, 330); this.AutoAcceptCheckBox.Name = "AutoAcceptCheckBox"; this.AutoAcceptCheckBox.Size = new System.Drawing.Size(85, 17); this.AutoAcceptCheckBox.TabIndex = 22; - this.AutoAcceptCheckBox.Text = "Auto Aceept"; + this.AutoAcceptCheckBox.Text = "Auto Accept"; this.AutoAcceptCheckBox.UseVisualStyleBackColor = true; // // RetryButton // - this.RetryButton.Location = new System.Drawing.Point(631, 411); + this.RetryButton.Location = new System.Drawing.Point(631, 415); this.RetryButton.Name = "RetryButton"; - this.RetryButton.Size = new System.Drawing.Size(75, 23); + this.RetryButton.Size = new System.Drawing.Size(75, 22); this.RetryButton.TabIndex = 23; this.RetryButton.Text = "Retry"; this.RetryButton.UseVisualStyleBackColor = true; @@ -303,12 +305,12 @@ private void InitializeComponent() this.Controls.Add(this.label1); this.Controls.Add(this.PortTextBox); this.Controls.Add(this.IpTextBox); - this.MinimumSize = new System.Drawing.Size(16, 277); + this.MaximumSize = new System.Drawing.Size(816, 485); + this.MinimumSize = new System.Drawing.Size(816, 485); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.Click += new System.EventHandler(this.Form1_Click); - this.Resize += new System.EventHandler(this.Form1_Resize); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Slovo/Form1.cs b/Slovo/Form1.cs index acfd2a0..ed4306b 100644 --- a/Slovo/Form1.cs +++ b/Slovo/Form1.cs @@ -123,14 +123,18 @@ await Task.Run(async () => if (ssp.GameRun) { - //Action action = () => - //{ - // StartButton_Click(null, null); - // GMComboBox.SelectedIndex = ssp.sp.GameMode; - // GMComboBox.Enabled = false; - // TemplateTextBox.Text = ssp.sp.Template; - //}; - //Invoke(action); + Action action = () => + { + GMComboBox.Enabled = false; + StartButton.Enabled = false; + TemplateTextBox.ReadOnly = true; + TemplateTextBox.BackColor = Color.White; + AutoAcceptCheckBox.Enabled = true; + GameStarted = true; + SyncHistoryButton.Enabled = true; + SendButtonCheck(); + }; + Invoke(action); } } else if (packet is HistoryPacket hp) @@ -268,7 +272,6 @@ private Task ServerMonitor() Action action = () => { ClientsList.Items.Add(user); - ssp.sp = new StartPacket(GMComboBox.SelectedIndex, TemplateTextBox.Text); }; Invoke(action); user.SendObject(ssp); @@ -487,45 +490,70 @@ private async void HostButton_Click(object sender, EventArgs e) socket.Close(); } - private void SendButton_Click(object sender, EventArgs e) + private async void SendButton_Click(object sender, EventArgs e) { + bool sent = false; bool find = false; bool correct = false; - if (HistoryListBox.Items.Count > 0) + if ((GMComboBox.SelectedIndex == 0) && (HistoryListBox.Items.Count > 0)) { - if (GMComboBox.SelectedIndex == 0) + for (int i = HistoryListBox.Items.Count - 1; i >= 0; i--) { - for (int i = HistoryListBox.Items.Count - 1; i >= 0; i--) + if (((MessagePacket) HistoryListBox.Items[i]).Res == "Accepted") { - if (((MessagePacket) HistoryListBox.Items[i]).Res == "Accepted") - { - find = true; - string word = ((MessagePacket) HistoryListBox.Items[i]).Word; - if (char.ToLower(MessageTextBox.Text.ToCharArray()[0]) == char.ToLower(word.ToCharArray()[word.Length - 1])) - correct = true; - break; - } + find = true; + string word = ((MessagePacket) HistoryListBox.Items[i]).Word; + if (char.ToLower(MessageTextBox.Text.ToCharArray()[0]) == char.ToLower(word.ToCharArray()[word.Length - 1])) + correct = true; + break; } } - else if (GMComboBox.SelectedIndex == 1) - correct = MessageTextBox.Text.StartsWith(TemplateTextBox.Text); - else - correct = MessageTextBox.Text.EndsWith(TemplateTextBox.Text); } + else if (GMComboBox.SelectedIndex == 1) + correct = MessageTextBox.Text.StartsWith(TemplateTextBox.Text); + else if (GMComboBox.SelectedIndex == 2) + correct = MessageTextBox.Text.EndsWith(TemplateTextBox.Text); - if (correct || (!find && (GMComboBox.SelectedIndex == 0))) + if ((MessageTextBox.TextLength > 0) && (correct || (!find && (GMComboBox.SelectedIndex == 0)))) { if (!IAmServer) localUser.SendObject(AesEncryption.Encryption(new QuestionPacket(MessageTextBox.Text))); else ((User) ClientsList.Items[1]).SendObject(AesEncryption.Encryption(new QuestionPacket(MessageTextBox.Text, !HistoryDict.ContainsKey(MessageTextBox.Text)))); MessageTextBox.Text = ""; - label1.Text = "true"; + sent = true; } - else + if (!sent) { - label1.Text = "false"; + await Task.Run(() => + { + int i = 0; + Point p = new Point(0, 0); + Action change = () => + { + p = SendButton.Location; + SendButton.BackColor = Color.Red; + SendButton.FlatStyle = FlatStyle.Popup; + }; + Action move = () => + { + SendButton.Location = new Point(SendButton.Location.X + Convert.ToInt32(Math.Sin(i)), SendButton.Location.Y); + }; + Action back = () => + { + SendButton.BackColor = Color.FromArgb(225, 225, 225); + SendButton.FlatStyle = FlatStyle.Standard; + SendButton.Location = p; + }; + Invoke(change); + for (i = 0; i < 20; i++) + { + Invoke(move); + Thread.Sleep(40); + } + Invoke(back); + }); } } @@ -578,12 +606,6 @@ private void PortTextBox_KeyPress(object sender, KeyPressEventArgs e) } } - private void NameTextBox_KeyPress(object sender, KeyPressEventArgs e) - { - if ((((TextBox) sender).TextLength > 16) || (e.KeyChar == '@')) - e.Handled = true; - } - private void GMComboBox_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = true; @@ -621,17 +643,11 @@ private void ClientsList_KeyDown(object sender, KeyEventArgs e) ClientsList.SelectedIndex = -1; } - private void Form1_Resize(object sender, EventArgs e) - { - ClientsList.Height = Height - 194; - } - private void StartButton_Click(object sender, EventArgs e) { if (ClientsList.Items.Count > 1) { GMComboBox.Enabled = false; - StartButton.Enabled = false; TemplateTextBox.ReadOnly = true; TemplateTextBox.BackColor = Color.White; AutoAcceptCheckBox.Enabled = true; @@ -640,7 +656,10 @@ private void StartButton_Click(object sender, EventArgs e) SendButtonCheck(); if (IAmServer) + { + StartButton.Enabled = false; ServerSendAllUsersPacket(new StartPacket(GMComboBox.SelectedIndex, TemplateTextBox.Text)); + } } } @@ -661,5 +680,23 @@ private void GMComboBox_SelectedIndexChanged(object sender, EventArgs e) { TemplateTextBox.Enabled = GMComboBox.SelectedIndex != 0; } + + private void MessageTextBox_KeyPress(object sender, KeyPressEventArgs e) + { + if (!char.IsLetter(e.KeyChar) && (e.KeyChar != 8)) + e.Handled = true; + } + + private void NameTextBox_KeyPress(object sender, KeyPressEventArgs e) + { + if (((((TextBox) sender).TextLength > 16) || (e.KeyChar == '@')) && (e.KeyChar != 8)) + e.Handled = true; + } + + private void MessageTextBox_KeyDown(object sender, KeyEventArgs e) + { + if ((e.KeyValue == 13) && SendButton.Enabled) + SendButton_Click(null, null); + } } } diff --git a/Slovo/Packets.cs b/Slovo/Packets.cs index 4ab63ff..ebcddc5 100644 --- a/Slovo/Packets.cs +++ b/Slovo/Packets.cs @@ -21,7 +21,6 @@ class ServerSecretPacket public byte[] Secret; public Guid guid; public bool GameRun; - public StartPacket sp; } [Serializable] diff --git a/Slovo/bin/Debug/Slovo.exe b/Slovo/bin/Debug/Slovo.exe index b20dc75..944449a 100644 Binary files a/Slovo/bin/Debug/Slovo.exe and b/Slovo/bin/Debug/Slovo.exe differ diff --git a/Slovo/bin/Debug/Slovo.pdb b/Slovo/bin/Debug/Slovo.pdb index 41ba2ca..34a5287 100644 Binary files a/Slovo/bin/Debug/Slovo.pdb and b/Slovo/bin/Debug/Slovo.pdb differ diff --git a/Slovo/obj/Debug/Slovo.csproj.GenerateResource.cache b/Slovo/obj/Debug/Slovo.csproj.GenerateResource.cache index fc52b37..8e3f5e8 100644 Binary files a/Slovo/obj/Debug/Slovo.csproj.GenerateResource.cache and b/Slovo/obj/Debug/Slovo.csproj.GenerateResource.cache differ diff --git a/Slovo/obj/Debug/Slovo.csprojAssemblyReference.cache b/Slovo/obj/Debug/Slovo.csprojAssemblyReference.cache index 73a41a3..c962903 100644 Binary files a/Slovo/obj/Debug/Slovo.csprojAssemblyReference.cache and b/Slovo/obj/Debug/Slovo.csprojAssemblyReference.cache differ diff --git a/Slovo/obj/Debug/Slovo.exe b/Slovo/obj/Debug/Slovo.exe index b20dc75..944449a 100644 Binary files a/Slovo/obj/Debug/Slovo.exe and b/Slovo/obj/Debug/Slovo.exe differ diff --git a/Slovo/obj/Debug/Slovo.pdb b/Slovo/obj/Debug/Slovo.pdb index 41ba2ca..34a5287 100644 Binary files a/Slovo/obj/Debug/Slovo.pdb and b/Slovo/obj/Debug/Slovo.pdb differ