我一直在尝试制作我的第一个应用程序,一个测验应用程序,但我似乎无法理解当点击相应的按钮然后继续下一个问题时我将如何验证正确答案。
测验页面:
public partial class Page1 : PhoneApplicationPage
{
// list array
List<Question> qu;
//counter for moving to next question
int questionNumber;
// correct answer counter
int correctAnswer;
public void main()
{
// method for adding more questions to the list
qu = new List<Question>();
qu.Add(new Question("what is your favourite colour?",
"blue",
"red",
"green",
"blue"));
qu.Add(new Question("what is your favourite film?",
"The Matrix",
"Star Wars",
"Wrath Of Khan",
"The Matrix"));
qu.Add(new Question("what is your favourite car?",
"BMW",
"VW",
"Mercedes",
"BMW"));
questionNumber = 0;
correctAnswer = 0;
}
public Page1()
{
InitializeComponent();
main();
// counter for displaying next question
displayQuestion(questionNumber);
}
// button for quitting back to the start screen
private void btn_quit_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(
new Uri("/MainPage.xaml", UriKind.Relative));
}
private void btn_Answer_A_Click(object sender, RoutedEventArgs e)
{
endQuestion();
}
private void btn_Answer_C_Click(object sender, RoutedEventArgs e)
{
endQuestion();
}
private void btn_Answer_B_Click(object sender, RoutedEventArgs e)
{
endQuestion();
}
// method for ending a question, inc : counter for
// moving on to next question and
// checking if the answer is correct or not
public void endQuestion()
{
//check the answer
//if it's correct
questionNumber++;
displayQuestion(questionNumber);
//otherwise
//stay on question
}
public void displayQuestion(int counter)
{
// where the question and answers are displayed
// in the buttons and txt block
txt_block_question.Text = counter + ". " + qu[counter].question;
btn_Answer_A.Content = qu[counter].a;
btn_Answer_B.Content = qu[counter].b;
btn_Answer_C.Content = qu[counter].c;
}
}
问题类
public class Question
{
public String question;
public String answer;
public String a;
public String b;
public String c;
public Question(string q, string an, string optionA, string optionB, string optionC)
{
question = q;
answer = an;
a = optionA;
b = optionB;
c = optionC;
}
}