Пример #1
0
        //Hàm lấy câu hỏi ngẫu nhiên  trả về là 1 câu hỏi.
        public cauhoi lcauhoi(int x)
        {
            string       path   = @Application.StartupPath + @"\QS\q" + x.ToString() + ".mpv";
            cauhoi       n      = new cauhoi();
            StreamReader caumot = new StreamReader(path);
            Random       rd     = new Random();
            int          rand   = rd.Next(1, (countLine(path) / 6) + 1);
            int          dk;

            dk = 1;
            while (dk != rand && !caumot.EndOfStream)
            {
                caumot.ReadLine();
                caumot.ReadLine();
                caumot.ReadLine();
                caumot.ReadLine();
                caumot.ReadLine();
                caumot.ReadLine();
                dk++;
            }
            n.cauHoi = caumot.ReadLine();
            n.A      = caumot.ReadLine();
            n.B      = caumot.ReadLine();
            n.C      = caumot.ReadLine();
            n.D      = caumot.ReadLine();
            n.dapan1 = caumot.ReadLine();
            return(n);
        }
Пример #2
0
        //Hàm lấy câu hỏi ngẫu nhiên  trả về là 1 câu hỏi.
        public cauhoi lcauhoi(int x)
        {
            Random rd        = new Random();
            int    fileCount = 0;
            string path      = " ";

            if (x <= 5)
            {
                path      = Application.StartupPath + @"\QS\0-5";
                fileCount = Directory.GetFiles(path, "*.mpv", SearchOption.AllDirectories).Length;
            }
            if (5 < x && x <= 10)
            {
                path      = Application.StartupPath + @"\QS\5-10";
                fileCount = Directory.GetFiles(path, "*.mpv", SearchOption.AllDirectories).Length;
            }
            if (x > 10)
            {
                path      = Application.StartupPath + @"\QS\10-15";
                fileCount = Directory.GetFiles(path, "*.mpv", SearchOption.AllDirectories).Length;
            }
            int rand = rd.Next(1, fileCount);

            cauhoi       n      = new cauhoi();
            StreamReader caumot = new StreamReader(path + @"\q" + rand.ToString() + ".mpv");
            string       a;

            n.cauHoi = caumot.ReadLine();
            n.A      = caumot.ReadLine();
            n.B      = caumot.ReadLine();
            n.C      = caumot.ReadLine();
            n.D      = caumot.ReadLine();
            n.dapan1 = caumot.ReadLine();

            return(n);
        }
Пример #3
0
        //Hàm hiển thị câu hỏi ra form.Các đáp án ngẫu nhiên/
        public void displaycauhoi(int x)
        {
            //Đến câu nào thì btn câu đó đổi màu
            if (x == 1)
            {
                pictureBox2.Image = Properties.Resources.Picture1;
            }
            if (x == 2)
            {
                pictureBox2.Image = Properties.Resources.Picture2;
            }
            if (x == 3)
            {
                pictureBox2.Image = Properties.Resources.Picture3;
            }
            if (x == 4)
            {
                pictureBox2.Image = Properties.Resources.Picture4;
            }
            if (x == 5)
            {
                pictureBox2.Image = Properties.Resources.Picture5;
            }
            if (x == 6)
            {
                pictureBox2.Image = Properties.Resources.Picture6;
            }
            if (x == 7)
            {
                pictureBox2.Image = Properties.Resources.Picture7;
            }
            if (x == 8)
            {
                pictureBox2.Image = Properties.Resources.Picture8;
            }
            if (x == 9)
            {
                pictureBox2.Image = Properties.Resources.Picture9;
            }
            if (x == 10)
            {
                pictureBox2.Image = Properties.Resources.Picture10;
            }
            if (x == 11)
            {
                pictureBox2.Image = Properties.Resources.Picture11;
            }
            if (x == 12)
            {
                pictureBox2.Image = Properties.Resources.Picture12;
            }
            if (x == 13)
            {
                pictureBox2.Image = Properties.Resources.Picture13;
            }
            if (x == 14)
            {
                pictureBox2.Image = Properties.Resources.Picture14;
            }
            if (x == 15)
            {
                pictureBox2.Image = Properties.Resources.Picture15;
            }

            Dem_nguoc();
            if (x == 16)
            {
            }
            else
            {//khai báo cauhoi outCH để nhận giá trị đưa ra từ hàm lcauhoi(int x).
                cauhoi outCH = new cauhoi();

                //thiết lập lại
                textBox_cauhoi.Text = "";
                btn_A.Text          = "";
                btn_B.Text          = "";
                btn_C.Text          = "";
                btn_D.Text          = "";
                btn_dapan.Text      = "";
                //Gán
                outCH = lcauhoi(x);
                textBox_cauhoi.Text = "Câu " + x.ToString() + ":   " + outCH.cauHoi;

                btn_dapan.Text = outCH.dapan1;
                //Random đáp án
                Random laydapan = new Random();
                int    rdda     = laydapan.Next(1, 4);
                if (rdda == 1)
                {
                    btn_A.Text = outCH.A;
                    btn_B.Text = outCH.B;
                    btn_C.Text = outCH.C;
                    btn_D.Text = outCH.D;
                }
                if (rdda == 2)
                {
                    btn_A.Text = outCH.D;
                    btn_B.Text = outCH.C;
                    btn_C.Text = outCH.A;
                    btn_D.Text = outCH.B;
                }
                if (rdda == 3)
                {
                    btn_A.Text = outCH.C;
                    btn_B.Text = outCH.A;
                    btn_C.Text = outCH.D;
                    btn_D.Text = outCH.B;
                }
                if (rdda == 4)
                {
                    btn_A.Text = outCH.B;
                    btn_B.Text = outCH.D;
                    btn_C.Text = outCH.C;
                    btn_D.Text = outCH.A;
                }
            }
        }
