diff --git a/bulls-and-cows-cpp/CGame.cpp b/bulls-and-cows-cpp/CGame.cpp index 7e152c3..8942a39 100644 --- a/bulls-and-cows-cpp/CGame.cpp +++ b/bulls-and-cows-cpp/CGame.cpp @@ -172,10 +172,11 @@ CGame::CGame() PrintGameHeader(); std::wcout << L"Введите количество цифр в числе (от 3 до 7).\n"; std::wcout << L"Чем больше цифр - тем сложнее. Обычно 4.\n"; - std::wcout << L"> "; + std::wcout << L"=> "; + if (userInput.Get()) { - if (userInput.m_vUserInput.at(0) >= 3 && userInput.m_vUserInput.at(0) <= 7) + if ((userInput.m_vUserInput.at(0) >= 3) && (userInput.m_vUserInput.at(0) <= 7)) { m_ucDigits = userInput.m_vUserInput.at(0); ok = true; @@ -186,8 +187,6 @@ CGame::CGame() } } } while (!ok); - - std::wcout << L"m_ucDigits: " << m_ucDigits << std::endl; } CGame::~CGame() diff --git a/bulls-and-cows-cpp/CUserInput.cpp b/bulls-and-cows-cpp/CUserInput.cpp index 6801a1f..7da6378 100644 --- a/bulls-and-cows-cpp/CUserInput.cpp +++ b/bulls-and-cows-cpp/CUserInput.cpp @@ -7,7 +7,7 @@ CUserInput::CUserInput(int nNumOfDigits) m_nNumOfExpectedDigits = nNumOfDigits; } -int CUserInput::Get() +bool CUserInput::Get() { std::wstring sDigits; wchar_t cDigit; @@ -15,14 +15,9 @@ int CUserInput::Get() std::getline(std::wcin, sDigits); - if (sDigits == L"Q" || sDigits == L"q") - { - return -1; - } - if (sDigits.length() != m_nNumOfExpectedDigits) { - return -2; + return false; } for (unsigned i = 0; i < m_nNumOfExpectedDigits; i++) @@ -31,10 +26,10 @@ int CUserInput::Get() if (!(bool)std::iswdigit(cDigit)) { m_vUserInput.clear(); - return -2; + return false; } nDigit = ((int)cDigit) - 48; m_vUserInput.push_back(nDigit); } - return 0; + return true; } diff --git a/bulls-and-cows-cpp/CUserInput.h b/bulls-and-cows-cpp/CUserInput.h index 4c5e360..8b7ead0 100644 --- a/bulls-and-cows-cpp/CUserInput.h +++ b/bulls-and-cows-cpp/CUserInput.h @@ -14,5 +14,5 @@ public: std::vector m_vUserInput; CUserInput(int nNumOfExpectedDigits); - int Get(); + bool Get(); };