public static int CheckingAgeInput() { int age = 0; try { age = int.Parse(Console.ReadLine()); if (age < 18 || age > 120) { throw new AgeException(); } return(age); } catch (AgeException ex) { if (age < 18) { PrintingEngine.PrintAgeException(ex.TooYoung); } else { PrintingEngine.PrintAgeException(ex.TooOld); } GameManager.AllowedToEnterTheGame = false; } catch (Exception ex) { PrintingEngine.PrintAgeException("Age input must consist only from integers !!!"); GameManager.AllowedToEnterTheGame = false; } return(age); }
private static bool CompareAnswers(string answer, GeneralQuestion currentQuestion) { if (Convert.ToInt32(answer) == 5 && newGame.HelpsRemained != 0) { Random rand = new Random(); int count = 0; newGame.HelpsRemained = 0; while (count < 2) { int index = rand.Next(0, 3); if (currentQuestion.Answers[index] != currentQuestion.RightAnswer && currentQuestion.Answers[index] != "") { currentQuestion.Answers[index] = ""; count++; } } PrintingEngine.PrintSessionInfo(newGame); PrintingEngine.PrintQuestion(currentQuestion, newGame.HelpsRemained); Console.ResetColor(); Console.SetCursorPosition(100, 45); return(CompareAnswers(Console.ReadLine(), currentQuestion)); } else if (currentQuestion.Answers[int.Parse(answer) - 1] == currentQuestion.RightAnswer) { return(true); } else { return(false); } }
public Player(object obj) { PrintingEngine.AskForData("Name"); this.Name = Console.ReadLine(); PrintingEngine.AskForData("Surname"); this.Surname = (Console.ReadLine()); PrintingEngine.AskForData("Age"); this.Age = ErrorsCheckig.CheckingAgeInput(); }
private static void MakeChanges(bool isRight, GeneralQuestion currentQuestion) // Will make a change in Session Instance { if (isRight) { if (newGame.CurrentQuestion == 15) { newGame.GameOver = true; newGame.CurrentScore = 1000000; } else { PrintingEngine.PrintWinningBill(); if (currentQuestion is EasyQuestion) { newGame.CurrentScore += 10000; } else if (currentQuestion is MediumQuestion) { newGame.CurrentScore += 70000; } else { newGame.CurrentScore += 120000; } newGame.CurrentQuestion++; } } else { if (newGame.CurrentScore >= 50000 && timesGameRenewed == 0) { PrintingEngine.AskToContinue(currentQuestion); ConsoleKeyInfo choice = Console.ReadKey(); if (choice.KeyChar == 'y') { newGame.CurrentQuestion = 3; newGame.CurrentScore = 30000; timesGameRenewed++; } else { newGame.GameOver = true; newGame.CurrentScore = 50000; } } else { newGame.GameOver = true; } } }
private static void FlowControl() { PrintingEngine.WelcomeMessagePrint(); newGame = new GameSession(QuestionsStash.SetQuestAnswer()); //Creating new Session with QuestionAnswer List shuffle.SfuffleQuestion <GeneralQuestion>(newGame.QuestionAnswerList); //Shuffling question list for each session if (!AllowedToEnterTheGame) { return; } PrintingEngine.GameIsReady(); while (!newGame.GameOver) { GeneralQuestion currentQuestion = TakeQuestion(); //Getting Question for current stage of the game. Array.Sort(currentQuestion.Answers, shuffle); //Shuffling answers PrintingEngine.PrintSessionInfo(newGame); PrintingEngine.PrintQuestion(currentQuestion, newGame.HelpsRemained); Console.ResetColor(); Console.SetCursorPosition(100, 45); bool isRight = CompareAnswers(Console.ReadLine(), currentQuestion); MakeChanges(isRight, currentQuestion); } if (newGame.CurrentQuestion == 15) { PrintingEngine.PrintSessionInfo(newGame); PrintingEngine.YouAre_Millionaire(); } else { PrintingEngine.PrintGameOver(); } }