-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscenariobox.cpp
143 lines (130 loc) · 3.75 KB
/
scenariobox.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "scenariobox.h"
#include "ui_scenariobox.h"
#include "Item.h"
#include <QDebug>
ScenarioBox::ScenarioBox(QWidget *parent) :
QDialog(parent),
ui(new Ui::ScenarioBox)
{
ui->setupUi(this);
numOfObjs = 5;
setupObjectives();
}
ScenarioBox::~ScenarioBox()
{
delete ui;
}
void ScenarioBox::setScenario(QString title, QString desc, QString Opt1, QString Opt2){
ui->lblTitle->setText(title);
ui->txtDescription->setText(desc);
ui->btnOptionA->setText(Opt1);
ui->btnOptionB->setText(Opt2);
ui->btnOptionA->setVisible(true);
ui->btnOptionB->setVisible(true);
ui->btnOptionC->setVisible(false);
ui->btnOptionB->move(380, 380);
setObjective();
getItems();
this->show();
}
void ScenarioBox::setScenario(QString title, QString desc, QString Opt1)
{
ui->lblTitle->setText(title);
ui->txtDescription->setText(desc);
ui->btnOptionB->setText(Opt1);
ui->btnOptionA->setVisible(false);
ui->btnOptionC->setVisible(false);
ui->btnOptionB->setVisible(true);
ui->btnOptionB->move(255, 380);
setObjective();
getItems();
this->show();
}
void ScenarioBox::endGame(QString title, QString desc, QString Opt1)
{
ui->lblTitle->setText(title);
ui->txtDescription->setText(desc);
ui->btnOptionC->setText(Opt1);
ui->btnOptionA->setVisible(false);
ui->btnOptionB->setVisible(false);
ui->btnOptionC->setVisible(true);
ui->btnOptionC->move(255, 380);
setObjective();
getItems();
this->show();
}
void ScenarioBox::showScenario(Room *x)
{
currentRoom = x;
if (currentRoom->longDescription() == "start")
setScenario("Start", "Welcome to Zorkenaders!\n To complete the game, you must collect all the items and bring them to the monster! Be careful, if you are caught by the monster's guard you will lose the game!!\nControls: F1", "Ok");
else if (currentRoom->longDescription() == "before the BEAST"){
if (checkItems()){
endGame("CHAMPION", "Congratulations!!\nYou've appeased the monster and won the game", "Ok");
}
else
setScenario("Monster", "You must appease the Monster by collecting all of the objectives", "Ok");
}
else if (isItem())
setScenario("Item Found!", "You have found: " + currentRoom->getItem()->getDescription() +".\nDo you wish to pick it up or leave it?", "Pick up", "Leave");
else
setScenario("Zorkenaders", "No items found!", "Ok");
}
void ScenarioBox::getItems()
{
QString temp = "";
for (int i = 0; i < items.size(); ++i) {
temp.append(items[i]);
temp.append("\n");
}
qDebug() << temp;
ui->txtInventory->setText(temp);
}
void ScenarioBox::setObjective()
{
QString objs = "Appease the monster!!\nBring it the following items:\n\n";
for (int i = 0; i < numOfObjs; i++)
objs += objectives[i] + "\n";
ui->txtObjectives->setText(objs);
}
void ScenarioBox::setupObjectives()
{
objectives[0] = "apple";
objectives[1] = "banana";
objectives[2] = "orange";
objectives[3] = "grape";
objectives[4] = "pear";
}
bool ScenarioBox::checkItems()
{
bool found;
for (int i = 0; i < numOfObjs; i++){
found = false;
for (int j = 0; j < items.size(); j++)
if (objectives[i] == items[j])
found = true;
if (!found)
return false;
}
return true;
}
void ScenarioBox::on_btnOptionA_clicked()
{
//qDebug() << "button A clicked";
if(isItem()){
items.push_back(x->getDescription());
currentRoom->removeItem();
}
close();
}
void ScenarioBox::on_btnOptionB_clicked()
{
//qDebug() << "button B clicked";
close();
}
void ScenarioBox::on_btnOptionC_clicked()
{
//qDebug() << "button B clicked";
close();
qApp->quit();
}