public partial class Form1 : Form
{
int c = 0, d = 0, a = 0, b = 0, f = 0, g = 0;
int rndmoney1 = 100;
int rndmoney2 = 100;
int rndmoney3 = 100;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
d = c % 3;
button1.Text = c.ToString();
if (c >= rndmoney1)
{
timer1.Enabled = false;
}
if (d == 0)
{
button1.BackColor = System.Drawing.Color.FromName("RED");
}
else if (d == 1)
{
button1.BackColor = System.Drawing.Color.FromName("Green");
}
else if (d == 2)
{
button1.BackColor = System.Drawing.Color.FromName("Yellow");
}
}
private void button4_Click(object sender, EventArgs e)
{
Random rnd = new Random();
rndmoney1 = rnd.Next(1, 11);
rndmoney2 = rnd.Next(1, 11);
rndmoney3 = rnd.Next(1, 11);
timer1.Enabled = true;
timer2.Enabled = true;
timer3.Enabled = true;
c = 0;
a = 0;
f = 0;
}
private void timer2_Tick(object sender, EventArgs e)
{
a = a + 1;
b = a % 3;
button2.Text = a.ToString();
if (a >= rndmoney2)
{
timer2.Enabled = false;
}
if (b == 0)
{
button2.BackColor = System.Drawing.Color.FromName("Yellow");
}
else if (b == 1)
{
button2.BackColor = System.Drawing.Color.FromName("RED");
}
else if (b == 2)
{
button2.BackColor = System.Drawing.Color.FromName("Green");
}
}
private void timer3_Tick(object sender, EventArgs e)
{
f = f + 1;
g = f % 3;
button3.Text = f.ToString();
if (f >= rndmoney3)
{
timer3.Enabled = false;
}
if (g == 0)
{
button3.BackColor = System.Drawing.Color.FromName("Green");
}
else if (g == 1)
{
button3.BackColor = System.Drawing.Color.FromName("Yellow");
}
else if (g == 2)
{
button3.BackColor = System.Drawing.Color.FromName("Red");
}
}
private void timer4_Tick(object sender, EventArgs e)
{
button4.Text = "Start ";
if (button3.BackColor == button2.BackColor && button3.BackColor == button1.BackColor && button1.BackColor == button2.BackColor)
{
button5.Text = "WIN ";
}
else
{
button5.Text = "Defult ";
}
}
private void button5_Click(object sender, EventArgs e)
{
}
}
}
4個timer
沒有留言:
張貼留言