Windows窗体 - 执行简单的数学游戏时出错

时间:2018-06-09 11:43:33

标签: c#

我想开始使用Windows窗体,所以我做了这个项目。但我有一个问题,我不知道答案。

当我按下回车键说出我的回答是否等于问题没有发生时

When I press the enter key to say if my answer equals to the question it happens nothing

namespace WindowsFormsApp2
{

public partial class Form1 : Form
{
    private int y;
    private int i = 1;
    private double Correct1;
    private double Correct2;
    private double Correct3;
    private double Correct4;
    private double Correct5;

    private bool Correct1Bool = false;
    private bool Correct2Bool = false;
    private bool Correct3Bool = false;
    private bool Correct4Bool = false;
    private bool Correct5Bool = false;

    private bool ClickedEnterButton = true;

    public Form1()
    {
        InitializeComponent();
    }



    public void aButton_Click(object sender, EventArgs e)
    {

        Random Number_1 = new Random();
        Random Number_2 = new Random();
        Random Operation = new Random();

        double Number1 = Number_1.Next(1,21);
        double Number2 = Number_2.Next(1, 11);
        int OperationDecider = Operation.Next(1, 6);

        switch (OperationDecider)
        {
            case 1:
                Correct1 = Number1 + Number2;
                MathProblems.Text = Number1.ToString() + " + " + Number2;   //PLUS


                Correct1Bool = true;
                break;
            case 2:
                Correct2 = Number1 - Number2;
                MathProblems.Text = Number1.ToString() + " - " + Number2; //MINUS



                Correct2Bool = true;
                break;
            case 3:
                Correct3 = Number1 / Number2;
                MathProblems.Text = Number1.ToString() + " / " + Number2;  //DIVISION



                Correct3Bool = true;
                break;

            case 4:
                Correct4 = Number1 * Number2;
                MathProblems.Text = Number1.ToString() + " * " + Number2;  //MULTIPLIKATION



                Correct4Bool = true;
                break;

            case 5:
                Correct5 = Number1 % Number2;
                MathProblems.Text = Number1.ToString() + " % " + Number2;   //MOLDULOS



                Correct5Bool = true;
                break;




        }

    }



    private void EnterButton_Click(object sender, EventArgs e)
    {

        if(Correct1Bool == true)
        {
            if(ClickedEnterButton == true)
            {
                if(textBox1.Text.ToString() == Correct1.ToString())
                {
                    ClickedEnterButton = false;
                    MathProblems.Text = "CORRECT!";
                    y = i++;
                    ProblemsSolvedNumbers.Text = y.ToString();

                }
                    else if(textBox1.Text.ToString() != Correct1.ToString())
                    {
                    MathProblems.Text = "WRONG!";
                    }
            }
        }
        if (Correct2Bool == true)
        {
            if (ClickedEnterButton == true)
            {
                if (textBox1.Text.ToString() == Correct2.ToString())
                {
                    ClickedEnterButton = false;
                    MathProblems.Text = "CORRECT!";
                    y = i++;
                    ProblemsSolvedNumbers.Text = y.ToString();
                }
                else if(textBox1.Text.ToString() != Correct2.ToString())
                {
                    MathProblems.Text = "WRONG!";

                }
            }
        }
        if (Correct3Bool == true)
        {
            if (ClickedEnterButton == true)
            {

                if (textBox1.Text.ToString() == Correct3.ToString())
                {
                    ClickedEnterButton = false;
                    MathProblems.Text = "CORRECT!";
                    y = i++;
                    ProblemsSolvedNumbers.Text = y.ToString();
                }
                else if(textBox1.Text.ToString() != Correct3.ToString())
                {
                    MathProblems.Text = "WRONG!";

                }
            }
        }
        if (Correct4Bool == true)
        {
            if (ClickedEnterButton == true)
            {
                if (textBox1.Text.ToString() == Correct4.ToString())
                {
                    ClickedEnterButton = false;
                    MathProblems.Text = "CORRECT!";
                    y = i++;
                    ProblemsSolvedNumbers.Text = y.ToString();
                }
                else if(textBox1.Text.ToString() != Correct4.ToString())
                {
                    MathProblems.Text = "WRONG!";

                }
            }
        }
        if (Correct5Bool == true)
        {
            if (ClickedEnterButton == true)
            {
                if (textBox1.Text.ToString() == Correct5.ToString())
                {
                    ClickedEnterButton = false;
                    MathProblems.Text = "CORRECT!";
                    y = i++;
                    ProblemsSolvedNumbers.Text = y.ToString();
                }
                else if(textBox1.Text.ToString() != Correct5.ToString())
                {
                    Console.WriteLine("WRONG");   // *1


                }
            }

        }
    }


}
}

它应该显示" CORRECT"在屏幕上,但它没有,虽然它给记分板增加了一个点。它既没有表现出错误!"错误!"

我将不胜感激任何帮助!

0 个答案:

没有答案