-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (73 loc) · 2.41 KB
/
Copy pathmain.cpp
File metadata and controls
80 lines (73 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cstdlib>
#include <cstring>
#include <vector>
#include "main.h"
#include "logging.h"
#include "formattedprint.h"
#include "carddeck.h"
int main(){
Print("Welcome, to the console suite. Type 'exit' to exit.");
while(InputHandler()){}
return 0;
}
// Helpers
bool InputHandler(){
// Take input
std::string strinput;
std::cout << ">> ";
std::cin >> strinput;
const char* input = strinput.c_str();
//------------------------
if(StringEqual(input, "exit") || StringEqual(input, "q")){
Print("Exiting...");
return false;
}
else if(StringEqual(input, "rand")){
Print("Generating a random number for you now (0-100)");
float random = rand() % 100000 / 1000;
std::cout << random << std::endl;
}
else if(StringEqual(input, "about")){
Print("+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+");
Print("|This program was created by Cameron Hadfield|");
Print("| On the 27th of August, 2021 |");
Print("| While his girlfriend napped on him |");
Print("+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+");
}
else if(StringEqual(input, "guess")){
Print("Let's play a guessing game!");
Print("Guess what number I am thinking of, from 1 to 10");
int random = rand() % 10 + 1;
int guess;
std::cin >> guess;
if(guess == random){
Print("Wow!! You must be smarter than me.");
}
else{
Print("I win this time >:)");
}
std::cout << "You guessed " << guess << " and I was thinking of " << random << std::endl;
}
else if(StringEqual(input, "card")){
Print("Getting a random card from the deck");
Card c = CardDeck::RandomCard();
std::cout << c.ToString() << std::endl;
}
else if(StringEqual(input, "help")){
Print("Fetching a list of commands for you now!");
std::vector<std::vector<std::string>> commands = {{"cmd", "desc"},
{ "help", "Print this table" },
{ "rand", "Generate a random number (0-100 inclusive)" },
{ "about", "Gives some info about the program" },
{ "exit", "Quit the program" }
};
PrintTable(commands);
}
else{
Print("Don't know that command yet");
}
return true;
}
bool StringEqual(const char* in, const char* target){
return (strcmp(in, target) == 0);
}