Skip to content

Commit 27f802d

Browse files
cardodge refactor, cardodge settings integration, game command, help command update
1 parent 2cf52d8 commit 27f802d

22 files changed

+1864
-1897
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ dlldata.c
5858
# All ZeeTerminal files that are automatically generated
5959
ZT_Config.ini
6060
NotesFile.txt
61+
GameHighScores.dat
6162

6263
# Benchmark Results
6364
BenchmarkDotNet.Artifacts/

CommandFiles/CommandHelpMessages.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ void SettingsHelp() {
174174
<< wordWrap("\n --commandlogging <toggle>\tEnable command input info logging. Set either true/t or false/f in place of <toggle>.")
175175
<< wordWrap("\n --usrinputlogging <toggle>\tEnable user input info logging. Set either true/t or false/f in place of <toggle>.")
176176
<< wordWrap("\n --newoptionselect <toggle>\tUse the new OptionSelect Engine style. Set either true/t or false/f in place of <toggle>.")
177+
<< wordWrap("\n --cdcarturnspeed <speed>\tSet the car turning speed in the CarDodge game. Cannot be >10 and <1. Put the speed in place of <speed>.")
178+
<< wordWrap("\n --cdstartupcar <car>\t\tToggle the type of car auto-selected on startup in the CarDodge game. Put the car style in place of <style>.")
179+
<< wordWrap("\n --cdforeground <num>\tSet the foreground colour in the CarDodge game. Put the colour number in place of <num>.")
180+
<< wordWrap("\n --cdbackground <num>\tSet the background colour in the CarDodge game. Put the colour number in place of <num>.")
177181
<< wordWrap("\n\nExample: settings --titlefore 1")
178182
<< wordWrap("\n\nNote: You can get colour numbers by executing the \"ColourNumbers\" command.") << "\n\n";
179183

@@ -1010,5 +1014,26 @@ void BunnyHelp() {
10101014
"\n --quote\t\tMake the bunny say a random quote from Nikola Tesla, Albert Einstein or Thomas Edison.\n -c\t\t\tOutput the bunny in a randomised colour.\n\n"
10111015
"Example: bunny --saytext \"Hello, I am a bunny\"\n\nNOTE: Please make sure that when using spaces in the <text> argument with --saytext, use quotes (\"\").\n\n");
10121016

1017+
return;
1018+
}
1019+
1020+
// GameHelp
1021+
void GameHelp() {
1022+
CentreColouredText(" ___GAME___ ", 1);
1023+
std::cout << "\n";
1024+
CentreColouredText("This command allows you to access the games within ZeeTerminal.", 2);
1025+
std::cout << "\n\n";
1026+
1027+
colourSubheading();
1028+
std::cout << "What this command does:" << NOULINE_STR;
1029+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1030+
std::cout << wordWrap("\n- This command allows you to access the games within ZeeTerminal.\n- These games may have settings that you can adjust. These can be found in the Settings command.\n\n");
1031+
1032+
colourSubheading();
1033+
std::cout << "Possible arguments for this command:" << NOULINE_STR;
1034+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1035+
std::cout << wordWrap("\n -h\t\tDisplays this help message.\n --cardodge\tStarts the CarDodge game, a game where you dodge enemy cars to gain points.\n\n"
1036+
"Example: game --cardodge\n\n");
1037+
10131038
return;
10141039
}

CommandFiles/CommandsFile.cpp

Lines changed: 106 additions & 28 deletions
Large diffs are not rendered by default.

CommandFiles/Settings.cpp

