-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmstartgame.cpp
92 lines (71 loc) · 2.33 KB
/
frmstartgame.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
#include "frmstartgame.h"
#include "ui_frmstartgame.h"
FrmStartGame::FrmStartGame(QWidget *parent) :
QWidget(parent),
ui(new Ui::FrmStartGame)
{
ui->setupUi(this);
// create modal
this->gameWindow = new FrmGameWindow();
// signal for closed modal => frmstartgame
connect(this->gameWindow,SIGNAL(gameClosed()),this,SLOT(on_gameWindow_closed()));
}
FrmStartGame::~FrmStartGame()
{
delete ui;
}
void FrmStartGame::closeEvent(QCloseEvent *event)
{
emit this->programCut();
}
void FrmStartGame::setDB(Database* db)
{
this->db = db;
}
void FrmStartGame::setUp(Levelliste *list)
{
// load level dropdown
this->level = list;
ui->cbxLevels->clear();
for(int i = 0; i<this->level->levelZaehlen(); i++){
ui->cbxLevels->addItem("Level " + QString::number(this->level->levelHolen(i)->getId()) + ": " + this->level->levelHolen(i)->getName());
}
// get cathegorys
DatabaseAnswer<ImageCathegoryList>* respCat = this->db->find<ImageCathegoryList>(ImageCathegory::generateFindAllModel(ImageCathegory::getTable()));
// check for error
if(!respCat->hasError()){ this->cathegory = respCat->getObject(); } else { Error(500, "Query Error", respCat->errorToText()); }
// delete pointer
delete respCat;
// load cathegory dropdown
ui->cbxCategory->clear();
for(int i = 0; i<this->cathegory->cathegoryZaehlen(); i++){
ui->cbxCategory->addItem(this->cathegory->cathegoryHolen(i)->getName());
}
}
void FrmStartGame::setUsername(QString username)
{
this->username = username;
}
void FrmStartGame::on_btnStartGame_clicked()
{
// get level and cathegory
Level* currentLevel = this->level->levelHolen(ui->cbxLevels->currentIndex());
ImageCathegory* currentCathegory = this->cathegory->cathegoryHolen(ui->cbxCategory->currentIndex());
// emit signal that game started
emit this->gameStarted();
// set context of gamewindow
this->gameWindow->setDB(this->db);
this->gameWindow->setCathegory(currentCathegory);
this->gameWindow->setLevel(currentLevel);
this->gameWindow->setPlayer(username);
// load game
this->gameWindow->load();
// show gamewindow and close this one
this->gameWindow->show();
this->close();
}
void FrmStartGame::on_gameWindow_closed()
{
// emit signal that game ended
emit this->gameClosed();
}