diff --git a/bulls-and-cows-cpp/CGame.cpp b/bulls-and-cows-cpp/CGame.cpp index efffb8d..29b71bd 100644 --- a/bulls-and-cows-cpp/CGame.cpp +++ b/bulls-and-cows-cpp/CGame.cpp @@ -2,9 +2,66 @@ // #include "CGame.h" #include +#include // Initialize the variables void CGame::Init() { - // TODO: Add your implementation code here. + m_ucBulls = 0; + m_ucCows = 0; + m_uStepCounter = 0; + + std::random_device r; + std::default_random_engine e(r()); + std::uniform_int_distribution d(0, 9); + + m_uGuessedNumber = new int[m_ucDigits] { 0 }; + int n = 0; + + for (int i = 0; i < m_ucDigits; ++i) + { + n = d(e); + if (i > 0) + { + while (CGame::IsEqual(n, i)) + { + n = d(e); + } + } + m_uGuessedNumber[i] = n; + } + + +} + +void CGame::ShowGuessedNumber() +{ + for (int i = 0; i < m_ucDigits; ++i) + { + std::cout << m_uGuessedNumber[i]; + } + std::cout << std::endl; +} + +void CGame::PrintGameHeader() +{ + std::wcout << L"Быки и Коровы. Версия " << VERSION << std::endl; +} + +bool CGame::IsEqual(int n, int j) +{ + j--; + bool result = false; + + while (j >= 0) + { + if (n == m_uGuessedNumber[j]) result = true; + j--; + } + return result; +} + +CGame::CGame(int digits) +{ + m_ucDigits = digits; } diff --git a/bulls-and-cows-cpp/CGame.h b/bulls-and-cows-cpp/CGame.h index 8bf615d..54eabe4 100644 --- a/bulls-and-cows-cpp/CGame.h +++ b/bulls-and-cows-cpp/CGame.h @@ -1,18 +1,27 @@ // CGame.h // #pragma once +#include "CStep.h" +#include + +#define VERSION 0.1 class CGame { private: - unsigned int m_uStepCounter; - unsigned int m_uGuessedNumber; + unsigned char m_ucDigits; + int m_uStepCounter; + int* m_uGuessedNumber; + std::vector m_Step; + + bool IsEqual(int, int); + public: unsigned char m_ucBulls; unsigned char m_ucCows; -private: - // Initialize the variables void Init(); + void ShowGuessedNumber(); + void PrintGameHeader(); + CGame(int); }; - diff --git a/bulls-and-cows-cpp/CStep.cpp b/bulls-and-cows-cpp/CStep.cpp new file mode 100644 index 0000000..e2d70da --- /dev/null +++ b/bulls-and-cows-cpp/CStep.cpp @@ -0,0 +1,4 @@ +// CStep.cpp +// +#include "CStep.h" + diff --git a/bulls-and-cows-cpp/CStep.h b/bulls-and-cows-cpp/CStep.h new file mode 100644 index 0000000..d899601 --- /dev/null +++ b/bulls-and-cows-cpp/CStep.h @@ -0,0 +1,11 @@ +// CStep.h +// +#pragma once +#include + +class CStep +{ +public: + std::tuple m_uStepNumber; + std::tuple m_ucStepAnimals; +}; diff --git a/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj b/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj index 2b937c6..9ef9cf3 100644 --- a/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj +++ b/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj @@ -129,11 +129,15 @@ + + + + diff --git a/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj.filters b/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj.filters index 11ad751..efee5fb 100644 --- a/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj.filters +++ b/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj.filters @@ -21,10 +21,22 @@ Source Files + + Source Files + + + Source Files + Header Files + + Header Files + + + Header Files + \ No newline at end of file diff --git a/bulls-and-cows-cpp/bulls-and-cows.cpp b/bulls-and-cows-cpp/bulls-and-cows.cpp index 14cb7e2..775c7a4 100644 --- a/bulls-and-cows-cpp/bulls-and-cows.cpp +++ b/bulls-and-cows-cpp/bulls-and-cows.cpp @@ -1,14 +1,16 @@ // bulls-and-cows.cpp // -#include -#include -#include -#include +#include +#include "..\..\..\MyFunctions\SetUserLocale.h" #include "CGame.h" int wmain(int argc, wchar_t* argv[]) { + if (!SetUserLocale()) return 1; + CGame game(4); + game.Init(); + game.PrintGameHeader();