primero necesitaremos los siguientes elementos
codigo del programa
public partial class casino : Form
{
int c = 0, n1 =0,n2=0,n3=0,n4=0;
Random objeto = new
Random();
public casino()
{
InitializeComponent();
}
private void
be_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer2.Enabled = true;
timer3.Enabled
= true;
timer4.Enabled = true;
be.Enabled = false;
button2.Enabled = true;
c
= 0;
}
private void
timer1_Tick(object sender, EventArgs e)
{
n1 = objeto.Next(0, 10);// n1=9
t1.Text = Convert.ToString(n1);//n1 = "9"
}
private void
timer2_Tick(object sender, EventArgs e)
{
n2 = objeto.Next(0, 10);// n2=9
t2.Text = Convert.ToString(n2);//n2 = "9"
}
private void
timer3_Tick(object sender, EventArgs e)
{
n3 = objeto.Next(0, 10);// n3=9
t3.Text = Convert.ToString(n3);//n3 = "9"
}
private void
timer4_Tick(object sender, EventArgs e)
{
n4 = objeto.Next(0, 10);// n4=9
t4.Text = Convert.ToString(n4);//n4 = "9"
}
private void
button2_Click(object sender, EventArgs e)
{
c++;
if (c == 1) timer1.Enabled = false;
if (c == 2) timer2.Enabled = false;
if (c == 3) timer3.Enabled = false;
if (c == 4)
{
timer4.Enabled = false;
be.Enabled = true;
button2.Enabled = false;
if ((n1 == n2) && (n2 == n3)
&& (n3 == n4))
{
MessageBox.Show("Ganaste", "felicidades",
MessageBoxButtons.OK);
}
else
{
MessageBox.Show("Perdiste", "Sigue
participando", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void
button1_Click(object sender, EventArgs e)
{
if (MessageBox.Show(" Deseas salir ", "Salir", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
MessageBox.Show("Ud decidio salir", "adios", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
this.Close();
}
else
{
MessageBox.Show("Ud decidio no salir", "...");
}
}
private void
casino_Load(object sender, EventArgs e)
{
}
}
el resultado será el siguiente
No hay comentarios.:
Publicar un comentario