-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
62 lines (48 loc) · 1.49 KB
/
Copy pathGame.cpp
File metadata and controls
62 lines (48 loc) · 1.49 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
#include "Game.h"
const unsigned int TOTAL_QUESTION_NB = 125;
const unsigned int ANSWER_TIME = 7; // seconds
unsigned int Game::newQuestion() {
int question_id;
do {
srand(static_cast<unsigned int>(time(NULL)));
question_id = std::rand() % TOTAL_QUESTION_NB;
} while (std::find(std::begin(this->questions), std::end(this->questions), question_id) != std::end(this->questions));
this->questions[this->question_asked] = question_id;
this->question_asked++;
return question_id;
}
void Game::startTimer() {
this->last_question = std::chrono::system_clock::now();
}
unsigned Game::getPoints() {
return this->points;
}
void Game::addPoint() {
this->points++;
}
bool Game::isOver() {
return this->question_asked == this->question_nb;
}
unsigned int Game::getTimeElapsed() {
return static_cast<unsigned int>((std::chrono::duration<double> (std::chrono::system_clock::now() - this->last_question)).count());
}
unsigned int Game::getTimeLeft() {
return ANSWER_TIME - this->getTimeElapsed();
}
bool Game::nextQuestion() {
return this->getTimeElapsed() < 15 && this->getTimeElapsed() >= ANSWER_TIME && !this->ended;
}
void Game::end() {
this->ended = true;
}
unsigned int Game::getCurrentQuestion() {
return this->questions[this->question_asked-1];
}
Game::Game() {
this->question_asked = 0;
for (unsigned int i = 0; i < this->question_nb; i++) {
this->questions[i] = TOTAL_QUESTION_NB+1;
}
this->points = 0;
this->ended = false;
}