コード例 #1
0
        public static void game()
        {
            Quizelement quiz = CreationOfQuestionAndAnswers();

            Console.WriteLine("Was willst du tun?");
            Console.WriteLine(player.playerName + "'s Score is: " + player.score);
            Console.WriteLine("1. Fragen beantworten   2. Fragen erstellen   3. Beenden");
            string mode = Console.ReadLine();

            switch (mode)
            {
            case "1":
                quiz.show();
                Console.WriteLine("Welche Nummer ist richtig ?");
                int userInput = Int32.Parse(Console.ReadLine());
                quiz.IsAnswerCorrect(userInput, player);
                game();
                break;

            case "2":
                CreateOwnQuestions();
                game();
                break;

            default:
                Console.WriteLine("Du hast  " + player.score + " Punkte erreicht. Super Wahnsinn");
                break;
            }
        }
コード例 #2
0
        public static void CreateOwnQuestions()
        {
            Quizelement newQuiz = new Quizelement();

            Console.WriteLine("Schreibe bitte deine Frage");
            string newQuestion = Console.ReadLine();

            newQuiz.question = newQuestion;

            Console.WriteLine("Wie viele Antworten willst du anzeigen lassen?");
            int amountOfAnswers = Int32.Parse(Console.ReadLine());

            newQuiz.answers = new Answer[amountOfAnswers];

            for (int i = 0; i < amountOfAnswers; i++)
            {
                Console.WriteLine("Stelle nun deine Frage");
                string userAnswer = Console.ReadLine();
                Console.WriteLine("Is das die richtige Antwort? Schreibe bitte ja oder nein");
                string userAnswerTruth = Console.ReadLine();
                bool   finalTruth;
                if (userAnswerTruth == "ja")
                {
                    finalTruth = true;
                }
                else
                {
                    finalTruth = false;
                }
                newQuiz.answers[i] = new Answer {
                    text = userAnswer, truth = finalTruth
                };
            }
            listWithAllQuestionsAndAnswers.Add(newQuiz);
        }
コード例 #3
0
        public static Quizelement GetRandomQuestion(List <Quizelement> _listWithAllQuestionsAndAnswers)
        {
            Random      rnd            = new Random();
            int         randomNumber   = rnd.Next(_listWithAllQuestionsAndAnswers.Count);
            Quizelement randomQuestion = _listWithAllQuestionsAndAnswers[randomNumber];

            return(randomQuestion);
        }
コード例 #4
0
        public static Quizelement CreationOfQuestionAndAnswers()
        {
            Quizelement quiz = new Quizelement();

            quiz.question   = "Wer war der erste Bundeskanzler der BRD ?";
            quiz.answers    = new Answer[4];
            quiz.answers[0] = new Answer {
                text = "Barack Obama", truth = false
            };
            quiz.answers[1] = new Answer {
                text = "Helmut Kohl", truth = false
            };
            quiz.answers[2] = new Answer {
                text = "Konrad Adenauer", truth = true
            };
            quiz.answers[3] = new Answer {
                text = "Angela Merkel", truth = false
            };


            Quizelement quiz2 = new Quizelement();

            quiz2.question   = "Wie viele Nachbarländer hat Deutschland?";
            quiz2.answers    = new Answer[6];
            quiz2.answers[0] = new Answer {
                text = "Eins", truth = false
            };
            quiz2.answers[1] = new Answer {
                text = "Fünf", truth = false
            };
            quiz2.answers[2] = new Answer {
                text = "Keins", truth = false
            };
            quiz2.answers[3] = new Answer {
                text = "Neun", truth = true
            };
            quiz2.answers[4] = new Answer {
                text = "Dreizehn", truth = false
            };
            quiz2.answers[5] = new Answer {
                text = "Zwei-und-Vierzig", truth = false
            };

            listWithAllQuestionsAndAnswers.Add(quiz);

            listWithAllQuestionsAndAnswers.Add(quiz2);

            Quizelement questionToDisplay = GetRandomQuestion(listWithAllQuestionsAndAnswers);

            return(questionToDisplay);
        }
コード例 #5
0
        public static void PlayTheGame(Quizelement quiz)
        {
            Console.Clear();

            quiz.showQuestion();
            Console.Write("\nEnter your answer: \n>");
            if (quiz.answers[Convert.ToInt32(Console.ReadLine()) - 1].IsCorrect())
            {
                score += 10;
                Console.WriteLine("Your score. (Score + 10)");
            }
            else
            {
                Console.WriteLine("You shall not pass");
            }
            currentQuestion++;
        }
コード例 #6
0
        public static void GenerateDefaultQuestions()
        {
            Quizelement quiz1 = new Quizelement(

                "Wer überlebt bei Harry Potter?",
                new Answer[] {
                new Answer("Snape", false),
                new Answer("Dumbledore", false),
                new Answer("Harry", true),
                new Answer("Voldemord", false)
            }
                );

            Quizelement quiz2 = new Quizelement(

                "Wer war der 1.Bundeskanzler der BRD?",
                new Answer[] {
                new Answer("Barack Obama", false),
                new Answer("Helmut Kohl", false),
                new Answer("Konrad Adenauer", true),
                new Answer("Angela Merkel", false)
            }
                );

            Quizelement quiz3 = new Quizelement(
                "Welchem Haus in Hogwarts gehört Harry Potter an?",
                new Answer[] {
                new Answer("Ravenclaw", false),
                new Answer("Gryffindor", true),
                new Answer("Hufflepuff", false),
                new Answer("Slytherin", false)
            }
                );

            questionPool.Add(quiz1);
            questionPool.Add(quiz2);
            questionPool.Add(quiz3);
        }