So i'm currently attempting to create a quiz game to help with my revision at School. It displays a question and you need to choose which button answers the question correctly to get the "point". At the moment, the answer is always on the leftmost button, and i can't figure out a way to randomise the position of the answer. Any help would be appreciated. https://i.stack.imgur.com/e1PUr.jpg
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
QuestionLbl.Text = GetQuestion();
Answer1Btn.Text = GetAnswer();
Answer2Btn.Text = GetFalse1();
Answer3Btn.Text = GetFalse2();
}
public static class Globals
{
public static int QNum = GetRandomNumber();
public static int FalseNum1 = GetRandomNumber();
public static int FalseNum2 = GetRandomNumber();
}
private void Answer1Btn_Click(object sender, EventArgs e)
{
}
private static readonly Random getrandom = new Random();
public static int GetRandomNumber()
{
lock (getrandom) // synchronize
{
return getrandom.Next(0, 6);
}
}
public static string GetQuestion()
{
string[] Questions = {
"What Is The Formula For Speed?",
"What Is The Formula For Energy Transfered?",
"What Is The Formula For Efficiency?",
"What Is The Formula For Work Done?",
"What Is The Formula For Gravitational Potential Energy?",
"What Is The Formula For Elastic Potential Energy?",
"What Is The Formula For Kinetic Energy"
};
string QText = Questions[Globals.QNum];
return (QText);
}
public static string GetAnswer()
{
string[] Answers = {
"Distance / Time",
"Power * Time",
"(useful power output ÷ actual power input) × 100 %",
"Force * Distance",
"mass × gravitational field strength × height",
"1/2 × spring constant × extension2",
"1/2 × mass × speed2"
};
string AnswerTxt = Answers[Globals.QNum];
return (AnswerTxt);
}
public static string GetFalse1()
{
string[] Answers = {
"Distance / Time",
"Power * Time",
"(useful power output ÷ actual power input) × 100 %",
"Force * Distance",
"mass × gravitational field strength × height",
"1/2 × spring constant × extension2",
"1/2 × mass × speed2"
};
int FalseNum;
if (Globals.FalseNum1 == Globals.QNum)
{
FalseNum = GetRandomNumber();
}
else
{
FalseNum = Globals.FalseNum1;
}
string FalseAnswer = Answers[FalseNum];
return (FalseAnswer);
}
public static string GetFalse2()
{
string[] Answers = {
"Distance / Time",
"Power * Time",
"(useful power output ÷ actual power input) × 100 %",
"Force * Distance",
"mass × gravitational field strength × height",
"1/2 × spring constant × extension2",
"1/2 × mass × speed2"
};
Validation1:
if (Globals.FalseNum2 == Globals.QNum)
{
Globals.FalseNum2 = GetRandomNumber();
goto Validation1;
}
else
{ }
Validation2:
if (Globals.FalseNum2 == Globals.FalseNum1)
{
Globals.FalseNum2 = GetRandomNumber();
goto Validation2;
}
else
{ }
string FalseAnswer = Answers[Globals.FalseNum2];
return (FalseAnswer);
}
}