diff --git a/bulls-and-cows-cpp/CGame.cpp b/bulls-and-cows-cpp/CGame.cpp index 89709ca..6a0a7e9 100644 --- a/bulls-and-cows-cpp/CGame.cpp +++ b/bulls-and-cows-cpp/CGame.cpp @@ -13,6 +13,7 @@ void CGame::Init(int digits) m_ucBulls = 0; m_ucCows = 0; m_uStepCounter = 0; + m_sLastError = L""; std::random_device r; std::default_random_engine e(r()); @@ -48,7 +49,34 @@ void CGame::Start() ShowGuessedNumber(false); PrintSteps(); ret = GetNumber(step); - if (ret == -1) return; + switch (ret) + { + case -1: + { + return; + break; + } + case -2: + { + m_sLastError = L"Вы должны ввести " + std::to_wstring(m_ucDigits) + L"-значное число!"; + break; + } + case -3: + { + m_sLastError = L"Вы должны ввести число!"; + break; + } + case -4: + { + m_sLastError = L"Цифры в числе не должны повторяться!"; + break; + } + default: + { + m_sLastError = L""; + break; + } + } } while (ret < 0); m_uStepCounter++; } @@ -110,6 +138,7 @@ int CGame::GetNumber(CStep step) std::wstring sNumber; wchar_t c; + std::wcout << L"\t\t\t\t\t" << m_sLastError << L"\r"; std::wcout << L"=>\t"; std::wcin >> sNumber; if (sNumber == L"Q" || sNumber == L"q") return -1; @@ -140,29 +169,3 @@ int CGame::GetNumber(CStep step) return 0; } - -bool CGame::IsEqual1(const int* a, const int n, int j) -{ - j--; - bool result = false; - - while (j >= 0) - { - if (n == a[j]) result = true; - j--; - } - return result; -} - -bool CGame::IsEqual2(const std::wstring& a, const wchar_t n, int j) -{ - j--; - bool result = false; - - while (j >= 0) - { - if (n == a[j]) result = true; - j--; - } - return result; -} diff --git a/bulls-and-cows-cpp/CGame.h b/bulls-and-cows-cpp/CGame.h index c3a231a..90e3b17 100644 --- a/bulls-and-cows-cpp/CGame.h +++ b/bulls-and-cows-cpp/CGame.h @@ -15,6 +15,7 @@ private: bool m_fGameIsEnd; int m_uStepCounter; int* m_uGuessedNumber; + std::wstring m_sLastError; std::vector m_Steps; template