Пример #4
0
        //Hàm hiển thị câu hỏi ra form.Các đáp án ngẫu nhiên/
        public void displaycauhoi(int x)
        {
            btn_A.Enabled = true; btn_C.Enabled = true;
            btn_B.Enabled = true; btn_D.Enabled = true;
            if (btn1Enable == 1)
            {
                button1.Enabled = true;
            }
            if (btn2Enable == 1)
            {
                button2.Enabled = true;
            }
            if (btn3Enable == 1)
            {
                button3.Enabled = true;
            }
            button4.Enabled = true;
            btn_A.BackColor = Color.Black; btn_B.BackColor = Color.Black;
            btn_C.BackColor = Color.Black; btn_D.BackColor = Color.Black;
            timer2.Stop();

            Dem_nguoc();
            //Đến câu nào thì btn câu đó đổi màu
            if (x == 1)
            {
                pictureBox2.Image = Properties.Resources.Picture1;
            }
            if (x == 2)
            {
                pictureBox2.Image = Properties.Resources.Picture2;
            }
            if (x == 3)
            {
                pictureBox2.Image = Properties.Resources.Picture3;
            }
            if (x == 4)
            {
                pictureBox2.Image = Properties.Resources.Picture4;
            }
            if (x == 5)
            {
                pictureBox2.Image = Properties.Resources.Picture5;
            }
            if (x == 6)
            {
                pictureBox2.Image = Properties.Resources.Picture6;
            }
            if (x == 7)
            {
                pictureBox2.Image = Properties.Resources.Picture7;
            }
            if (x == 8)
            {
                pictureBox2.Image = Properties.Resources.Picture8;
            }
            if (x == 9)
            {
                pictureBox2.Image = Properties.Resources.Picture9;
            }
            if (x == 10)
            {
                pictureBox2.Image = Properties.Resources.Picture10;
            }
            if (x == 11)
            {
                pictureBox2.Image = Properties.Resources.Picture11;
            }
            if (x == 12)
            {
                pictureBox2.Image = Properties.Resources.Picture12;
            }
            if (x == 13)
            {
                pictureBox2.Image = Properties.Resources.Picture13;
            }
            if (x == 14)
            {
                pictureBox2.Image = Properties.Resources.Picture14;
            }
            if (x == 15)
            {
                pictureBox2.Image = Properties.Resources.Picture15;
            }
            // khi hiện câu hỏi thì reset đồng hồ

            if (x == 16)
            {
            }
            else
            {//khai báo cauhoi outCH để nhận giá trị đưa ra từ hàm lcauhoi(int x).
                cauhoi outCH = new cauhoi();

                //thiết lập lại
                textBox_cauhoi.Text = "";
                btn_A.Text          = "";
                btn_B.Text          = "";
                btn_C.Text          = "";
                btn_D.Text          = "";
                btn_dapan.Text      = "";
                //Gán
                outCH = lcauhoi(x);
                textBox_cauhoi.Text = "Câu " + x.ToString() + ":   " + outCH.cauHoi;

                btn_dapan.Text = outCH.dapan1;
                //Random đáp án
                Random laydapan = new Random();
                int    rdda     = laydapan.Next(1, 4);
                if (rdda == 1)
                {
                    btn_A.Text = outCH.A;
                    btn_B.Text = outCH.B;
                    btn_C.Text = outCH.C;
                    btn_D.Text = outCH.D;
                }
                if (rdda == 2)
                {
                    btn_A.Text = outCH.D;
                    btn_B.Text = outCH.C;
                    btn_C.Text = outCH.A;
                    btn_D.Text = outCH.B;
                }
                if (rdda == 3)
                {
                    btn_A.Text = outCH.C;
                    btn_B.Text = outCH.A;
                    btn_C.Text = outCH.D;
                    btn_D.Text = outCH.B;
                }
                if (rdda == 4)
                {
                    btn_A.Text = outCH.B;
                    btn_B.Text = outCH.D;
                    btn_C.Text = outCH.C;
                    btn_D.Text = outCH.A;
                }
            }
        }