Moved string literals to the defines.h header.

This commit is contained in:
2023-08-08 17:50:51 +03:00
parent 5482fe1814
commit 036a8e4645
4 changed files with 31 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
// Bulls and Cows the game // Bulls and Cows the game
// CGame.cpp // CGame.cpp
// //
#include "defines.h"
#include "CGame.h" #include "CGame.h"
#include "CUserInput.h" #include "CUserInput.h"
#include "CPrint.h" #include "CPrint.h"
@@ -74,14 +75,14 @@ bool CGame::GetNumber(CStep step)
{ {
if (IsEqual(userInput.m_vUserInput, userInput.m_vUserInput.at(i), i)) if (IsEqual(userInput.m_vUserInput, userInput.m_vUserInput.at(i), i))
{ {
m_sLastError = L"Цифры в числе не должны повторяться!"; m_sLastError = strERROR_1;
return false; return false;
} }
} }
} }
else else
{ {
m_sLastError = L"Вы должны ввести " + std::to_wstring(m_ucDigits) + L"-значное число!"; m_sLastError = strERROR_2_1 + std::to_wstring(m_ucDigits) + strERROR_2_2;
return false; return false;
} }

View File

@@ -2,7 +2,6 @@
// CGame.h // CGame.h
// //
#pragma once #pragma once
#include "defines.h"
#include "CStep.h" #include "CStep.h"
#include <string> #include <string>

View File

@@ -1,26 +1,27 @@
// Bulls and Cows the game // Bulls and Cows the game
// CPrint.cpp // CPrint.cpp
// //
#include "CPrint.h" #include "CPrint.h"
#include "defines.h"
#include <iostream> #include <iostream>
void CPrint::GameInitialQuery() void CPrint::GameInitialQuery()
{ {
std::wcout << L"Введите количество цифр в числе (от 3 до 5).\n"; std::wcout << strINITIAL_QUERY_1;
std::wcout << L"Чем больше цифр - тем сложнее. Обычно 4.\n" << std::endl; std::wcout << strINITIAL_QUERY_2 << std::endl;
} }
void CPrint::GameHeader() void CPrint::GameHeader()
{ {
std::system("cls"); std::system("cls");
std::wcout << L"Быки и Коровы." << ' ' << L"Версия" << ' ' << VERSION << std::endl; std::wcout << strGAME_NAME << ' ' << strGAME_VERSION << ' ' << VERSION << std::endl;
std::wcout << L"Copyright (c) 2023 by W0LF aka 'dreamforce'" << "\n\n" << std::endl; std::wcout << strGAME_COPYRIGHT << "\n\n" << std::endl;
} }
void CPrint::GameFooter(CGame* const game) void CPrint::GameFooter(CGame* const game)
{ {
std::wcout << L"\n\n\t" << L"!!! П О Б Е Д А !!!" << std::endl; std::wcout << "\n\n\t" << strVICTORY << std::endl;
std::wcout << L"\tКоличество ходов: " << game->m_uStepCounter << L"\n\n" << std::endl; std::wcout << strNUM_STEPS << game->m_uStepCounter << "\n\n" << std::endl;
} }
void CPrint::Steps(CGame* const game) void CPrint::Steps(CGame* const game)
@@ -31,7 +32,7 @@ void CPrint::Steps(CGame* const game)
{ {
std::wcout << '\t'; std::wcout << '\t';
for (int& d : s.GetStepNumber()) std::wcout << d; for (int& d : s.GetStepNumber()) std::wcout << d;
std::wcout << '\t' << s.GetStepAnimals().first << L" Б., " << s.GetStepAnimals().second << L" К."; std::wcout << '\t' << s.GetStepAnimals().first << strBULLS << s.GetStepAnimals().second << strCOWS;
std::wcout << std::endl; std::wcout << std::endl;
} }
} }

View File

@@ -1,4 +1,4 @@
// Bulls and Cows the game // Bulls and Cows the game
// defines.h // defines.h
// //
#pragma once #pragma once
@@ -9,3 +9,20 @@
#else #else
#define IS_SHOW false #define IS_SHOW false
#endif #endif
#define strERROR_1 L"Цифры в числе не должны повторяться!"
#define strERROR_2_1 L"Вы должны ввести "
#define strERROR_2_2 L"-значное число!"
#define strBULLS L" Б., "
#define strCOWS L" К."
#define strINITIAL_QUERY_1 L"Введите количество цифр в числе (от 3 до 5).\n"
#define strINITIAL_QUERY_2 L"Чем больше цифр - тем сложнее. Обычно 4.\n"
#define strGAME_NAME L"Быки и Коровы."
#define strGAME_VERSION L"Версия"
#define strGAME_COPYRIGHT L"Copyright (c) 2023 by W0LF aka 'dreamforce'"
#define strVICTORY L"!!! П О Б Е Д А !!!"
#define strNUM_STEPS L"\tКоличество ходов: "