public static TestTaker loadNotes(string fileName, out bool foundFile) { StringBuilder file = new StringBuilder(fileName); TestTaker t = new TestTaker(); askType(t); Console.WriteLine("Loading file..."); if (!fileName.Contains('.')) { file.Append(".txt"); } bool success = t.parseFile($"{file}"); if (!success) { foundFile = false; Console.WriteLine("...failure :("); } else { foundFile = true; Console.WriteLine("...success!"); } return(t); }
public static void askType(TestTaker t) { bool goodKey; string key; Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Which type of test will you take?"); Console.WriteLine("\t[1] Keywords Partial (words indicated in txt file will be partially hidden)"); Console.WriteLine("\t[2] Keywords Full Blank (words indicated in txt file will be fully hidden)"); Console.WriteLine("\t[3] Keywords First Letters (only first few letters revealed, the rest hidden)"); Console.WriteLine("\t[4] Full Random (all words in answer will be randomly hidden)"); Console.WriteLine(); do { Console.Write("Your choice: "); key = Console.ReadLine(); goodKey = (key == "1" || key == "2" || key == "3" || key == "4"); if (!goodKey) { Console.WriteLine(); Console.WriteLine("Please provide your choice by entering 1, 2, 3, or 4 on your keyboard"); } } while (!goodKey); int keyNum = int.Parse(key); t.setExamType((TestTaker.testType)keyNum); return; }
public static int askHowManyQuestions(TestTaker t) { Console.Clear(); printTitle(); Console.WriteLine(); Console.WriteLine($"These notes contain {t.exam.totalQuestions} questions."); Console.WriteLine(); Console.WriteLine($"How many would you like to practice?"); Console.WriteLine($"\t* Press [enter] for all"); Console.WriteLine($"\t* Otherwise [enter a number] and press [enter]"); Console.WriteLine(); int num = t.exam.totalQuestions; // default string userInput = null; bool parseSuccess = true; do { Console.WriteLine(); Console.Write("Your choice: "); userInput = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(userInput)) { parseSuccess = int.TryParse(userInput, out num); } } while (!parseSuccess || (num > t.exam.totalQuestions) || (num < 1)); if (num <= 0 || string.IsNullOrWhiteSpace(userInput)) { num = t.exam.totalQuestions; } t.SetNumQuestionsSession(num); return(num); }
public static bool testComplete(TestTaker t) { Console.Clear(); printTitle(); Console.WriteLine("Thanks for playing!"); string answer; do { Console.WriteLine(); Console.WriteLine("Would you like to play again? (yes/no)"); Console.Write("Your response: "); answer = Console.ReadLine(); } while (!answer.ToLower().Contains('y') && !answer.ToLower().Contains('n')); if (answer.ToLower().Contains('y')) { return(true); } else { return(false); } }
public static keyCommand askQuestion(TestTaker t) { // TITLE Console.Clear(); printTitle(); // REVIEW QUESTION INDICATOR if (t.exam.currentQuestion.IsReviewQuestion) { WriteColor(" *---------------------*\n", ConsoleColor.Magenta); WriteColor(" | ~[REVIEW QUESTION]~ |\n", ConsoleColor.Magenta); WriteColor(" *---------------------*\n", ConsoleColor.Magenta); Console.WriteLine(); } // HEADER string trimmedSectionName = (t.exam.currentSection.topic).Replace(TestTaker.TOPIC_SYMBOL, ""); int sectionNum = t.exam.currentSection.howManyTotal() - t.exam.currentSection.howManyLeft(); Console.Write($"SECTION: "); WriteColor(trimmedSectionName, ConsoleColor.White); Console.Write($" [Question {sectionNum} out of {t.exam.currentSection.howManyTotal()}]"); Console.WriteLine(); // Question int questionNum = t.exam.currentQuestion.QuestionNumber; string reviewIndicator = t.exam.currentQuestion.IsReviewQuestion ? "(review)" : ""; if (t.HasPreviousQuestions()) { Console.Write("<<--- ["); WriteColor("previous", ConsoleColor.DarkCyan); Console.Write("] "); } else { Console.Write(" "); } Console.Write($"Question {questionNum} {reviewIndicator} out of {t.GetNumQuestionsSession()}: "); if (t.HasForwardQuestions()) { Console.Write(" ["); WriteColor("forward", ConsoleColor.DarkCyan); Console.Write("] --->>\n"); } else { Console.Write("\n"); } // Questions for Review: Console.Write(" "); Console.Write($"Questions for Review: ["); if (t.exam.NumberQuestionsForReview() > 0) { WriteColor(t.exam.NumberQuestionsForReview().ToString(), ConsoleColor.Magenta); } else { Console.Write(t.exam.NumberQuestionsForReview().ToString()); } Console.Write("]\n"); // QUESTION Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); t.exam.currentQuestion.WriteSymbolColor(t.exam.currentQuestion.processedQuestion, ConsoleColor.Yellow); Console.WriteLine(); Console.WriteLine("[Press enter to continue]"); // REVEAL ANSWER? Console.WriteLine(); var key = Console.ReadKey(false).Key; if (key == ConsoleKey.Escape) { return(keyCommand.ESCAPE); } if (key != ConsoleKey.LeftArrow && key != ConsoleKey.RightArrow) { Console.WriteLine(); Console.WriteLine("[ANSWER]:"); Console.WriteLine(); t.exam.currentQuestion.WriteSymbolColor(t.exam.currentQuestion.answer, ConsoleColor.Green); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Press [Backspace] to review later"); Console.WriteLine("Press [Enter] to complete this question"); Console.WriteLine(); key = Console.ReadKey(false).Key; } // Add to review questions: if (key == ConsoleKey.Backspace) { t.exam.AddReviewQuestion(t.exam.currentQuestion); } if (key == ConsoleKey.Enter && !t.HasForwardQuestions()) { t.exam.CompleteQuestion(t.exam.currentQuestion); } // Restart question: if (key == ConsoleKey.UpArrow) { return(keyCommand.RESTART_QUESTION); } // KEYBOARD LOGIC if (key == ConsoleKey.LeftArrow) { return(keyCommand.BACKWARD_ONE); } else if (key == ConsoleKey.RightArrow) { return(keyCommand.FORWARD_ONE); } else if (key == ConsoleKey.Escape) { return(keyCommand.ESCAPE); } else { return(keyCommand.NEXT); } }