mirror of
https://gitflic.ru/project/w0lf/bulls-and-cows-cpp.git
synced 2026-03-28 16:02:46 +03:00
37 lines
600 B
C++
37 lines
600 B
C++
// Bulls and Cows the game
|
|
// CUserInput.cpp
|
|
//
|
|
#include "CUserInput.h"
|
|
|
|
CUserInput::CUserInput(int nNumOfDigits)
|
|
{
|
|
m_nNumOfExpectedDigits = nNumOfDigits;
|
|
}
|
|
|
|
bool CUserInput::Get()
|
|
{
|
|
std::wstring sDigits;
|
|
wchar_t cDigit;
|
|
int nDigit;
|
|
|
|
std::getline(std::wcin, sDigits);
|
|
|
|
if (sDigits.length() != m_nNumOfExpectedDigits)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
for (unsigned i = 0; i < m_nNumOfExpectedDigits; i++)
|
|
{
|
|
cDigit = sDigits.at(i);
|
|
if (!(bool)std::iswdigit(cDigit))
|
|
{
|
|
m_vUserInput.clear();
|
|
return false;
|
|
}
|
|
nDigit = ((int)cDigit) - 48;
|
|
m_vUserInput.push_back(nDigit);
|
|
}
|
|
return true;
|
|
}
|