From f7572874b05b43fbd1cf4976b2fb8d1f5a450b93 Mon Sep 17 00:00:00 2001 From: W0LF Date: Mon, 7 Aug 2023 19:37:59 +0300 Subject: [PATCH] Removed headers.h file due to recursive inclusion. Also, moved Print*() methods to separate class. --- bulls-and-cows-cpp/CGame.cpp | 38 +++++++------------ bulls-and-cows-cpp/CGame.h | 8 ++-- bulls-and-cows-cpp/CPrint.cpp | 24 ++++++++++++ bulls-and-cows-cpp/CPrint.h | 14 +++++++ bulls-and-cows-cpp/CStep.h | 2 +- bulls-and-cows-cpp/CUserInput.cpp | 3 ++ bulls-and-cows-cpp/CUserInput.h | 2 +- bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj | 4 +- .../bulls-and-cows-cpp.vcxproj.filters | 5 ++- bulls-and-cows-cpp/bulls-and-cows.cpp | 1 - bulls-and-cows-cpp/headers.h | 12 ------ 11 files changed, 67 insertions(+), 46 deletions(-) create mode 100644 bulls-and-cows-cpp/CPrint.cpp create mode 100644 bulls-and-cows-cpp/CPrint.h delete mode 100644 bulls-and-cows-cpp/headers.h diff --git a/bulls-and-cows-cpp/CGame.cpp b/bulls-and-cows-cpp/CGame.cpp index f7c028c..f8c2b15 100644 --- a/bulls-and-cows-cpp/CGame.cpp +++ b/bulls-and-cows-cpp/CGame.cpp @@ -2,6 +2,10 @@ // CGame.cpp // #include "CGame.h" +#include "CUserInput.h" +#include "CPrint.h" +#include +#include void CGame::Init() { @@ -42,7 +46,7 @@ void CGame::Start() { do { - PrintGameHeader(); + CPrint::GameHeader(); ShowGuessedNumber(IS_SHOW); PrintSteps(); } while (!GetNumber(step)); @@ -50,10 +54,15 @@ void CGame::Start() m_uStepCounter++; } - PrintGameHeader(); + CPrint::GameHeader(); ShowGuessedNumber(true); PrintSteps(); - PrintGameFooter(); + CPrint::GameFooter(this); +} + +int CGame::GetStepCounter() +{ + return m_uStepCounter; } bool CGame::GetNumber(CStep step) @@ -106,25 +115,6 @@ void CGame::ShowGuessedNumber(bool show) std::wcout << std::endl; } -void CGame::PrintGameHeader() -{ - std::system("cls"); - std::wcout << L"Быки и Коровы." << ' ' << L"Версия" << ' ' << VERSION << std::endl; - std::wcout << L"Copyright (c) 2023 by W0LF aka 'dreamforce'" << "\n\n" << std::endl; -} - -void CGame::PrintGameFooter() -{ - std::wcout << L"\n\n\t" << L"!!! П О Б Е Д А !!!" << std::endl; - std::wcout << L"\tКоличество ходов: " << m_uStepCounter << L"\n\n" << std::endl; -} - -void CGame::PrintGameInitialQuery() -{ - std::wcout << L"Введите количество цифр в числе (от 3 до 5).\n"; - std::wcout << L"Чем больше цифр - тем сложнее. Обычно 4.\n" << std::endl; -} - void CGame::PrintSteps() { if (m_Steps.size() < 1) return; @@ -146,8 +136,8 @@ CGame::CGame() do { - PrintGameHeader(); - PrintGameInitialQuery(); + CPrint::GameHeader(); + CPrint::GameInitialQuery(); std::wcout << "=> "; if (userInput.Get()) diff --git a/bulls-and-cows-cpp/CGame.h b/bulls-and-cows-cpp/CGame.h index e3da5a9..1509447 100644 --- a/bulls-and-cows-cpp/CGame.h +++ b/bulls-and-cows-cpp/CGame.h @@ -2,9 +2,9 @@ // CGame.h // #pragma once -#include "headers.h" -#include "CUserInput.h" +#include "defines.h" #include "CStep.h" +#include class CGame { @@ -20,9 +20,6 @@ private: bool GetNumber(CStep); void ShowGuessedNumber(bool); - void PrintGameHeader(); - void PrintGameFooter(); - void PrintGameInitialQuery(); void PrintSteps(); template @@ -31,6 +28,7 @@ private: public: void Init(); void Start(); + int GetStepCounter(); CGame(); ~CGame(); }; diff --git a/bulls-and-cows-cpp/CPrint.cpp b/bulls-and-cows-cpp/CPrint.cpp new file mode 100644 index 0000000..ceb8004 --- /dev/null +++ b/bulls-and-cows-cpp/CPrint.cpp @@ -0,0 +1,24 @@ +// Bulls and Cows the game +// CPrint.cpp +// +#include "CPrint.h" +#include + +void CPrint::GameHeader() +{ + std::system("cls"); + 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) +{ + std::wcout << L"\n\n\t" << L"!!! !!!" << std::endl; + std::wcout << L"\t : " << game->GetStepCounter() << L"\n\n" << std::endl; +} + +void CPrint::GameInitialQuery() +{ + std::wcout << L" ( 3 5).\n"; + std::wcout << L" - . 4.\n" << std::endl; +} diff --git a/bulls-and-cows-cpp/CPrint.h b/bulls-and-cows-cpp/CPrint.h new file mode 100644 index 0000000..a015d9f --- /dev/null +++ b/bulls-and-cows-cpp/CPrint.h @@ -0,0 +1,14 @@ +// Bulls and Cows the game +// CPrint.h +// +#pragma once +#include "CGame.h" + +static class CPrint +{ +public: + static void GameHeader(); + static void GameFooter(CGame*); + static void GameInitialQuery(); + +}; diff --git a/bulls-and-cows-cpp/CStep.h b/bulls-and-cows-cpp/CStep.h index 07f2659..d8f72f9 100644 --- a/bulls-and-cows-cpp/CStep.h +++ b/bulls-and-cows-cpp/CStep.h @@ -2,7 +2,7 @@ // CStep.h // #pragma once -#include "headers.h" +#include class CStep { diff --git a/bulls-and-cows-cpp/CUserInput.cpp b/bulls-and-cows-cpp/CUserInput.cpp index cd72899..39808b6 100644 --- a/bulls-and-cows-cpp/CUserInput.cpp +++ b/bulls-and-cows-cpp/CUserInput.cpp @@ -2,6 +2,9 @@ // CUserInput.cpp // #include "CUserInput.h" +#include +#include +#include CUserInput::CUserInput(int nNumOfDigits) { diff --git a/bulls-and-cows-cpp/CUserInput.h b/bulls-and-cows-cpp/CUserInput.h index b76d810..ff1e6d7 100644 --- a/bulls-and-cows-cpp/CUserInput.h +++ b/bulls-and-cows-cpp/CUserInput.h @@ -2,7 +2,7 @@ // CUserInput.h // #pragma once -#include "headers.h" +#include class CUserInput { diff --git a/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj b/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj index 8eac939..e4149f3 100644 --- a/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj +++ b/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj @@ -77,6 +77,7 @@ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpp17 + 4018;%(DisableSpecificWarnings) Console @@ -133,16 +134,17 @@ + + - 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 b750d60..949345f 100644 --- a/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj.filters +++ b/bulls-and-cows-cpp/bulls-and-cows-cpp.vcxproj.filters @@ -30,6 +30,9 @@ Source Files + + Source Files + @@ -47,7 +50,7 @@ Header Files - + Header Files diff --git a/bulls-and-cows-cpp/bulls-and-cows.cpp b/bulls-and-cows-cpp/bulls-and-cows.cpp index 87d9e63..c7de317 100644 --- a/bulls-and-cows-cpp/bulls-and-cows.cpp +++ b/bulls-and-cows-cpp/bulls-and-cows.cpp @@ -1,7 +1,6 @@ // Bulls and Cows the game // bulls-and-cows.cpp // -#include "headers.h" #include "..\..\..\MyFunctions\SetUserLocale.h" #include "CGame.h" diff --git a/bulls-and-cows-cpp/headers.h b/bulls-and-cows-cpp/headers.h deleted file mode 100644 index 887c870..0000000 --- a/bulls-and-cows-cpp/headers.h +++ /dev/null @@ -1,12 +0,0 @@ -// Bulls and Cows the game -// headers.h -// -#pragma once -#include -#include -#include -#include -#include -#include - -#include "defines.h"