Exemplo n.º 1
0
        private void InitializeQuiz()
        {
            db = new Database();

            lblDisplayName.Text += User.Instance.DisplayName;
            lblScore.Text       += User.Instance.Score.ToString();
            // Daten holen
            listGeodata = db.GetData(QuizConfig.Instance.MaxQuestions, QuizConfig.Instance.Continent);

            // Objekt questions mit Abstrakter Klasse initialisieren
            questions = new Question[QuizConfig.Instance.MaxQuestions];

            for (int i = 0; i < QuizConfig.Instance.MaxQuestions; i++)
            {
                // Den ersten Eintrag als Frage speichern
                GeoData question = listGeodata[i];

                // Falsche Anworten holen (WHERE id != question.Id)
                List <GeoData> answers = db.GetFalseAnswers(question.Id, QuizConfig.Instance.Continent);

                // Je nach Fragentyp (Qt) wird das abstrakte Objekt
                // mit einem konkreten Objekt 'gefüllt'.
                // Als Parameter werden die Frage, die Antworten und der Antworttyp übergeben.
                switch (QuizConfig.Instance.Qt)
                {
                case QuestionType.Capital:
                    questions[i] = new CapitalQuestion(
                        question,
                        answers,
                        QuizConfig.Instance.At
                        );
                    break;

                case QuestionType.Country:
                    questions[i] = new CountryQuestion(
                        question,
                        answers,
                        QuizConfig.Instance.At
                        );
                    break;

                case QuestionType.Flag:
                    questions[i] = new FlagQuestion(
                        question,
                        answers,
                        QuizConfig.Instance.At
                        );
                    break;
                }
            }
        }
Exemplo n.º 2
0
        // Nagut, die hier erkläre ich.
        // Beim Aufruf der Klasse wird diese Methode hier als erstes aufgerufen.
        // Deswegen heisst es Method Factory
        public override void CreateAnswers(GeoData question, List <GeoData> answers, AnswerType at)
        {
            // Da die Methode oft und schnell aufgerufen wird, kommt Random()
            // nicht so schnell hinterher um ein gutes Random Ergebnis zu erstellen.
            // Was Random() übrigens eh nicht tut. Siehe Birthday Paradox.
            // Daher die Übergabe der Guid.

            Random gen = new Random(Guid.NewGuid().GetHashCode());

            At                  = at;
            gen                 = new Random(Guid.NewGuid().GetHashCode());
            CorrectAnswer       = question;
            CorrectAnswer.State = true;

            WrongAnswers = new List <GeoData>();
            WrongAnswers = answers;

            AllAnswers = new List <GeoData>();
            AllAnswers.Add(WrongAnswers[0]);
            AllAnswers.Add(WrongAnswers[1]);
            AllAnswers.Add(WrongAnswers[2]);
            AllAnswers.Insert(gen.Next(4), CorrectAnswer);

            switch (At)
            {
            case AnswerType.Country:
                Answers.Add(new CountryAnswer(AllAnswers[0]));
                Answers.Add(new CountryAnswer(AllAnswers[1]));
                Answers.Add(new CountryAnswer(AllAnswers[2]));
                Answers.Add(new CountryAnswer(AllAnswers[3]));
                break;

            case AnswerType.Capital:
                Answers.Add(new CapitalAnswer(AllAnswers[0]));
                Answers.Add(new CapitalAnswer(AllAnswers[1]));
                Answers.Add(new CapitalAnswer(AllAnswers[2]));
                Answers.Add(new CapitalAnswer(AllAnswers[3]));
                break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
        public override void CreateAnswers(GeoData question, List <GeoData> answers, AnswerType at)
        {
            Random gen = new Random(Guid.NewGuid().GetHashCode());

            At                  = at;
            gen                 = new Random(Guid.NewGuid().GetHashCode());
            CorrectAnswer       = question;
            CorrectAnswer.State = true;

            WrongAnswers = new List <GeoData>();
            WrongAnswers = answers;

            AllAnswers = new List <GeoData>();
            AllAnswers.Add(WrongAnswers[0]);
            AllAnswers.Add(WrongAnswers[1]);
            AllAnswers.Add(WrongAnswers[2]);
            AllAnswers.Insert(gen.Next(4), CorrectAnswer);

            switch (At)
            {
            case AnswerType.Capital:
                Answers.Add(new CapitalAnswer(AllAnswers[0]));
                Answers.Add(new CapitalAnswer(AllAnswers[1]));
                Answers.Add(new CapitalAnswer(AllAnswers[2]));
                Answers.Add(new CapitalAnswer(AllAnswers[3]));
                break;

            case AnswerType.Flag:
                Answers.Add(new FlagAnswer(AllAnswers[0]));
                Answers.Add(new FlagAnswer(AllAnswers[1]));
                Answers.Add(new FlagAnswer(AllAnswers[2]));
                Answers.Add(new FlagAnswer(AllAnswers[3]));
                break;

            default:
                break;
            }
        }
Exemplo n.º 4
0
 public FlagQuestion(GeoData question, List <GeoData> answers, AnswerType at)
     : base(question, answers, at)
 {
     Text = question.Flag.ToLower();
 }
Exemplo n.º 5
0
 public Answer(GeoData data)
 {
 }
Exemplo n.º 6
0
 public CapitalAnswer(GeoData data) : base(data)
 {
     Text  = data.Capital;
     State = data.State;
 }
Exemplo n.º 7
0
 public CountryQuestion(GeoData question, List <GeoData> answers, AnswerType at)
     : base(question, answers, at)
 {
     Text = question.Country;
 }
Exemplo n.º 8
0
 public CountryAnswer(GeoData data) : base(data)
 {
     Text  = data.Country;
     State = data.State;
 }
Exemplo n.º 9
0
 public FlagAnswer(GeoData data) : base(data)
 {
     Text  = data.Flag;
     State = data.State;
 }
Exemplo n.º 10
0
 // Die Factory Methode!!
 public abstract void CreateAnswers(GeoData question, List <GeoData> anwers, AnswerType at);
Exemplo n.º 11
0
 // Der Konstruktor ruft die Factory Methode auf.
 public Question(GeoData question, List <GeoData> anwers, AnswerType at)
 {
     CreateAnswers(question, anwers, at);
 }
Exemplo n.º 12
0
 public CapitalQuestion(GeoData question, List <GeoData> answers, AnswerType at)
     : base(question, answers, at)
 {
     Text = question.Capital;
 }