/// <summary> /// This method proceeds to the next or to the previous level. /// </summary> private void Proceed() { int choice = ChosenNumbers.Peek(); // If choice is 0, then we should go back to the previous level or stay if we are at level 0. if (choice == 0) { if (ChosenNumbers.GetSize() > 1) { InputOutputDevice.Write(PhraseProvider.GetPhrase(PhraseTypes.LevellingDownMessage)); ChosenNumbers.Pop(); int previousChoice = ChosenNumbers.Pop(); for (int i = 0; i < Numbers.Length; i++) { Numbers[i] /= previousChoice; } PrintNumbers(); InputOutputDevice.WriteLine(); } else { ChosenNumbers.Pop(); InputOutputDevice.WriteError(PhraseProvider.GetPhrase(PhraseTypes.LevellingDownErrorMessage)); } } // If choice is not 0, then we should go to the next level. Return if level 4, because it is a last level. else { if (ChosenNumbers.GetSize() == 4) { return; } InputOutputDevice.Write(string.Format(PhraseProvider.GetPhrase(PhraseTypes.LevellingUpMessage), choice)); StringBuilder levelLogs = new StringBuilder("( "); for (int i = 0; i < Numbers.Length; i++) { levelLogs.AppendFormat($"{Numbers[i]}x{choice} "); Numbers[i] *= choice; } levelLogs.Append(")"); PrintNumbers(); InputOutputDevice.WriteLine(levelLogs.ToString()); } }
/// <summary> /// This is a method used to start the game. /// </summary> public void Play() { InputOutputDevice.WriteLine(PhraseProvider.GetPhrase(PhraseTypes.Welcome)); InputOutputDevice.WriteLine(PhraseProvider.GetPhrase(PhraseTypes.NumberOfDoors)); Numbers = ArrayGenerator.GetArray(SettingsProvider.GetNumberOfDoors()); while (ChosenNumbers.GetSize() < 4) { InputOutputDevice.WriteLine(PhraseProvider.GetPhrase(PhraseTypes.LevelMessage) + (ChosenNumbers.GetSize() + 1)); InputOutputDevice.Write(PhraseProvider.GetPhrase(PhraseTypes.NumbersMessage)); PrintNumbers(); InputOutputDevice.WriteLine(); GetNumberFromPlayer(); Proceed(); } InputOutputDevice.WriteLine(); InputOutputDevice.Write(PhraseProvider.GetPhrase(PhraseTypes.WinMessage)); }