【发布时间】:2019-11-29 13:22:00
【问题描述】:
我对编码和 c# 完全陌生。我正在学习 3 级 ICT,在我的编程科目中,我们被要求对学生的基本技能进行测验(使用表格。)。 我被要求创建一个非常基本的登录屏幕、主题选择屏幕、级别选择屏幕以及实际的问题和答案;答案是按钮。
我的问题是,我选择了下一个问题的错误答案,但显示了该问题的正确答案。
不太确定我需要做什么。我想在周末解决这个问题,所以我无法问我的老师。
必须保持非常基本。
这是我的代码。感谢您对此主题的任何帮助。
0级表格-
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 EssentialSkills.Numeracy
{
public partial class Level0num : Form
{
Point p1 = new Point(142, 303);
Point p2 = new Point(322, 303);
Point p3 = new Point(499, 303);
List<Point> points = new List<Point>();
public Level0num()
{
InitializeComponent();
Globals.listQuestionsNum0.Add("1 + 1");
Globals.listQuestionsNum0.Add("9 x 1");
Globals.listQuestionsNum0.Add("10 x 3");
Globals.listQuestionsNum0.Add("3 / 3");
Globals.listQuestionsNum0.Add("2 + 5 + 6");
Globals.listQuestionsNum0.Add("8 x 3");
Globals.listQuestionsNum0.Add("99 - 87");
Globals.listQuestionsNum0.Add("60 + 10 ");
Globals.listQuestionsNum0.Add("55 + 15");
Globals.listQuestionsNum0.Add("40 x 20");
Globals.listQuestionsNum0.Add("120 / 60");
Globals.listQuestionsNum0.Add("1.0 + 1.2");
Globals.listQuestionsNum0.Add("3 x 13");
Globals.listQuestionsNum0.Add("2 x 2");
Globals.listQuestionsNum0.Add("10 x 30");
Globals.listQuestionsNum0.Add("8 x 9");
Globals.listQuestionsNum0.Add("9 x 9");
Globals.listQuestionsNum0.Add("3 x 1");
Globals.listQuestionsNum0.Add("4 / 4");
Globals.listQuestionsNum0.Add("21 / 7");
Globals.listQuestionsNum0.Add("42 / 7");
Globals.listQuestionsNum0.Add("10 + 10 - 1");
Globals.listQuestionsNum0.Add("84 - 2 + 3");
Globals.listQuestionsNum0.Add("50 + 9 + 8");
Globals.listQuestionsNum0.Add("-1 + 2");
Globals.listQuestionsNum0.Add("33 + 88");
Globals.listQuestionsNum0.Add("10 - 3");
Globals.listQuestionsNum0.Add("32 + 2 x 1");
Globals.listQuestionsNum0.Add("1 x 543 + 1");
Globals.listQuestionsNum0.Add("3 + 10 x 2");
Globals.listAnswersNum0.Add(1 + 1);
Globals.listAnswersNum0.Add(9 * 1);
Globals.listAnswersNum0.Add(10 * 3);
Globals.listAnswersNum0.Add(3 / 3);
Globals.listAnswersNum0.Add(2 + 5 + 6);
Globals.listAnswersNum0.Add(8 * 3);
Globals.listAnswersNum0.Add(99 - 87);
Globals.listAnswersNum0.Add(60 + 10);
Globals.listAnswersNum0.Add(55 + 15);
Globals.listAnswersNum0.Add(40 * 20);
Globals.listAnswersNum0.Add(120 / 60);
Globals.listAnswersNum0.Add(1.0 + 1.2);
Globals.listAnswersNum0.Add(3 * 13);
Globals.listAnswersNum0.Add(2 * 2);
Globals.listAnswersNum0.Add(10 * 30);
Globals.listAnswersNum0.Add(8 * 9);
Globals.listAnswersNum0.Add(9 * 9);
Globals.listAnswersNum0.Add(3 * 1);
Globals.listAnswersNum0.Add(4 / 4);
Globals.listAnswersNum0.Add(21 / 7);
Globals.listAnswersNum0.Add(42 / 7);
Globals.listAnswersNum0.Add(10 + 10 - 1);
Globals.listAnswersNum0.Add(84 - 2 + 3);
Globals.listAnswersNum0.Add(50 + 9 + 8);
Globals.listAnswersNum0.Add(-1 + 2);
Globals.listAnswersNum0.Add(33 + 88);
Globals.listAnswersNum0.Add(10 - 3);
Globals.listAnswersNum0.Add(32 + 2 * 1);
Globals.listAnswersNum0.Add(1 * 543 * 1);
Globals.listAnswersNum0.Add(3 + 10 * 2);
points.Add(p1);
points.Add(p2);
points.Add(p3);
}
private void LoadQuestions()
{
lblCountdownval.Visible = false;
lblCountdown.Visible = false;
Globals.intQuestionNumber += 1;
lblQuestionsNumber.Text = "Question Number: " + Globals.intQuestionNumber.ToString();
Random random = new Random();
Globals.listIndex = random.Next(0, Globals.listAnswersNum0.Count - 1);
lblQuestion.Text = Globals.listQuestionsNum0.ElementAt(Globals.listIndex);
btnCorrect.Text = Globals.listAnswersNum0.ElementAt(Globals.listIndex).ToString();
btnAnswer1.Text = random.Next(100).ToString();
btnAnswer3.Text = random.Next(100).ToString();
int locationIndex = random.Next(0, 3);
btnCorrect.Location = points.ElementAt(locationIndex);
locationIndex = random.Next(0, 3);
btnAnswer1.Location = points.ElementAt(locationIndex);
while ((btnAnswer1.Location == btnCorrect.Location))
{
locationIndex = random.Next(0, 3);
btnAnswer1.Location = points.ElementAt(locationIndex);
}
locationIndex = random.Next(0, 3);
btnAnswer3.Location = points.ElementAt(locationIndex);
while ((btnAnswer3.Location == btnCorrect.Location) || (btnAnswer3.Location == btnAnswer1.Location))
{
locationIndex = random.Next(0, 3);
btnAnswer3.Location = points.ElementAt(locationIndex);
}
}
public void showCorrectAnswer()
{
timerLoadQuestion.Start();
lblCountdownval.Visible = true;
lblCountdown.Visible = true;
lblCountdownval.Text = "5";
lblCountdown.Text = "Next question will load in .... ";
btnAnswer1.Visible = false;
btnAnswer3.Visible = false;
btnCorrect.Location = p2;
btnCorrect.BackColor = Color.Green;
}
private void Level0num_Load(object sender, EventArgs e)
{
lblLoggedUser.Text = Globals.loggedUser;
lblQuestionsNumber.Text = "Question Number: ";
LoadQuestions();
Globals.s = 0;
lblScore.Text = "Score: " + Globals.s;
}
private void btnBack_Click(object sender, EventArgs e)
{
frmNumeracy back = new frmNumeracy();
this.Close();
back.ShowDialog();
}
private void btnAnswer1_Click(object sender, EventArgs e)
{
showCorrectAnswer();
MessageBox.Show("Incorrect");
LoadQuestions();
}
private void btnAnswer3_Click(object sender, EventArgs e)
{
showCorrectAnswer();
MessageBox.Show("Incorrect");
LoadQuestions();
}
private void btnCorrect_Click(object sender, EventArgs e)
{
MessageBox.Show("Correct!");
Globals.s += 1;
lblScore.Text = "Score: " + Globals.s.ToString();
LoadQuestions();
}
}
}
这是我的全局类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EssentialSkills
{
public static class Globals
{
public static string username, password;
public static string user1, user2, user3, user4, user5, user6, loggedUser, admin;
public static string pass1, pass2, pass3, pass4, pass5, pass6, adminPass1;
public static List<string> listQuestionsNum0 = new List<string>();
public static List<double> listAnswersNum0 = new List<double>();
public static int intQuestionNumber = 0;
public static int listIndex;
public static int s;
}
}
【问题讨论】: