Skip to content

Commit

Permalink
new features and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekeris committed Aug 26, 2020
1 parent f889b86 commit 50d2f92
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 58 deletions.
Binary file modified .vs/Slovo/v16/.suo
Binary file not shown.
34 changes: 18 additions & 16 deletions Slovo/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 78 additions & 41 deletions Slovo/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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));
}
}
}

Expand All @@ -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);
}
}
}
1 change: 0 additions & 1 deletion Slovo/Packets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ServerSecretPacket
public byte[] Secret;
public Guid guid;
public bool GameRun;
public StartPacket sp;
}

[Serializable]
Expand Down
Binary file modified Slovo/bin/Debug/Slovo.exe
Binary file not shown.
Binary file modified Slovo/bin/Debug/Slovo.pdb
Binary file not shown.
Binary file modified Slovo/obj/Debug/Slovo.csproj.GenerateResource.cache
Binary file not shown.
Binary file modified Slovo/obj/Debug/Slovo.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified Slovo/obj/Debug/Slovo.exe
Binary file not shown.
Binary file modified Slovo/obj/Debug/Slovo.pdb
Binary file not shown.

0 comments on commit 50d2f92

Please sign in to comment.