Ejemplo n.º 1
0
        public void Test_PlayShortQuiz(int submitAnswerOne, int submitAnswerTwo, int numCorrect)
        {
            // Question 1
            Assert.AreEqual(GameState.Quiz, model.State);
            Assert.AreEqual("Please select \"Answer One\"", model.CurrentItem.Question.Question);
            Assert.AreEqual("Answer One", model.CurrentItem.Question.Choices[0]);
            Assert.AreEqual("Answer Two", model.CurrentItem.Question.Choices[1]);
            Assert.AreEqual(false, model.CurrentItem.Answered);
            Assert.AreEqual(false, model.CurrentItem.Correct);
            model.SubmitAnswer(submitAnswerOne);
            model.AdvanceCard();

            // Question 2
            Assert.AreEqual(GameState.Quiz, model.State);
            Assert.AreEqual("Please select \"Selection Two\"", model.CurrentItem.Question.Question);
            Assert.AreEqual("Selection One", model.CurrentItem.Question.Choices[0]);
            Assert.AreEqual("Selection Two", model.CurrentItem.Question.Choices[1]);
            Assert.AreEqual(false, model.CurrentItem.Answered);
            Assert.AreEqual(false, model.CurrentItem.Correct);
            model.SubmitAnswer(submitAnswerTwo);
            model.AdvanceCard();

            // Score
            Assert.AreEqual(GameState.Score, model.State);
            Assert.AreEqual(numCorrect, model.CorrectCount);
        }
Ejemplo n.º 2
0
 private void AdvanceCard(object obj)
 {
     GameModel.AdvanceCard();
     NotifyPropertyChanged("GameModel");
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var filename = "./Quizzes/Central American Capitals.txt";

            // Read args if user specifies file
            if (args.Length >= 1)
            {
                filename = args[0];
            }

            // Setup game from specified file file
            GameModel model = null;

            try
            {
                model = new GameModel(filename);
            } catch
            {
                Console.WriteLine("There was an error reading or setting up: " + filename);
                return;
            }

            Console.WriteLine("Playing from " + filename);
            Console.WriteLine();

            // Answer questions
            while (model.State == GameState.Quiz)
            {
                Console.WriteLine(model.CurrentItem.Question.Question);
                for (int i = 0; i < model.CurrentItem.Question.Choices.Count; i++)
                {
                    Console.WriteLine((i + 1) + ". " + model.CurrentItem.Question.Choices[i]);
                }
                Console.Write("Answer #: ");
                var answer = Console.ReadLine();

                int answerInt = int.Parse(answer.Trim());

                var correct = model.SubmitAnswer(answerInt);

                if (correct)
                {
                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Incorrect");
                    Console.WriteLine("Correct Answer: " + model.CurrentItem.Question.CorrectAnswer);
                }

                model.AdvanceCard();

                Console.WriteLine();
            }

            // Print Results
            Console.WriteLine();
            var correctCount = model.CorrectCount;
            var totalCount   = model.QuizItems.Count;

            Console.WriteLine("Answered " + correctCount + " / " + totalCount + " correctly.");
        }