diff --git a/bulls-and-cows-cpp/CGame.cpp b/bulls-and-cows-cpp/CGame.cpp index f8c2b15..2db24e4 100644 --- a/bulls-and-cows-cpp/CGame.cpp +++ b/bulls-and-cows-cpp/CGame.cpp @@ -9,10 +9,10 @@ void CGame::Init() { - m_fGameIsEnd = false; m_ucBulls = 0; m_ucCows = 0; m_uStepCounter = 0; + m_fGameIsEnd = false; m_sLastError = L""; std::random_device r; @@ -20,6 +20,7 @@ void CGame::Init() 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) @@ -47,24 +48,19 @@ void CGame::Start() do { CPrint::GameHeader(); - ShowGuessedNumber(IS_SHOW); - PrintSteps(); + CPrint::GuessedNumber(this, IS_SHOW); + CPrint::Steps(this); } while (!GetNumber(step)); m_uStepCounter++; } CPrint::GameHeader(); - ShowGuessedNumber(true); - PrintSteps(); + CPrint::GuessedNumber(this, true); + CPrint::Steps(this); CPrint::GameFooter(this); } -int CGame::GetStepCounter() -{ - return m_uStepCounter; -} - bool CGame::GetNumber(CStep step) { std::wcout << L"\t\t\t\t\t" << m_sLastError << L"\r"; @@ -99,35 +95,6 @@ bool CGame::GetNumber(CStep step) return true; } -void CGame::ShowGuessedNumber(bool show) -{ - std::wcout << '\t'; - for (int i = 0; i < m_ucDigits; ++i) - { - show ? std::wcout << m_uGuessedNumber[i] : std::wcout << '#'; - } - std::wcout << '\n' << '\t'; - - for (int i = 0; i < m_ucDigits; ++i) - { - std::wcout << '-'; - } - std::wcout << std::endl; -} - -void CGame::PrintSteps() -{ - if (m_Steps.size() < 1) return; - - for (CStep& s : m_Steps) - { - std::wcout << '\t'; - for (auto& d : s.GetStepNumber()) std::wcout << d; - std::wcout << '\t' << s.GetStepAnimals().first << L" Б., " << s.GetStepAnimals().second << L" К."; - std::wcout << std::endl; - } -} - CGame::CGame() { CUserInput userInput(1); diff --git a/bulls-and-cows-cpp/CGame.h b/bulls-and-cows-cpp/CGame.h index 1509447..12d1181 100644 --- a/bulls-and-cows-cpp/CGame.h +++ b/bulls-and-cows-cpp/CGame.h @@ -9,26 +9,24 @@ class CGame { private: - int m_ucDigits = 4; // Number of digits into the guessed number int m_ucBulls; int m_ucCows; bool m_fGameIsEnd; - int m_uStepCounter; - int* m_uGuessedNumber; std::wstring m_sLastError; - std::vector m_Steps; bool GetNumber(CStep); - void ShowGuessedNumber(bool); - void PrintSteps(); template bool IsEqual(const T, const N, int); public: + int m_ucDigits; // Number of digits into the guessed number + int m_uStepCounter; + int* m_uGuessedNumber; + std::vector m_Steps; + void Init(); void Start(); - int GetStepCounter(); CGame(); ~CGame(); }; diff --git a/bulls-and-cows-cpp/CPrint.cpp b/bulls-and-cows-cpp/CPrint.cpp index ceb8004..9a4c567 100644 --- a/bulls-and-cows-cpp/CPrint.cpp +++ b/bulls-and-cows-cpp/CPrint.cpp @@ -1,24 +1,53 @@ -// Bulls and Cows the game +// Bulls and Cows the game // CPrint.cpp // #include "CPrint.h" #include +void CPrint::GameInitialQuery() +{ + std::wcout << L"Введите количество цифр в числе (от 3 до 5).\n"; + std::wcout << L"Чем больше цифр - тем сложнее. Обычно 4.\n" << std::endl; +} + void CPrint::GameHeader() { std::system("cls"); - std::wcout << L" ." << ' ' << L"" << ' ' << VERSION << std::endl; + std::wcout << L"Быки и Коровы." << ' ' << L"Версия" << ' ' << VERSION << std::endl; std::wcout << L"Copyright (c) 2023 by W0LF aka 'dreamforce'" << "\n\n" << std::endl; } -void CPrint::GameFooter(CGame *game) +void CPrint::GameFooter(CGame* const game) { - std::wcout << L"\n\n\t" << L"!!! !!!" << std::endl; - std::wcout << L"\t : " << game->GetStepCounter() << L"\n\n" << std::endl; + std::wcout << L"\n\n\t" << L"!!! П О Б Е Д А !!!" << std::endl; + std::wcout << L"\tКоличество ходов: " << game->m_uStepCounter << L"\n\n" << std::endl; } -void CPrint::GameInitialQuery() +void CPrint::Steps(CGame* const game) { - std::wcout << L" ( 3 5).\n"; - std::wcout << L" - . 4.\n" << std::endl; + if (game->m_Steps.size() < 1) return; + + for (CStep& s : game->m_Steps) + { + std::wcout << '\t'; + for (int& d : s.GetStepNumber()) std::wcout << d; + std::wcout << '\t' << s.GetStepAnimals().first << L" Б., " << s.GetStepAnimals().second << L" К."; + std::wcout << std::endl; + } +} + +void CPrint::GuessedNumber(CGame* const game, const bool show) +{ + std::wcout << '\t'; + for (int i = 0; i < game->m_ucDigits; ++i) + { + show ? std::wcout << game->m_uGuessedNumber[i] : std::wcout << '#'; + } + std::wcout << '\n' << '\t'; + + for (int i = 0; i < game->m_ucDigits; ++i) + { + std::wcout << '-'; + } + std::wcout << std::endl; } diff --git a/bulls-and-cows-cpp/CPrint.h b/bulls-and-cows-cpp/CPrint.h index a015d9f..194b7de 100644 --- a/bulls-and-cows-cpp/CPrint.h +++ b/bulls-and-cows-cpp/CPrint.h @@ -4,11 +4,12 @@ #pragma once #include "CGame.h" -static class CPrint +class CPrint { public: - static void GameHeader(); - static void GameFooter(CGame*); static void GameInitialQuery(); - + static void GameHeader(); + static void GameFooter(CGame* const); + static void Steps(CGame* const); + static void GuessedNumber(CGame* const, const bool); };