mirror of
https://gitflic.ru/project/w0lf/bulls-and-cows-cpp.git
synced 2026-03-28 16:02:46 +03:00
Removed headers.h file due to recursive inclusion.
Also, moved Print*() methods to separate class.
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
// CGame.cpp
|
// CGame.cpp
|
||||||
//
|
//
|
||||||
#include "CGame.h"
|
#include "CGame.h"
|
||||||
|
#include "CUserInput.h"
|
||||||
|
#include "CPrint.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
void CGame::Init()
|
void CGame::Init()
|
||||||
{
|
{
|
||||||
@@ -42,7 +46,7 @@ void CGame::Start()
|
|||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
PrintGameHeader();
|
CPrint::GameHeader();
|
||||||
ShowGuessedNumber(IS_SHOW);
|
ShowGuessedNumber(IS_SHOW);
|
||||||
PrintSteps();
|
PrintSteps();
|
||||||
} while (!GetNumber(step));
|
} while (!GetNumber(step));
|
||||||
@@ -50,10 +54,15 @@ void CGame::Start()
|
|||||||
m_uStepCounter++;
|
m_uStepCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintGameHeader();
|
CPrint::GameHeader();
|
||||||
ShowGuessedNumber(true);
|
ShowGuessedNumber(true);
|
||||||
PrintSteps();
|
PrintSteps();
|
||||||
PrintGameFooter();
|
CPrint::GameFooter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CGame::GetStepCounter()
|
||||||
|
{
|
||||||
|
return m_uStepCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGame::GetNumber(CStep step)
|
bool CGame::GetNumber(CStep step)
|
||||||
@@ -106,25 +115,6 @@ void CGame::ShowGuessedNumber(bool show)
|
|||||||
std::wcout << std::endl;
|
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()
|
void CGame::PrintSteps()
|
||||||
{
|
{
|
||||||
if (m_Steps.size() < 1) return;
|
if (m_Steps.size() < 1) return;
|
||||||
@@ -146,8 +136,8 @@ CGame::CGame()
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
PrintGameHeader();
|
CPrint::GameHeader();
|
||||||
PrintGameInitialQuery();
|
CPrint::GameInitialQuery();
|
||||||
std::wcout << "=> ";
|
std::wcout << "=> ";
|
||||||
|
|
||||||
if (userInput.Get())
|
if (userInput.Get())
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
// CGame.h
|
// CGame.h
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "headers.h"
|
#include "defines.h"
|
||||||
#include "CUserInput.h"
|
|
||||||
#include "CStep.h"
|
#include "CStep.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class CGame
|
class CGame
|
||||||
{
|
{
|
||||||
@@ -20,9 +20,6 @@ private:
|
|||||||
|
|
||||||
bool GetNumber(CStep);
|
bool GetNumber(CStep);
|
||||||
void ShowGuessedNumber(bool);
|
void ShowGuessedNumber(bool);
|
||||||
void PrintGameHeader();
|
|
||||||
void PrintGameFooter();
|
|
||||||
void PrintGameInitialQuery();
|
|
||||||
void PrintSteps();
|
void PrintSteps();
|
||||||
|
|
||||||
template<typename T, typename N>
|
template<typename T, typename N>
|
||||||
@@ -31,6 +28,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
void Init();
|
void Init();
|
||||||
void Start();
|
void Start();
|
||||||
|
int GetStepCounter();
|
||||||
CGame();
|
CGame();
|
||||||
~CGame();
|
~CGame();
|
||||||
};
|
};
|
||||||
|
|||||||
24
bulls-and-cows-cpp/CPrint.cpp
Normal file
24
bulls-and-cows-cpp/CPrint.cpp
Normal 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;
|
||||||
|
}
|
||||||
14
bulls-and-cows-cpp/CPrint.h
Normal file
14
bulls-and-cows-cpp/CPrint.h
Normal 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();
|
||||||
|
|
||||||
|
};
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// CStep.h
|
// CStep.h
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "headers.h"
|
#include <vector>
|
||||||
|
|
||||||
class CStep
|
class CStep
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
// CUserInput.cpp
|
// CUserInput.cpp
|
||||||
//
|
//
|
||||||
#include "CUserInput.h"
|
#include "CUserInput.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <cwctype>
|
||||||
|
|
||||||
CUserInput::CUserInput(int nNumOfDigits)
|
CUserInput::CUserInput(int nNumOfDigits)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// CUserInput.h
|
// CUserInput.h
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "headers.h"
|
#include <vector>
|
||||||
|
|
||||||
class CUserInput
|
class CUserInput
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -77,6 +77,7 @@
|
|||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
<DisableSpecificWarnings>4018;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -133,16 +134,17 @@
|
|||||||
<ClCompile Include="..\..\..\MyFunctions\SetUserLocale.cpp" />
|
<ClCompile Include="..\..\..\MyFunctions\SetUserLocale.cpp" />
|
||||||
<ClCompile Include="bulls-and-cows.cpp" />
|
<ClCompile Include="bulls-and-cows.cpp" />
|
||||||
<ClCompile Include="CGame.cpp" />
|
<ClCompile Include="CGame.cpp" />
|
||||||
|
<ClCompile Include="CPrint.cpp" />
|
||||||
<ClCompile Include="CStep.cpp" />
|
<ClCompile Include="CStep.cpp" />
|
||||||
<ClCompile Include="CUserInput.cpp" />
|
<ClCompile Include="CUserInput.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\..\MyFunctions\SetUserLocale.h" />
|
<ClInclude Include="..\..\..\MyFunctions\SetUserLocale.h" />
|
||||||
<ClInclude Include="CGame.h" />
|
<ClInclude Include="CGame.h" />
|
||||||
|
<ClInclude Include="CPrint.h" />
|
||||||
<ClInclude Include="CStep.h" />
|
<ClInclude Include="CStep.h" />
|
||||||
<ClInclude Include="CUserInput.h" />
|
<ClInclude Include="CUserInput.h" />
|
||||||
<ClInclude Include="defines.h" />
|
<ClInclude Include="defines.h" />
|
||||||
<ClInclude Include="headers.h" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
|||||||
@@ -30,6 +30,9 @@
|
|||||||
<ClCompile Include="CUserInput.cpp">
|
<ClCompile Include="CUserInput.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="CPrint.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="CGame.h">
|
<ClInclude Include="CGame.h">
|
||||||
@@ -47,7 +50,7 @@
|
|||||||
<ClInclude Include="defines.h">
|
<ClInclude Include="defines.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="headers.h">
|
<ClInclude Include="CPrint.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// Bulls and Cows the game
|
// Bulls and Cows the game
|
||||||
// bulls-and-cows.cpp
|
// bulls-and-cows.cpp
|
||||||
//
|
//
|
||||||
#include "headers.h"
|
|
||||||
#include "..\..\..\MyFunctions\SetUserLocale.h"
|
#include "..\..\..\MyFunctions\SetUserLocale.h"
|
||||||
#include "CGame.h"
|
#include "CGame.h"
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
|
||||||
Reference in New Issue
Block a user