{
byte[] lotoNumbers = new byte[6];
byte[] guess = new byte[6];
bool status;
public Form1()
{
InitializeComponent();
}
private void Exit_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void Form1_Load(object sender, EventArgs e)
{
status = false;
Results.Visible = false;
}
private void showResult_Click(object sender, EventArgs e)
{
if (!status)
{
MessageBox.Show("There is not any numbers generated!");
return;
}
byte buffer = 0;
#region Tahmin 1
if (byte.TryParse(g1.Text, out buffer))
if (byte.Parse(g1.Text) < 50)
guess[0] = byte.Parse(g1.Text);
else
{
g1.Text = null;
MessageBox.Show("Please enter a value smaller then 50!");
guess[0] = 0;
return;
}
else
{
g1.Text = null;
MessageBox.Show("Please enter a valid value to first field!");
return;
}
#endregion
#region Tahmin 2
if (byte.TryParse(g2.Text, out buffer))
if (byte.Parse(g2.Text) < 50)
guess[1] = byte.Parse(g2.Text);
else
{
g2.Text = null;
MessageBox.Show("Please enter a value smaller then 50!");
guess[1] = 0;
return;
}
else
{
g2.Text = null;
MessageBox.Show("Please enter a valid value to second field!");
return;
}
#endregion
#region Tahmin 3
if (byte.TryParse(g3.Text, out buffer))
if (byte.Parse(g3.Text) < 50)
guess[2] = byte.Parse(g3.Text);
else
{
g3.Text = null;
MessageBox.Show("Please enter a value smaller then 50!");
guess[2] = 0;
return;
}
else
{
g3.Text = null;
MessageBox.Show("Please enter a valid value to third field!");
return;
}
#endregion
#region Tahmin 4
if (byte.TryParse(g4.Text, out buffer))
if (byte.Parse(g4.Text) < 50)
guess[3] = byte.Parse(g4.Text);
else
{
g4.Text = null;
MessageBox.Show("Please enter a value smaller then 50!");
guess[3] = 0;
return;
}
else
{
g4.Text = null;
MessageBox.Show("Please enter a valid value to fourth field!");
return;
}
#endregion
#region Tahmin 5
if (byte.TryParse(g5.Text, out buffer))
if (byte.Parse(g5.Text) < 50)
guess[4] = byte.Parse(g5.Text);
else
{
g5.Text = null;
MessageBox.Show("Please enter a value smaller then 50!");
guess[4] = 0;
return;
}
else
{
g5.Text = null;
MessageBox.Show("Please enter a valid value to fifth field!");
return;
}
#endregion
#region Tahmin 6
if (byte.TryParse(g6.Text, out buffer))
if (byte.Parse(g6.Text) < 50)
guess[5] = byte.Parse(g6.Text);
else
{
g6.Text = null;
MessageBox.Show("Please enter a value smaller then 50!");
guess[5] = 0;
return;
}
else
{
g6.Text = null;
MessageBox.Show("Please enter a valid value to sixth field!");
return;
}
#endregion
byte result = 0;
for (int i = 0; i < lotoNumbers.Length; i++)
if (guess[i] == lotoNumbers[i])
result++;
Results.Visible = true;
Result.Text = result + " adet sayı tutturdunuz!";
}
private void calculate_Click(object sender, EventArgs e)
{
Random generate = new Random();
for (byte i = 0; i < lotoNumbers.Length; i++)
{
lotoNumbers[i] = Convert.ToByte(generate.Next(50));
}
//GroupBox assignments
{
loto1.Text = lotoNumbers[0].ToString();
loto2.Text = lotoNumbers[1].ToString();
loto3.Text = lotoNumbers[2].ToString();
loto4.Text = lotoNumbers[3].ToString();
loto5.Text = lotoNumbers[4].ToString();
loto6.Text = lotoNumbers[5].ToString();
}
status = true;
}
private void Restart_Click(object sender, EventArgs e)
{
Results.Visible = false;
g1.Text = null;
g2.Text = null;
g3.Text = null;
g4.Text = null;
g5.Text = null;
g6.Text = null;
for (int i = 0; i < lotoNumbers.Length; i++)
{
lotoNumbers[i] = 0;
guess[i] = 0;
}
g1.Select();
}
Hiç yorum yok:
Yorum Gönder