C#
紅綠燈
紅燈五秒
綠燈三秒
黃燈兩秒
public partial class Form1 : Form
{
int a = 0, b = 5, c = 3, d = 0, g = 0;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
g = g + 1;
a = g % 10;
if (a <= 4)
{
button1.BackColor = System.Drawing.Color.Red;
button2.BackColor = System.Drawing.Color.Red;
b = b - 1;
button2.Text = b.ToString();
}
else
{
button1.BackColor = System.Drawing.Color.Black;
button2.BackColor = System.Drawing.Color.Black;
b = 5;
}
if (a >4 && a <=7)
{
button4.BackColor = System.Drawing.Color.Green;
button2.BackColor = System.Drawing.Color.Green;
c = c - 1;
button2.Text = c.ToString();
}
else
{
button4.BackColor = System.Drawing.Color.Black;
c = 3;
}
if (a >= 8 && a<=9 )
{
button3.BackColor = System.Drawing.Color.Yellow;
}
else
{
button3.BackColor = System.Drawing.Color.Black;
}
}