generated from mcmarius/oop-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQFrame.cpp
75 lines (67 loc) · 2.16 KB
/
QFrame.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
//
// Created by raduc on 07.05.2023.
//
#include "QFrame.h"
#include "ratingQuestion.h"
#include "tfQuestion.h"
#include "FrameErr.h"
#include "boxQuestion.h"
void QFrame::draw(sf::RenderWindow &window) {
questions[currentQuestion]->showQuestion(window);
}
void QFrame::nextQuestion() {
currentQuestion++;
}
std::string QFrame::handleEvent(sf::Event event, sf::RenderWindow &window) {
std::string result = questions[currentQuestion]->handleEvent(event, window);
if (!result.empty()) {
if (result == "YES") {
auto & ch = questions[currentQuestion]->getCharacteristics();
auto *q = dynamic_cast<boxQuestion*>(questions[currentQuestion].get());
if (q) {
q->passAnswer(user);
}
else {
auto mult = questions[currentQuestion]->getAnswer();
user.updateCharacteristics(ch, mult);
}
}
nextQuestion();
if (currentQuestion == (int)questions.size()) {
return "end";
}
return "next";
}
return result;
}
QFrame::QFrame(User &user, std::ifstream &f) : Frame(user) {
std::string qtype, question;
Characteristics ch;
while (f >> qtype) {
f.get();
std::getline(f, question);
if (qtype == "box") {
std::shared_ptr<Question> q = std::make_shared<boxQuestion>(question);
questions.push_back(q);
}else {
double d[4];
for (double & i : d) {
f >> i;
}
ch = Characteristics(d[0], d[1], d[2], d[3]);
if (qtype == "yn") {
std::shared_ptr<Question> q = std::make_shared<tfQuestion>(question, ch);
questions.push_back(q);
} else if (qtype == "rating") {
std::shared_ptr<Question> q = std::make_shared<ratingQuestion>(question, ch);
questions.push_back(q);
}
else {
throw FrameErr("Invalid question type");
}
}
}
}
void QFrame::reset() {
currentQuestion = 0;
}