Lines changed: 142 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ void LogFileSystemSettings(short int nChoice = 0, short int nChoiceLogging = 0,
825825

826826
// Error
827827
else {
828-
VerbosityDisplay("In OtherSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
828+
VerbosityDisplay("In LogFileSystemSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
829829
UserErrorDisplay("ERROR - Unknown error occured. Please try again later.\n");
830830

831831
return;
@@ -879,7 +879,7 @@ void LogFileSystemSettings(short int nChoice = 0, short int nChoiceLogging = 0,
879879

880880
// Error
881881
else {
882-
VerbosityDisplay("In OtherSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
882+
VerbosityDisplay("In LogFileSystemSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
883883
UserErrorDisplay("ERROR - Unknown error occured. Please try again later.\n");
884884

885885
return;
@@ -933,7 +933,7 @@ void LogFileSystemSettings(short int nChoice = 0, short int nChoiceLogging = 0,
933933

934934
// Error
935935
else {
936-
VerbosityDisplay("In OtherSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
936+
VerbosityDisplay("In LogFileSystemSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
937937
UserErrorDisplay("ERROR - Unknown error occured. Please try again later.\n");
938938

939939
return;
@@ -987,7 +987,7 @@ void LogFileSystemSettings(short int nChoice = 0, short int nChoiceLogging = 0,
987987

988988
// Error
989989
else {
990-
VerbosityDisplay("In OtherSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
990+
VerbosityDisplay("In LogFileSystemSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
991991
UserErrorDisplay("ERROR - Unknown error occured. Please try again later.\n");
992992

993993
return;
@@ -1041,7 +1041,7 @@ void LogFileSystemSettings(short int nChoice = 0, short int nChoiceLogging = 0,
10411041

10421042
// Error
10431043
else {
1044-
VerbosityDisplay("In OtherSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
1044+
VerbosityDisplay("In LogFileSystemSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
10451045
UserErrorDisplay("ERROR - Unknown error occured. Please try again later.\n");
10461046

10471047
return;
@@ -1054,7 +1054,143 @@ void LogFileSystemSettings(short int nChoice = 0, short int nChoiceLogging = 0,
10541054
}
10551055
else
10561056
{
1057-
VerbosityDisplay("In OtherSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
1057+
VerbosityDisplay("In LogFileSystemSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
1058+
UserErrorDisplay("ERROR - Unknown error occured. Please try again later.\n");
1059+
1060+
return;
1061+
}
1062+
}
1063+
1064+
void CarDodgeGameSettings(short int nChoiceMain = 0, int nChoiceCarTurnSpeed = 0, int nChoiceStartupCar = 0, int nChoiceForeground = 0, int nChoiceBackground = 0) {
1065+
OptionSelectEngine oseCarDodgeSettings;
1066+
1067+
if (nChoiceMain == 0) {
1068+
oseCarDodgeSettings.nSizeOfOptions = 4;
1069+
std::string sOptions[] = {
1070+
"Car Turning Speed",
1071+
"Game Startup Car",
1072+
"Game Foreground Colour",
1073+
"Game Background Colour"
1074+
};
1075+
oseCarDodgeSettings.sOptions = sOptions;
1076+
nChoiceMain = oseCarDodgeSettings.OptionSelect("Please select which setting you want to change relating to the Car Dodge game:", " ___CAR DODGE GAME SETTINGS___ ");
1077+
}
1078+
1079+
if (nChoiceMain == 1) {
1080+
while (true) {
1081+
if (nChoiceCarTurnSpeed == 0) {
1082+
CentreColouredText(" ___CAR TURN SPEED SETINGS___ ", 1);
1083+
std::cout << "\n";
1084+
colourSubheading(); // extra info colour is the same as subheading colour
1085+
std::cout << wordWrap("This speed is a measure of characters moved left/right per keypress, so higher numbers are faster.") << NOULINE_STR;
1086+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1087+
std::cout << "\nDefault Speed: 2\nCurrent Speed: " << ConfigObjMain.nCarDodgeCarTurningSpeed << wordWrap("\n\nInput 0 to exit. Turning speed cannot be lower than 1 or higher than 10.") << '\n';
1088+
1089+
nChoiceCarTurnSpeed = NumInputi("Please input how fast you want the car to turn: > ");
1090+
}
1091+
1092+
if (nChoiceCarTurnSpeed == 0) {
1093+
colour(YLW, ConfigObjMain.sColourGlobalBack);
1094+
std::cout << "Modifying setting terminated.\n";
1095+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1096+
return;
1097+
}
1098+
else if (nChoiceCarTurnSpeed < 1 || nChoiceCarTurnSpeed > 10) {
1099+
colour(YLW, ConfigObjMain.sColourGlobalBack);
1100+
std::cout << "Sorry, but you can't have a speed number lower than 1 or higher than 10. Please try again.\n";
1101+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1102+
return;
1103+
}
1104+
else break;
1105+
}
1106+
1107+
ConfigObjMain.nCarDodgeCarTurningSpeed = nChoiceCarTurnSpeed;
1108+
ConfigObjMain.WriteConfigFile();
1109+
1110+
colour(LGRN, ConfigObjMain.sColourGlobalBack);
1111+
std::cout << wordWrap("CarDodge Car Turning Speed has successfully been set to " + std::to_string(ConfigObjMain.nCarDodgeCarTurningSpeed) + " in character speed.\n");
1112+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1113+
1114+
return;
1115+
1116+
}
1117+
else if (nChoiceMain == 2) {
1118+
std::string sOptions[] = {
1119+
"KartCar (Default)",
1120+
"TheHoverRocket",
1121+
"TheSweeper",
1122+
"TheSlicer",
1123+
"GTSpeed",
1124+
"XtraAero",
1125+
};
1126+
if (nChoiceStartupCar == 0) {
1127+
oseCarDodgeSettings.nSizeOfOptions = 6;
1128+
1129+
oseCarDodgeSettings.sOptions = sOptions;
1130+
1131+
nChoiceStartupCar = oseCarDodgeSettings.OptionSelect("Please select which car you want CarDodge to auto-select when starting up:\n"
1132+
"(Currently set to: Option " + std::to_string(ConfigObjMain.nCarDodgeGameStartupCar) + ")", " ___GAME STARTUP CAR SETTINGS___ ");
1133+
}
1134+
1135+
colour(LGRN, ConfigObjMain.sColourGlobalBack);
1136+
1137+
if (nChoiceStartupCar == 1) {
1138+
std::cout << "CarDodge Game Startup Car successfully set to \"Default User Car (KartCar)\".\n";
1139+
}
1140+
else if (nChoiceStartupCar > 1 && nChoiceStartupCar <= 6) {
1141+
std::cout << "CarDodge Game Startup Car successfully set to \"" << sOptions[nChoiceStartupCar - 1] << "\".\n";
1142+
}
1143+
else if (nChoiceStartupCar == -1) {
1144+
Exiting();
1145+
return;
1146+
}
1147+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1148+
1149+
ConfigObjMain.nCarDodgeGameStartupCar = nChoiceStartupCar;
1150+
ConfigObjMain.WriteConfigFile();
1151+
1152+
return;
1153+
}
1154+
else if (nChoiceMain == 3) {
1155+
if (nChoiceForeground == 0) {
1156+
oseCarDodgeSettings.nSizeOfOptions = 16;
1157+
oseCarDodgeSettings.sOptions = sOptionsColour;
1158+
1159+
nChoiceForeground = oseCarDodgeSettings.OptionSelect("Please select what foreground colour you want CarDodge to use (note that this only affects the car colours on-screen):"
1160+
"\n(Currently set to: " + colconv::ColourToLogicalDisplayName(ConfigObjMain.sCarDodgeGameplayColourFore) + ")", " ___GAME FOREGROUND COLOUR SETTINGS___ ");
1161+
}
1162+
1163+
ColourForegroundSwitch(&nChoiceForeground, &ConfigObjMain.sCarDodgeGameplayColourBack, &ConfigObjMain.sCarDodgeGameplayColourFore);
1164+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1165+
1166+
colour(LGRN, ConfigObjMain.sColourGlobalBack);
1167+
std::cout << CentreText("CarDodge game foreground colour successfully set!") << std::endl;
1168+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1169+
return;
1170+
}
1171+
else if (nChoiceMain == 4) {
1172+
if (nChoiceBackground == 0) {
1173+
oseCarDodgeSettings.nSizeOfOptions = 16;
1174+
oseCarDodgeSettings.sOptions = sOptionsColour;
1175+
1176+
nChoiceBackground = oseCarDodgeSettings.OptionSelect("Please select what background colour you want CarDodge to use (note that this does NOT affect game borders, only the gameplay background):"
1177+
"\n(Currently set to: " + colconv::ColourToLogicalDisplayName(ConfigObjMain.sCarDodgeGameplayColourBack) + ")", " ___GAME BACKGROUND COLOUR SETTINGS___ ");
1178+
}
1179+
1180+
ColourBackgroundSwitch(&nChoiceBackground, &ConfigObjMain.sCarDodgeGameplayColourBack, &ConfigObjMain.sCarDodgeGameplayColourFore);
1181+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1182+
1183+
colour(LGRN, ConfigObjMain.sColourGlobalBack);
1184+
std::cout << CentreText("CarDodge game background colour successfully set!") << std::endl;
1185+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1186+
return;
1187+
}
1188+
else if (nChoiceMain == -1) {
1189+
Exiting();
1190+
return;
1191+
}
1192+
else {
1193+
VerbosityDisplay("In CarDodgeGameSettings() - ERROR: Unknown return value from OptionSelectEngine::OptionSelect().\n");
10581194
UserErrorDisplay("ERROR - Unknown error occured. Please try again later.\n");
10591195

10601196
return;

Core/ColourConv.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,14 @@ namespace zt {
336336
ConfigObjMain.sColourSubheadingBack = MAG_WIN32;
337337
bSuccess = false;
338338
}
339+
if (not (isNumberi(ConfigObjMain.sCarDodgeGameplayColourFore) && std::stoi(ConfigObjMain.sCarDodgeGameplayColourFore) < 8192)) {
340+
ConfigObjMain.sCarDodgeGameplayColourFore = LWHT_WIN32;
341+
bSuccess = false;
342+
}
343+
if (not (isNumberi(ConfigObjMain.sCarDodgeGameplayColourBack) && std::stoi(ConfigObjMain.sCarDodgeGameplayColourBack) < 8192)) {
344+
ConfigObjMain.sCarDodgeGameplayColourBack = BLK_WIN32;
345+
bSuccess = false;
346+
}
339347

340348
return bSuccess;
341349
}
@@ -423,6 +431,14 @@ namespace zt {
423431
ConfigObjMain.sColourSubheadingBack = MAG_ANSI;
424432
bSuccess = false;
425433
}
434+
if (!VerifyANSIColourString(ConfigObjMain.sCarDodgeGameplayColourFore)) {
435+
ConfigObjMain.sCarDodgeGameplayColourFore = LWHT_ANSI;
436+
bSuccess = false;
437+
}
438+
if (!VerifyANSIColourString(ConfigObjMain.sCarDodgeGameplayColourBack)) {
439+
ConfigObjMain.sCarDodgeGameplayColourBack = BLK_ANSI;
440+
bSuccess = false;
441+
}
426442

427443
return bSuccess;
428444
}

Core/ZeeTerminalCore.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ namespace zt {
252252
// sColourOutlineBack - The background colour for the outline.
253253
// sColourTextFore - The foreground colour for the text.
254254
// sColourTextBack - The background colour for the text.
255+
// bCentreBox - If specified, centre the box on the terminal screen. This is based on the terminal's horizontal width. Defaults to FALSE.
255256
// Return Values: None
256257
//
257258
void OutputBoxWithText(std::string sText, std::string sColourOutlineFore, std::string sColourOutlineBack, std::string sColourTextFore, std::string sColourTextBack, bool bCentreBox)
@@ -373,6 +374,15 @@ namespace zt {
373374
nBoxWidth = csbiDirections.srWindow.Right - csbiDirections.srWindow.Left + 1;
374375
}
375376

377+
// Calculate left padding width based on box width (for centring text)
378+
int nLeftPaddingWidth = 0;
379+
if (bCentreBox) {
380+
nLeftPaddingWidth = ((csbiDirections.srWindow.Right - csbiDirections.srWindow.Left + 1) - nBoxWidth) / 2;
381+
}
382+
383+
// Output padding
384+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
385+
std::cout << std::string(nLeftPaddingWidth, ' ');
376386

377387
// Firstly, output box top
378388
colour(sColourOutlineFore, sColourOutlineBack);
@@ -387,6 +397,10 @@ namespace zt {
387397
}
388398

389399
// Output padding
400+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
401+
std::cout << std::string(nLeftPaddingWidth, ' ');
402+
403+
// Output box border character
390404
colour(sColourOutlineFore, sColourOutlineBack);
391405
std::cout << "* ";
392406
colour(sColourTextFore, sColourTextBack);
@@ -399,6 +413,10 @@ namespace zt {
399413
std::cout << " *\n";
400414
}
401415

416+
// Output padding
417+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
418+
std::cout << std::string(nLeftPaddingWidth, ' ');
419+
402420
// Finally, output box bottom
403421
colour(sColourOutlineFore, sColourOutlineBack);
404422
std::cout << std::string(nBoxWidth, '=');
@@ -639,7 +657,7 @@ namespace zt {
639657
}
640658

641659
// Function to set console cursor position
642-
inline void SetCursorPosition(int x, int y) {
660+
void SetCursorPosition(int x, int y) {
643661
COORD CursorPos{};
644662
CursorPos.X = x;
645663
CursorPos.Y = y;
@@ -1135,6 +1153,7 @@ namespace zt {
11351153
}
11361154

11371155
// Function that outputs text with random colours
1156+
// Specify a background colour with sBackgroundColour to set the text background before writing to display
11381157
void RandomColourOutput(std::string sText, std::string sBackgroundColour) {
11391158

11401159
// Add word wrapping
@@ -1147,10 +1166,10 @@ namespace zt {
11471166
// Colour indicator going past 16 will give an error
11481167
if (i > 16) i = 1;
11491168

1150-
if (colconv::NumberToColour(i) == ConfigObjMain.sColourGlobalBack && !ConfigObjMain.bAutoReadableContrast) {
1151-
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1169+
if (colconv::NumberToColour(i) == sBackgroundColour && !ConfigObjMain.bAutoReadableContrast) {
1170+
colour(ConfigObjMain.sColourGlobal, sBackgroundColour);
11521171
}
1153-
else colour(colconv::NumberToColour(i), ConfigObjMain.sColourGlobalBack);
1172+
else colour(colconv::NumberToColour(i), sBackgroundColour);
11541173

11551174
// Output with colour
11561175
std::cout << sText[j];
@@ -1257,8 +1276,9 @@ namespace zt {
12571276
return;
12581277
}
12591278

1260-
// Firstly, output string of spaces
1261-
std::cout << std::string((nWidth - sText.length()) / 2, ' ');
1279+
// Firstly, set cursor to correct centre position
1280+
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiCentreCT);
1281+
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), { (short)((nWidth - sText.length()) / 2), csbiCentreCT.dwCursorPosition.Y });
12621282
// Then output the string itself like slowcharfn()
12631283
for (int i = 0; i <= sText.length(); i++) {
12641284
sleep(ConfigObjMain.nSlowCharSpeed);

0 commit comments

Comments
 (0)