public static QuizElementMultAnswers CreateQuizElement() { try { string question = QuizElement.promptEnterQuestion(); var answerList = new List <Answer> { }; var cont = true; while (cont) { Console.WriteLine("Please enter a possible answer, alternatively simply press enter to go to the next step."); Console.Write("> "); var input = Console.ReadLine(); if (input.Equals("")) { cont = false; } else { Console.WriteLine("Is this answer true? (Type y/n for true/false)"); Console.Write("> "); var input2 = Console.ReadLine().ToLower(); if (input2.Equals("y")) { answerList.Add(new Answer(input, true)); } else if (input2.Equals("n")) { answerList.Add(new Answer(input, false)); } else { throw new System.FormatException(); } } } return(new QuizElementMultAnswers(question, answerList)); } catch (System.FormatException) { Console.WriteLine("Invalid input! Please try again."); return(QuizElementMultAnswers.CreateQuizElement()); } }
static void CreateNewQuizElement() { while (true) { DisplayQuestionTypes(); try { var input = Int32.Parse(Console.ReadLine()); QuizElement question = null; string basePath = "QuizElements\\"; switch (input) { case 1: question = QuizElementTrueFalse.CreateQuizElement(); AddToDatabase <QuizElementTrueFalse>(question, basePath + "TrueFalse.json"); break; case 2: question = QuizElementText.CreateQuizElement(); AddToDatabase <QuizElementText>(question, basePath + "Text.json"); break; case 3: question = QuizElementGuess.CreateQuizElement(); AddToDatabase <QuizElementGuess>(question, basePath + "Guess.json"); break; case 4: question = QuizElementMultAnswers.CreateQuizElement(); AddToDatabase <QuizElementMultAnswers>(question, basePath + "MultAnswers.json"); break; case 5: question = QuizElementSingleAnswer.CreateQuizElement(); AddToDatabase <QuizElementSingleAnswer>(question, basePath + "SingleAnswer.json"); break; default: break; } Console.Write("Saving question....."); if (question != null) { _quizElements.Add(question); Console.WriteLine("Done!"); } else { Console.WriteLine("Error!"); } break; } catch (System.FormatException) { Console.WriteLine("Input had the wring format, try again!"); } } }