Skip to content

Commit 4f1da39

Browse files
Modifications after last commit with QC bugfixes applied as well:
- Add commands Y2038, CalcQuadratic, Factorial - Add game Guess The Number - Add settings for the Guess The Number game - Fix settings indentation in help page - Fix issues with incomplete error checking in settings involving colours in the Settings command
1 parent 6bab8eb commit 4f1da39

File tree

14 files changed

+835
-11
lines changed

14 files changed

+835
-11
lines changed

CommandFiles/CommandFileAssets.cpp

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ void help(bool bFromTutorial) {
229229
"[6] DevTools\t\t[21] Copy\t\t[36] RandCol\t\t[51] Game\n"
230230
"[7] CPUStress\t\t[22] CopyFile\t\t[37] Pause\t\t[52] FileCryptor\n"
231231
"[8] Colour\t\t[23] TextInfo\t\t[38] CommandNum\t\t[53] Delete\n"
232-
"[9] Settings\t\t[24] ConfigAction\t[39] SlowChar\n"
233-
"[10] Title\t\t[25] BeepSounds\t\t[40] ReverseText\n"
234-
"[11] Date\t\t[26] RickRoll\t\t[41] Notes\n"
232+
"[9] Settings\t\t[24] ConfigAction\t[39] SlowChar\t\t[54] Factorial\n"
233+
"[10] Title\t\t[25] BeepSounds\t\t[40] ReverseText\t[55] CalcQuadratic\n"
234+
"[11] Date\t\t[26] RickRoll\t\t[41] Notes\t\t[56] Y2038\n"
235235
"[12] ColourNumbers\t[27] ShellExecute\t[42] FileParse\n"
236236
"[13] MediaPlayer\t[28] Hacker\t\t[43] Disp\n"
237237
"[14] AudioPlayer\t[29] Calculator\t\t[44] SysInfo\n"
@@ -2699,6 +2699,59 @@ std::string FormatValueForEuropeanNotation(long double dValue) {
26992699
return sFormatBuffer;
27002700
}
27012701

2702+
// GetNumPrimeFactorsAsString - Get the prime factors of a specified integer argument and return them as a string in this format: "<n>, <n>, <n>"...
2703+
// Parameters: nNumToUse - The number to calculate the prime factors of.
2704+
// Return Values: std::string containing the prime factors of nNumToUse, as a string.
2705+
//
2706+
std::string GetNumPrimeFactorsAsString(uint64_t nNumToUse) {
2707+
std::string sPrimeFactorStr = "";
2708+
2709+
// Repeat until square root of nNumToUse
2710+
for (uint64_t i = 2; i * i <= nNumToUse; ++i) {
2711+
2712+
// Check if divisible by i
2713+
while (nNumToUse % i == 0) {
2714+
// Add prime factor to string with space
2715+
sPrimeFactorStr += std::to_string(i) + ", ";
2716+
// Divide by i to move on to next prime factor
2717+
nNumToUse /= i;
2718+
}
2719+
}
2720+
2721+
// nNumToUse has been divided all the way, do not forget about it
2722+
if (nNumToUse > 1) {
2723+
// Add prime factor to string with space
2724+
sPrimeFactorStr += std::to_string(nNumToUse) + ", ";
2725+
}
2726+
2727+
// There should be an unnecessary extra ", " at the end of the string - remove it
2728+
sPrimeFactorStr.erase(sPrimeFactorStr.length() - 2, 2);
2729+
2730+
// Return string
2731+
return sPrimeFactorStr;
2732+
}
2733+
2734+
// GetNumFactorsAsString - Get the factors of a specified integer argument and return it as a string in this format: "<n>, <n>, <n>"...
2735+
// Parameters: nNumToUse - The number to calculate the factors of.
2736+
// Return Values: std::string containing the factors of nNumToUse, as a string.
2737+
//
2738+
std::string GetNumFactorsAsString(uint64_t nNumToUse) {
2739+
std::string sFactorsStr = "";
2740+
2741+
// Iterate until number with increment of 1 (brute-force technique)
2742+
for (uint64_t i = 1; i <= nNumToUse; i++) {
2743+
if (nNumToUse % i == 0) {
2744+
// Add number to string
2745+
sFactorsStr += std::to_string(i) + ", ";
2746+
}
2747+
}
2748+
2749+
// There should be an unnecessary extra ", " at the end of the string - remove it
2750+
sFactorsStr.erase(sFactorsStr.length() - 2, 2);
2751+
2752+
return sFactorsStr;
2753+
}
2754+
27022755
/* MessageBox Codes */
27032756
//////////////////////
27042757
/* Message box codes are the following for icons:

CommandFiles/CommandHelpMessages.cpp

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ namespace helpmsgs
178178
<< wordWrap("\n --newoptionselect <toggle>\tUse the new OptionSelect Engine style. Set either true/t or false/f in place of <toggle>.")
179179
<< 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>.")
180180
<< 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>.")
181-
<< wordWrap("\n --cdforeground <num>\tSet the foreground colour in the CarDodge game. Put the colour number in place of <num>.")
182-
<< wordWrap("\n --cdbackground <num>\tSet the background colour in the CarDodge game. Put the colour number in place of <num>.")
181+
<< wordWrap("\n --cdforeground <num>\t\tSet the foreground colour in the CarDodge game. Put the colour number in place of <num>.")
182+
<< wordWrap("\n --cdbackground <num>\t\tSet the background colour in the CarDodge game. Put the colour number in place of <num>.")
183+
<< wordWrap("\n --gtnforeground <num>\t\tSet the foreground colour in the Guess The Number game. Put the colour number in place of <num>.")
184+
<< wordWrap("\n --gtnbackground <num>\t\tSet the background colour in the Guess The Number game. Put the colour number in place of <num>.")
183185
<< wordWrap("\n\nExample: settings --titlefore 1")
184186
<< wordWrap("\n\nNote: You can get colour numbers by executing the \"ColourNumbers\" command.") << "\n\n";
185187

@@ -1036,7 +1038,8 @@ namespace helpmsgs
10361038
colourSubheading();
10371039
std::cout << "Possible arguments for this command:" << NOULINE_STR;
10381040
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1039-
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"
1041+
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"
1042+
" --gtn\t\tStarts the Guess The Number game, a game where you guess a number between 1 and 100 in as little tries as you can.\n\n"
10401043
"Example: game --cardodge\n\n");
10411044

10421045
return;
@@ -1084,4 +1087,68 @@ namespace helpmsgs
10841087

10851088
return;
10861089
}
1090+
1091+
// FactorialHelp
1092+
void FactorialHelp() {
1093+
CentreColouredText(" ___FACTORIAL___ ", 1);
1094+
std::cout << "\n";
1095+
CentreColouredText("This command calculates the factors and prime factors of a positive integer.", 2);
1096+
std::cout << "\n\n";
1097+
1098+
colourSubheading();
1099+
std::cout << "What this command does:" << NOULINE_STR;
1100+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1101+
std::cout << wordWrap("\n- This command simply calculates the prime factors and factors of a positive integer.\n- The results are displayed on the terminal screen.\n\n");
1102+
1103+
colourSubheading();
1104+
std::cout << "Possible arguments for this command:" << NOULINE_STR;
1105+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1106+
std::cout << wordWrap("\n -h\tDisplays this help message.\n <num>\tFactorise a number from an argument parameter. Put the number in place of <num>.\n\nExample: factorial 45\n\n");
1107+
1108+
return;
1109+
}
1110+
1111+
// CalcQuadraticHelp
1112+
void CalcQuadraticHelp() {
1113+
CentreColouredText(" ___CALCQUADRATIC___ ", 1);
1114+
std::cout << "\n";
1115+
CentreColouredText("CalcQuadratic allows you to compute all values of a quadratic equation quickly and easily.", 2);
1116+
std::cout << "\n\n";
1117+
1118+
colourSubheading();
1119+
std::cout << "What this command does:" << NOULINE_STR;
1120+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1121+
std::cout << wordWrap("\n- This command calculates all the values of a quadratic mathematical equation quickly and easily.\n- All the command needs is the A, B and C values, from this quadratic equation form: [ax^2 + bx + c = 0].\n\n");
1122+
1123+
colourSubheading();
1124+
std::cout << "Possible arguments for this command:" << NOULINE_STR;
1125+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1126+
std::cout << wordWrap("\n -h\t\tDisplays this help message.\n <a> <b> <c>\tCompute values of quadratic equation from arguments. Put A, B and C values in place of <a>, <b> and <c> respectively.\n\n"
1127+
"Example: calcquadratic 1 9 18\n\nNOTE: The A, B and C arguments must be numerical for the calculator to work.\n\n");
1128+
1129+
return;
1130+
}
1131+
1132+
// Y2038Help
1133+
void Y2038Help() {
1134+
CentreColouredText(" ___Y2038___ ", 1);
1135+
std::cout << "\n";
1136+
CentreColouredText("This command displays how long is left until the Y2038 time overflow occurs.", 2);
1137+
std::cout << "\n\n";
1138+
1139+
colourSubheading();
1140+
std::cout << "What this command does:" << NOULINE_STR;
1141+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1142+
std::cout << wordWrap("\n- This command displays how long is left until the Y2038 time overflow occurs (aka the Y2038 problem, Y2K38).\n- This bug occurs because there are simply too many seconds to fit into a 32-bit integer. Therefore, it affects all 32-bit systems."
1143+
"\n- You can find out more about this phenomenon on the Wikipedia page: ");
1144+
colour(LBLU, ConfigObjMain.sColourGlobalBack);
1145+
std::cout << wordWrap("https://en.wikipedia.org/wiki/Year_2038_problem\n\n");
1146+
1147+
colourSubheading();
1148+
std::cout << "Possible arguments for this command:" << NOULINE_STR;
1149+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
1150+
std::cout << wordWrap("\n -h\tDisplays this help message.\n\nExample: y2038 -h\n\n");
1151+
1152+
return;
1153+
}
10871154
}

CommandFiles/CommandsFile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "CommandHelpMessages.cpp"
2929
#include "CalculationAlgorithm/CalculationAlgorithm.h"
3030
#include "../GameFiles/CarDodge/CarDodge.cpp"
31+
#include "../GameFiles/GuessTheNumber/GuessTheNumber.h"
3132

3233
#include <vector>
3334
#include <string>

CommandFiles/CommandsFiles/CommandsFile_1to10.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,34 @@ bool commands::Commands1To10(const std::string sCommand, char* cCommandArgs, con
805805
UserErrorDisplay("An error occured. Your setting option seems to be incorrect. Make sure it's a number and try again.\nType \"settings -h\" for more info.\n");
806806
}
807807

808+
return true;
809+
}
810+
else if (sStringOptionCommandArgs[0] == "gtnforeground") {
811+
if (isNumberi(sStringDataCommandArgs[0])) {
812+
GuessTheNumberGameSettings(1, std::stoi(sStringDataCommandArgs[0]), 0);
813+
}
814+
else {
815+
VerbosityDisplay("In Commands() - ERROR: Could not detect numerical value in string-based number argument.\n");
816+
UserErrorDisplay("An error occured. Your setting option seems to be incorrect. Make sure it's a number and try again.\nType \"settings -h\" for more info.\n");
817+
}
818+
819+
return true;
820+
}
821+
else if (sStringOptionCommandArgs[0] == "gtnbackground") {
822+
if (isNumberi(sStringDataCommandArgs[0])) {
823+
GuessTheNumberGameSettings(2, 0, std::stoi(sStringDataCommandArgs[0]));
824+
}
825+
else {
826+
VerbosityDisplay("In Commands() - ERROR: Could not detect numerical value in string-based number argument.\n");
827+
UserErrorDisplay("An error occured. Your setting option seems to be incorrect. Make sure it's a number and try again.\nType \"settings -h\" for more info.\n");
828+
}
829+
808830
return true;
809831
}
810832
}
811833

812834
OptionSelectEngine oseSettings;
813-
oseSettings.nSizeOfOptions = 11;
835+
oseSettings.nSizeOfOptions = 12;
814836
std::string sOptions[] = {
815837
"Highlight Colour Settings",
816838
"Title Colour Settings",
@@ -822,6 +844,7 @@ bool commands::Commands1To10(const std::string sCommand, char* cCommandArgs, con
822844
"Cursor Settings",
823845
"LogFile System Settings",
824846
"CarDodge Game Settings",
847+
"Guess The Number Game Settings",
825848
"Other Settings"
826849
};
827850
oseSettings.sOptions = sOptions;
@@ -866,6 +889,9 @@ bool commands::Commands1To10(const std::string sCommand, char* cCommandArgs, con
866889
CarDodgeGameSettings();
867890
break;
868891
case 11:
892+
GuessTheNumberGameSettings();
893+
break;
894+
case 12:
869895
OtherSettings();
870896
break;
871897

0 commit comments

Comments
 (0)