using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace bai4_tr47_dkdengiaothong
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int x;
        private void delay_ms(int delayms)
        {
            x = 0;
            do
            {
                Application.DoEvents();
            }
            while (x < (delayms / 100));
            Application.DoEvents();
        }
        int a = 0;
        private void button_bangtay_Click(object sender, EventArgs e)
        {
            button_tudong.Enabled = true;
            button_batdau.Enabled = false;
            button_tat.Enabled = false;
            textBox_xanh.ReadOnly = true;
            textBox_vang.ReadOnly = true;
            textBox_do.ReadOnly = true;
            button_xanh.Enabled = true;
            button_vang.Enabled = true;
            button_do.Enabled = true;
           a = 2;          
        }

        private void button_xanh_Click(object sender, EventArgs e)
        {
            xanh1.BackColor = Color.Green;
            xanh2.BackColor = Color.DarkGray;
            xanh3.BackColor = Color.DarkGray;
            xanh4.BackColor = Color.Green;
            vang1.BackColor = Color.DarkGray;
            vang2.BackColor = Color.DarkGray;
            vang3.BackColor = Color.DarkGray;
            vang4.BackColor = Color.DarkGray;
            do1.BackColor = Color.DarkGray;
            do2.BackColor = Color.Red;
            do3.BackColor = Color.Red;
            do4.BackColor = Color.DarkGray;
        }

        private void button_vang_Click(object sender, EventArgs e)
        {
            if(xanh1.BackColor == Color.Green)
            {
                xanh1.BackColor = Color.DarkGray;
                xanh2.BackColor = Color.DarkGray;
                xanh3.BackColor = Color.DarkGray;
                xanh4.BackColor = Color.DarkGray;
                vang1.BackColor = Color.Yellow;
                vang2.BackColor = Color.DarkGray;
                vang3.BackColor = Color.DarkGray;
                vang4.BackColor = Color.Yellow;
                do1.BackColor = Color.DarkGray;
                do2.BackColor = Color.Red;
                do3.BackColor = Color.Red;
                do4.BackColor = Color.DarkGray;               
            }
            if(xanh2.BackColor == Color.Green)
            {
                xanh1.BackColor = Color.DarkGray;
                xanh2.BackColor = Color.DarkGray;
                xanh3.BackColor = Color.DarkGray;
                xanh4.BackColor = Color.DarkGray;
                vang1.BackColor = Color.DarkGray;
                vang2.BackColor = Color.Yellow;
                vang3.BackColor = Color.Yellow;
                vang4.BackColor = Color.DarkGray;
                do1.BackColor = Color.Red;
                do2.BackColor = Color.DarkGray;
                do3.BackColor = Color.DarkGray;
                do4.BackColor = Color.Red;
            }

        }

        private void button_do_Click(object sender, EventArgs e)
        {
            xanh1.BackColor = Color.DarkGray;
            xanh2.BackColor = Color.Green;
            xanh3.BackColor = Color.Green;
            xanh4.BackColor = Color.DarkGray;
            vang1.BackColor = Color.DarkGray;
            vang2.BackColor = Color.DarkGray;
            vang3.BackColor = Color.DarkGray;
            vang4.BackColor = Color.DarkGray;
            do1.BackColor = Color.Red;
            do2.BackColor = Color.DarkGray;
            do3.BackColor = Color.DarkGray;
            do4.BackColor = Color.Red;
        }

        private void button_tudong_Click(object sender, EventArgs e)
        {
            button_bangtay.Enabled = true;
            button_batdau.Enabled = true;
            button_tat.Enabled = true;
            textBox_xanh.ReadOnly = false;
            textBox_vang.ReadOnly = false;
            textBox_do.ReadOnly = false;
            button_xanh.Enabled = false;
            button_vang.Enabled = false;
            button_do.Enabled = false;
        }
        private void button_tat_Click(object sender, EventArgs e)
        {
            button_tudong.Enabled = true;                    
            textBox_xanh.ReadOnly = true;
            textBox_vang.ReadOnly = true;
            textBox_do.ReadOnly = true;          
            a = 2;
            xanh1.BackColor = Color.DarkGray;
            xanh2.BackColor = Color.DarkGray;
            xanh3.BackColor = Color.DarkGray;
            xanh4.BackColor = Color.DarkGray;
            vang1.BackColor = Color.DarkGray;
            vang2.BackColor = Color.DarkGray;
            vang3.BackColor = Color.DarkGray;
            vang4.BackColor = Color.DarkGray;
            do1.BackColor = Color.DarkGray;
            do2.BackColor = Color.DarkGray;
            do3.BackColor = Color.DarkGray;
            do4.BackColor = Color.DarkGray;
           
        }
        private void button_batdau_Click(object sender, EventArgs e)
        {
            try
            {
                int x = 1000 * int.Parse(textBox_xanh.Text.ToString());
                int v = 1000 * int.Parse(textBox_vang.Text.ToString());
                int d = 1000 * int.Parse(textBox_do.Text.ToString());
                a = 0;
                while (a < 1)
                {
                    xanh1.BackColor = Color.Green;
                    xanh2.BackColor = Color.DarkGray;
                    xanh3.BackColor = Color.DarkGray;
                    xanh4.BackColor = Color.Green;
                    vang1.BackColor = Color.DarkGray;
                    vang2.BackColor = Color.DarkGray;
                    vang3.BackColor = Color.DarkGray;
                    vang4.BackColor = Color.DarkGray;
                    do1.BackColor = Color.DarkGray;
                    do2.BackColor = Color.Red;
                    do3.BackColor = Color.Red;
                    do4.BackColor = Color.DarkGray;
                    delay_ms(x);
                    xanh1.BackColor = Color.DarkGray;
                    xanh2.BackColor = Color.DarkGray;
                    xanh3.BackColor = Color.DarkGray;
                    xanh4.BackColor = Color.DarkGray;
                    vang1.BackColor = Color.Yellow;
                    vang2.BackColor = Color.DarkGray;
                    vang3.BackColor = Color.DarkGray;
                    vang4.BackColor = Color.Yellow;
                    do1.BackColor = Color.DarkGray;
                    do2.BackColor = Color.Red;
                    do3.BackColor = Color.Red;
                    do4.BackColor = Color.DarkGray;
                    delay_ms(v);
                    xanh1.BackColor = Color.DarkGray;
                    xanh2.BackColor = Color.Green;
                    xanh3.BackColor = Color.Green;
                    xanh4.BackColor = Color.DarkGray;
                    vang1.BackColor = Color.DarkGray;
                    vang2.BackColor = Color.DarkGray;
                    vang3.BackColor = Color.DarkGray;
                    vang4.BackColor = Color.DarkGray;
                    do1.BackColor = Color.Red;
                    do2.BackColor = Color.DarkGray;
                    do3.BackColor = Color.DarkGray;
                    do4.BackColor = Color.Red;
                    delay_ms(d);
                    xanh1.BackColor = Color.DarkGray;
                    xanh2.BackColor = Color.DarkGray;
                    xanh3.BackColor = Color.DarkGray;
                    xanh4.BackColor = Color.DarkGray;
                    vang1.BackColor = Color.DarkGray;
                    vang2.BackColor = Color.Yellow;
                    vang3.BackColor = Color.Yellow;
                    vang4.BackColor = Color.DarkGray;
                    do1.BackColor = Color.Red;
                    do2.BackColor = Color.DarkGray;
                    do3.BackColor = Color.DarkGray;
                    do4.BackColor = Color.Red;
                    delay_ms(v);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Chọn thời gian trước khi bắt đầu", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
            
           

        private void Timer1_tick(object sender, EventArgs e)
        {
            {
                x++;
            if (x > 65000) x = 0;
            }
        }

        
    }
}
