Esempio n. 1
0
        static void Main(string[] args)
        {
            Game     spiel = new Game(true);
            Question q1    = new Question("Was ist 2+2");
            Answer   a1    = new Answer("4", true);
            Answer   a2    = new Answer("6");

            q1.AddAnswer(a1);
            q1.AddAnswer(a2);
            spiel.AddQuestion(q1);

            Question q2 = new Question("Wie geht es dir ...");
            Answer   a3 = new Answer("gut", true);
            Answer   a4 = new Answer("1111");

            q2.AddAnswer(a3);
            q2.AddAnswer(a4);
            spiel.AddQuestion(q2);

            Question q3 = new Question("´Welche Schleife gibt es in C#");
            Answer   a5 = new Answer("For-schleife", true);
            Answer   a6 = new Answer("Int-Schleife");

            q3.AddAnswer(a5);
            q3.AddAnswer(a6);
            spiel.AddQuestion(q3);


            while (spiel.Status == GameStatus.Active)
            {
                var frage     = spiel.NextQuestion;
                var antworten = frage.Answers;
                Console.WriteLine(frage.Text);
                int counter = 0;
                foreach (Answer a in antworten)
                {
                    Console.WriteLine("(" + counter + ") " + a.Text);
                    counter++;
                }
                Console.WriteLine("Geben Sie die richtig: ");
                int eingabeindex = Convert.ToInt32(Console.ReadLine());
                antworten[eingabeindex].IsChecked = true;
                spiel.ValidateCurrentQuestion();
            }

            if (spiel.Status == GameStatus.HasFinished)
            {
                Console.WriteLine("Sie haben gewonnen, erreichtes Level: " + spiel.Level);
            }
            else
            {
                Console.WriteLine("Sie haben Verloren, Aktuelles Level:" + spiel.Level);
            }
        }
Esempio n. 2
0
        public static Question[] ReadQuestions(string table_name)
        {
            List <Question> questions = new List <Question>();

            string sql = "select * from Questions order by Question";

            IDbConnection _connection;

            _connection = (IDbConnection) new SqliteConnection("URI=file:" + Application.dataPath + "/sampledb.sqlite");
            _connection.Open();

            IDbCommand IDbCommand = _connection.CreateCommand();

            IDbCommand.CommandText = sql;
            IDataReader _reader = IDbCommand.ExecuteReader();

            _connection.Close();


            while (_reader.Read())
            {
                //Debug.Log("Question: " + _reader["Question"] + "\t" + "Subject: " + _reader["Subject"]);

                Question quest = new Question();

                quest.Text = _reader["Question"] as string;
                quest.AddSubject(_reader["Subject"] as string);
                quest.AddHint(_reader["Hint"] as string);
                quest.difficulty = (Difficulty)_reader["Difficulty"];

                quest.AddAnswer(_reader["Answer 1"] as string);
                quest.AddAnswer(_reader["Answer 2"] as string);
                quest.AddAnswer(_reader["Answer 3"] as string);
                quest.AddAnswer(_reader["Answer 4"] as string);

                questions.Add(quest);
            }
//
//			if (_command != null){
//				_command.Dispose();
//				_command = null;
//			}
//			if (_connection != null){
//				_connection .Close();
//				_connection = null;
//			}

            Debug.Log(questions.Count);

            return(questions.ToArray());
        }