-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.cpp
63 lines (51 loc) · 1.4 KB
/
popup.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
#include "popup.h"
#include "ui_popup.h"
#include "mainwindow.h"
Popup::Popup(QWidget *parent) :
QDialog(parent),
ui(new Ui::Popup)
{
ui->setupUi(this);
popupFillMoveLocations();
}
Popup::~Popup()
{
delete ui;
}
void Popup::popupFillMoveLocations() {
// Fill locations with less that two players
// Count players in each location
Game *game = Game::getInstance();
ui->locationCombo->clear();
int numOfRegions = game->getMap()->getGraph()->getNumOfNodes();
for (int i = 0; i < numOfRegions; i++) {
if (game->getMap()->getGraph()->nodes[i]->hasSubRegions()) {
continue;
}
if (game->playersInRegion(i) == 2) {
continue;
}
string regionName = game->getMap()->getGraph()->nodes[i]->getName();
ui->locationCombo->addItem(regionName.c_str(), QVariant(i));
}
}
void Popup::on_stayButton_clicked()
{
hide();
}
void Popup::on_moveButton_clicked()
{
Game *game = Game::getInstance();
int location = ui->locationCombo->currentData().toInt();
// get id of player in manhattan
int playerToMove = -1;
for (int i = 0; i < game->getNumOfPlayers(); i++) {
if (game->getPlayers()[i].getZone() == 0) {
playerToMove = i;
break;
}
}
game->getPlayers()[playerToMove].setZone(location);
((MainWindow *)parentWidget())->updateMap();
hide();
}