Removed headers.h file due to recursive inclusion.

Also, moved Print*() methods to separate class.
This commit is contained in:
2023-08-07 19:37:59 +03:00
parent 33d1f783ac
commit f7572874b0
11 changed files with 67 additions and 46 deletions

View File

@@ -2,6 +2,10 @@
// CGame.cpp
//
#include "CGame.h"
#include "CUserInput.h"
#include "CPrint.h"
#include <iostream>
#include <random>
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())

View File

@@ -2,9 +2,9 @@
// CGame.h
//
#pragma once
#include "headers.h"
#include "CUserInput.h"
#include "defines.h"
#include "CStep.h"
#include <string>
class CGame
{
@@ -20,9 +20,6 @@ private:
bool GetNumber(CStep);
void ShowGuessedNumber(bool);
void PrintGameHeader();
void PrintGameFooter();
void PrintGameInitialQuery();
void PrintSteps();
template<typename T, typename N>
@@ -31,6 +28,7 @@ private:
public:
void Init();
void Start();
int GetStepCounter();
CGame();
~CGame();
};

View File

@@ -0,0 +1,24 @@
// Bulls and Cows the game
// CPrint.cpp
//
#include "CPrint.h"
#include <iostream>
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;
}

View File

@@ -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();
};

View File

@@ -2,7 +2,7 @@
// CStep.h
//
#pragma once
#include "headers.h"
#include <vector>
class CStep
{

View File

@@ -2,6 +2,9 @@
// CUserInput.cpp
//
#include "CUserInput.h"
#include <iostream>
#include <string>
#include <cwctype>
CUserInput::CUserInput(int nNumOfDigits)
{

View File

@@ -2,7 +2,7 @@
// CUserInput.h
//
#pragma once
#include "headers.h"
#include <vector>
class CUserInput
{

View File

@@ -77,6 +77,7 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<DisableSpecificWarnings>4018;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -133,16 +134,17 @@
<ClCompile Include="..\..\..\MyFunctions\SetUserLocale.cpp" />
<ClCompile Include="bulls-and-cows.cpp" />
<ClCompile Include="CGame.cpp" />
<ClCompile Include="CPrint.cpp" />
<ClCompile Include="CStep.cpp" />
<ClCompile Include="CUserInput.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\MyFunctions\SetUserLocale.h" />
<ClInclude Include="CGame.h" />
<ClInclude Include="CPrint.h" />
<ClInclude Include="CStep.h" />
<ClInclude Include="CUserInput.h" />
<ClInclude Include="defines.h" />
<ClInclude Include="headers.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@@ -30,6 +30,9 @@
<ClCompile Include="CUserInput.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CPrint.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CGame.h">
@@ -47,7 +50,7 @@
<ClInclude Include="defines.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="headers.h">
<ClInclude Include="CPrint.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>

View File

@@ -1,7 +1,6 @@
// Bulls and Cows the game
// bulls-and-cows.cpp
//
#include "headers.h"
#include "..\..\..\MyFunctions\SetUserLocale.h"
#include "CGame.h"

View File

@@ -1,12 +0,0 @@
// Bulls and Cows the game
// headers.h
//
#pragma once
#include <Windows.h>
#include <iostream>
#include <random>
#include <string>
#include <vector>
#include <cwctype>
#include "defines.h"