-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cpp
82 lines (71 loc) · 2.11 KB
/
Game.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
77
78
79
80
81
82
#include <iostream>
#include <ctime>
#include "Game.h"
void Game::StartGame() {
CreateWorld();
PlayRounds();
}
void Game::CreateWorld() {
InitSrand();
InitWordlDimensions();
InitOrganisms();
}
void Game::PlayRounds() {
while(userMove != KEY_QUIT) {
ClearTerminal();
PrintAuthor();
gameWorld.PrintWorld();
PrintLegend();
LogEvents(gameWorld.GetEventsFromLastRound());
GetUserMove();
gameWorld.MakeMove(userMove);
}
}
void Game::InitWordlDimensions() {
unsigned int width = 0, height = 0;
while(width <= 0 && height <= 0) {
std::cout << "Wprowadz szerokosc swiata: ";
std::cin >> width;
std::cout << "Wprowadz wysokosc swiata: ";
std::cin >> height;
}
gameWorld.InitDimensions(width, height);
}
void Game::InitSrand() const {
srand(time(NULL));
}
void Game::InitOrganisms() {
unsigned int organismsNum = 0;
while(organismsNum <= 0) {
std::cout << "Wprowadz ilosc organizmow: ";
std::cin >> organismsNum;
}
try {
gameWorld.InitOrganisms(organismsNum);
} catch (const char* error) {
std::cout << error << std::endl;
InitOrganisms();
}
}
void Game::ClearTerminal() const {
// system("CLS"); // Windows
system("clear"); // Linux
}
void Game::PrintAuthor() const {
std::cout << '\t' << "Bartlomiej" << " " << "Wilczynski" << " nr 184899" << '\n';
}
void Game::PrintLegend() const {
std::cout << "\n" << WOLF_SYMBOL << " wilk " << SHEEP_SYMBOL << " owca " << FOX_SYMBOL << " lis "
<< TURTLE_SYMBOL << " zolw " << ANTELOPE_SYMBOL << " antylopa " << HUMAN_SYMBOL << " gracz "
<< GRASS_SYMBOL << " trawa\n" << SONCHUS_SYMBOL << " mlecz " << GUARANA_SYMBOL << " guarana "
<< BERRIES_SYMBOL << " jagody " << SOSNOWSKI_BARSCH_SYMBOL << " barszcz \n"
<< "Q - wyjście\tS - Supermoc\n\n";
}
void Game::LogEvents(const std::string events) const {
std::cout << events;
}
void Game::GetUserMove() {
do {
userMove = input.GetGameKeyPresses();
} while(userMove == NO_PROPER_KEY);
}