-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simon-Cs.cpp
76 lines (66 loc) · 1.48 KB
/
Simon-Cs.cpp
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
// Simon-Cs.cpp : This file contains the 'main' function. Program execution begins and ends there.
#include "Name.h"
#include "Startmenu.h"
#include "Gameloop.h"
#include "Highscore.h"
#include <iostream>
#include <ctime>
using namespace std;
void ClearConsole()
{
system("cls");
}
int main()
{
srand(time(NULL)); // Set a new seed for the random class
bool welcomeBack = true;
// Retrieves the name of the player or sets it if there is none
Name nameHandler;
string name = nameHandler.GetName();
if (name.empty())
{
cout << "We see that this is your first time playing" << endl;
cout << endl;
welcomeBack = false;
name = nameHandler.AskName();
ClearConsole();
}
// Initialize Components
Startmenu startmenu;
Gameloop gameloop = Gameloop(name);
Highscore highscore;
Command command;
string lastSequence;
do
{
// Greet the player
cout << "Simons Cs" << endl;
cout << endl;
cout << "Welcome " << ((welcomeBack) ? "back, " : "") << name << endl;
cout << endl;
welcomeBack = false;
// Ask for a command
command = startmenu.AskCommand();
ClearConsole();
// Execute the command
switch (command)
{
case ChangeName:
name = nameHandler.AskName();
break;
case ViewHighscores:
highscore.DisplayScore();
break;
case Play:
lastSequence = gameloop.Run();
highscore.SaveScore(name, lastSequence);
highscore.DisplayScore();
break;
default:
break;
}
ClearConsole();
} while (command != Quit);
cout << "Quit Game" << '\n';
return 0;
}