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

namespace assig7
{
    public partial class Child_Q : Form
    {
        int x, count; string[] st = new string[11];
        int correct, Ncorrect, Nanswered;
        public int level=13;
        Child_Answer Myans = new Child_Answer();
        Random rnd = new Random();
        void NewQ()
        {
            progressBar2.Value = 10;
            textBox1.Text = "";
            if (count != 10)
            {
                label1.Text = rnd.Next(1, level).ToString();
                label2.Text = rnd.Next(1, level).ToString();
            }
                timer1.Interval = 1000;
                timer1.Enabled = true;
                label5.Text = "10";
                if (count != 0)
                {
                    progressBar1.Increment(10);
                }
                label6.Text = count.ToString();
                count++;
                if (count == 11)
                {
                    button1.Enabled = false;
                    textBox1.Enabled = false;
                    st[10] = "11-Correct = " + correct + " * Incorrect = " +
                    Ncorrect + " * Not Answred = " + Nanswered;
                    Myans.richTextBox1.Lines = st;
                }
        }
        void Result()
        {
            int x = 0, y = 0;
            x = int.Parse(label1.Text) * int.Parse(label2.Text);
            y = int.Parse(textBox1.Text);
            if (x == y && count < 11)
            {
                correct++;
                st[count - 1] = count.ToString() + "-  Your Answer is  " + label1.Text + " * " +
                    label2.Text+ " = " + x.ToString() + "     Correct  |:-)";
                Myans.richTextBox1.Lines = st;
                NewQ();
            }
            else if (x != y && count < 11)
            {
                Ncorrect++;
                st[count - 1] = count.ToString() + "-  Your answer is  " + label1.Text + " * " +
                    label2.Text + " = " + y.ToString() + "     Incorrect  |:-(";
                Myans.richTextBox1.Lines = st;
                NewQ();
            }
        }
        public Child_Q(Child_Answer ans)
        {
            Myans = ans;
            InitializeComponent();
        }
        private void Child_Q_Load(object sender, EventArgs e)
        {
            NewQ();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
                x = int.Parse(label5.Text);
                x--;
                label5.Text = x.ToString();
                progressBar2.Increment(-1);
                if (x == 0 &&count<11)
                {
                    //Program.f.MdiChildren[1].Activate();
                    Nanswered++;
                    st[count - 1] = count.ToString()+"-  "+"Not Answerd "+label1.Text+
                        " * "+label2.Text;
                    Myans.richTextBox1.Lines = st;
                    NewQ();
                }
                if (count == 11)
                {
                    timer1.Enabled = false;
                    timer1.Stop();
                }
        }

        private void button1_Click(object sender, EventArgs e)
        {
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                Result();
            }
            catch
            {
                MessageBox.Show("Plz Check Your Answer...");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            progressBar2.Increment(-2);
        }

        private void progressBar2_Click(object sender, EventArgs e)
        {

        }
    }
}