public void PlayGame(CSharpQuestionAndAnswer argCsharp, GeneralKnowledge argGeneralKnowledge, CalculationEngine calculation) { bool exitToMenu = false; do { Console.WriteLine($"Select the game you wish to play: " + $"{gameList[0]} {gameList[1]} {gameList[2]} {gameList[3]} {gameList[4]} {gameList[5]} {gameList[6]} {gameList[7]}. Type {gameList[8]} to return to main menu"); selectGame = Console.ReadLine() ?? string.Empty; switch (selectGame.ToUpper()) { case "HTML": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[0]} Game!"); break; case "CSS": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[1]} Game!"); break; case "JAVASCRIPT": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[2]} Game!"); break; case "C#": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[3]} Game!"); PlayCsharpGame(argCsharp, calculation); break; case "ASP.NET": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[4]} Game!"); break; case "SQL": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[5]} Game!"); break; case "NETWORKING": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[6]} Game!"); break; case "GENERAL": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[7]} Game!"); PlayGeneralKnowledgeGame(argGeneralKnowledge, calculation); break; case "EXIT": Console.WriteLine($"{Constants.horizontalRule}Exited Game!"); exitToMenu = true; break; default: Console.WriteLine($"{Constants.horizontalRule}Cannot find game with that name, please check it is on the list, and is spelt correctly"); break; } } while (!exitToMenu); }
static void Main(string[] args) { try { CalculationEngine calculation = new CalculationEngine(); PlayGameMethods playGameMethods = new PlayGameMethods(); CSharpQuestionAndAnswer cSharpQuestionAndAnswer = new CSharpQuestionAndAnswer(); GeneralKnowledge generalKnowledge = new GeneralKnowledge(); CustomGame customGame = new CustomGame(); bool continueQuizGames = false; do { // Decide if you want to play Console.WriteLine("Do you wish to continue playing? Y/N"); var shouldPlay = Console.ReadLine() ?? string.Empty; if (shouldPlay.Equals("Y", StringComparison.OrdinalIgnoreCase)) { playGameMethods.PlayGame(cSharpQuestionAndAnswer, generalKnowledge, customGame, calculation); continueQuizGames = true; } // Immediately exit app if we do not want to continue else if (shouldPlay.Equals("N", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Quiz has been closed. Press any key to continue"); Environment.Exit(0); } // If we enter an invalid input just keep playing else { Console.WriteLine("Operation Not recognized"); continueQuizGames = true; } } while (continueQuizGames); } catch (Exception ex) { Console.WriteLine("There was an error: " + ex.Message); } }
public static void PlayGeneralKnowledgeGame(GeneralKnowledge argGeneralKnowledge, CalculationEngine calculation) { // apply C# calculations calculation.CalculateScore(argGeneralKnowledge.questionsList, argGeneralKnowledge.answerListCorrect, argGeneralKnowledge.answerListIncorrect1, argGeneralKnowledge.answerListIncorrect2, argGeneralKnowledge.answerListIncorrect3); }
public void PlayGame(CSharpQuestionAndAnswer argCsharp, GeneralKnowledge argGeneralKnowledge, CustomGame argCustomGame, CalculationEngine argCalculation) { bool exitToMenu = false, customSelected = false; string selectCustomOrBuiltIn = string.Empty; IList <string> gameList = new List <string> { "HTML", "CSS", "JAVASCRIPT", "C#", "ASP.NET", "SQL", "NETWORKING", "GENERAL", "EXIT" }; do { selectCustomOrBuiltIn = ChooseCustomOrBuiltIn(gameList, ref customSelected); Console.WriteLine($"Select the game you wish to play: " + $"{gameList[0]}, {gameList[1]}, {gameList[2]}, {gameList[3]}, {gameList[4]}, {gameList[5]}, {gameList[6]}, {gameList[7]}," + $" MYGAME to select {gameList[gameList.Count - 1]}, if you created one." + // last element will be the name of the game $". Type EXIT to return to main menu"); selectGame = Console.ReadLine() ?? string.Empty; switch (selectGame.ToUpper()) { case "HTML": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[0]} Game!\n"); break; case "CSS": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[1]} Game!\n"); break; case "JAVASCRIPT": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[2]} Game!\n"); break; case "C#": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[3]} Game!\n"); PlayCsharpGame(argCsharp, argCalculation); break; case "ASP.NET": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[4]} Game\n!"); break; case "SQL": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[5]} Game!\n"); break; case "NETWORKING": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[6]} Game!\n"); break; case "GENERAL": Console.WriteLine($"{Constants.horizontalRule}Welcome to the {gameList[7]} Game!\n"); // custom always last PlayGeneralKnowledgeGame(argGeneralKnowledge, argCalculation); break; case "MYGAME": Console.WriteLine($"{Constants.horizontalRule}Welcome to your {gameList[gameList.Count - 1]} Game!\n"); PlayCustomGame(argCustomGame, argCalculation); break; case "EXIT": Console.WriteLine($"{Constants.horizontalRule}Exited Game!"); exitToMenu = true; break; default: Console.WriteLine($"{Constants.horizontalRule}Cannot find game with that name, please check it is on the list, and is spelt correctly"); break; } if (customSelected) // if custom was selected we remove the custom game so we can add a new custom game, ensure we set it back to false so we do not keep removing list items { gameList.RemoveAt(gameList.Count - 1); customSelected = false; } } while (!exitToMenu); }