我需要一些帮助才能在Windows Phone 7上开始使用简单的测验应用。 用户将不得不猜测图片中显示的城市中给定地点的名称。 屏幕上会有一张图片,在它下面会有4个答案,如果用户点击正确答案,他会得到正确答案的通知,然后他可以转到另一个问题,同样不正确的情况。我需要跟踪正确的答案。所以我需要帮助或指导如何设置这样的问题/答案游戏。我需要随机生成的问题(每个问题4个随机的问题)并且说我每场比赛会有10个问题。
我打算有一个能够容纳我所在城市的名单
cityList = new List<string>();
cityList.Add("answer1");
cityList.Add("answer2");
cityList.Add("asnwer3");
cityList.Add("answer4");
我被卡住了,之前做过类似事情的人请帮忙,谢谢
答案 0 :(得分:2)
像这样的东西。我在答案框中输入了这个,它可能不会按原样编译,但肯定会让你开始。
class Question
{
string ImageURI { get; set; }
string Text { get; set; }
ObservableCollection<Answer> Answers { get; set; }
Answer CorrectAnswer { get; set; }
bool MakeGuess(Answer a) { UserGuess = a; if (a.Equals(CorrectAnswer)) { return true; } return false; }
bool AnsweredSuccessfully { get { return UserGuess != null && UserGuess.Equals(CorrectAnswer); } }
Answer UserGuess { get; set; }
}
class Answer
{
string text { get; set; }
}
class Game
{
public Game()
{
Questions = new ObservableCollection<Question>();
for (int i = 0; i < 10; i++) { Questions.Add(GenerateQuestion()); }
}
public Question GenerateQuestion()
{
Question q = new Question();
q.ImageURI = your link to image//;
q.Text = your image text//;
q.Answers = new ObservableCollection<Answer>();
q.CorrectAnswer = the correct answer//;
q.Answers.Add(CorrectAnswer);
for (int i = 0; i < 5; i++) { q.Answers.Add(GenerateAnswer(q.CorrectAnswer)); }
return q;
}
public Answer GenerateAnswer(Answer ignore)
{
List<Answer> answers = DataStore.Answers;//go to your main list of answers.
Random rand = new Random();
Answer a = answers[Random.Next(0,answers.Size())];
while (a == null || a.Equals(ignore) { a = answers[Random.Next(0,answers.Size())];}
return a;
}
public ObservableCollection<Question> Questions { get; set; }
}
答案 1 :(得分:1)
我会制作我自己的类拼图,它看起来像这样:
public class Puzzle
{
List<string> answers = new List<string>(4);
public Puzzle(string question, List<string> answers, int correctAnswer)
{
Question = question;
Answers = answers;
CorrectAnswer = correctAnswer;
}
public string Question {get; private set;}
public int CorrectAnswer {get; private set;} //or you can make CorrectAnswer a string
public List<string> Answers { get { return answers;} }
}
如果你使用一个接口,这个类需要dataBiding的逻辑。
您的列表如下所示:
cityPlaces = new List<string>(); //guess that's a better name
var answersOne = new List<string>() { "bla1", "bla2", "bla3", "bla4"};
cityPlaces .Add("What is the blabla blabla?",answersOne,2);
我怀疑“我需要随机生成的问题”。我认为这不是这种游戏的最佳选择。更好的是以随机顺序显示问题和答案。使用Fisher–Yates shuffle以随机顺序显示它们(here is a C# example,第一个,第二个是错误的,GUID是唯一的非随机的,排序算法可以对这种比较器执行任何操作。崩溃)。
那应该对你有帮助。