-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
48 lines (40 loc) · 1.39 KB
/
main.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
#include "Printer.h"
#include "GameStateEnum.h"
#include "GameLoop.h"
#include "Ship.h"
#include "EventHandler.h"
#include <memory>
#include <chrono>
#include <thread>
int main()
{
GameState state = proceed;
std::shared_ptr<Ship> ship = nullptr; // Allocating space from memory for the ship to be selected
int eventCounter = 0; // When it reaches 5 the game will be over
while (state == proceed)
{
if (eventCounter == 0) // Game starts
{
Printer::PrintWelcomeMessage();
GameLoop::GetInput();
ship = GameLoop::SelectShip(); // Assign the selected ship to "ship" value
}
// Sleep terminal for 2 seconds to avoiding text overlapping
std::this_thread::sleep_for(std::chrono::seconds(2));
EventHandler::EventRandomizer(ship); // Random event occurrence
eventCounter++;
// Sleep terminal again for 2 seconds to avoiding text overlapping
std::this_thread::sleep_for(std::chrono::seconds(2));
// Print the status of ship
Printer::PrintStatus(ship);
if (ship->GetHealth() <= 0 || ship->GetFuel() <= 0) // Losing condition (If fuel or currency drops below zero)
{
state = lose;
}
else if (eventCounter == 5) // Winnig condition
{
state = win;
}
}
Printer::PrintEndingMessage(state, ship); // Game ends
}