-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
103 lines (82 loc) · 2.66 KB
/
Copy pathmainwindow.cpp
File metadata and controls
103 lines (82 loc) · 2.66 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
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "fireextinguisher.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowIcon(QIcon("fireIcon.png"));
enterKey = new QShortcut(this);
enterKey->setKey(Qt::Key::Key_Enter);
connect(enterKey, SIGNAL(activated()), this, SLOT(shortCutEnter()));
escapeKey = new QShortcut(this);
escapeKey->setKey(Qt::Key::Key_Escape);
connect(escapeKey, SIGNAL(activated()), this, SLOT(on_closeButton_clicked()));
roomPlan = new RoomPlan(400, 400);
roomPlan->addHuman();
srand(time(nullptr));
roomPlan->generateEvacuationButtons(10);
roomPlan->generateExitPointers(10);
roomPlan->generateFireExtinguishers(10);
roomPlanDrawer = ui->paintWidget;
roomPlanDrawer->setRoomPlan(roomPlan);
roomPlanDrawer->draw();
connect(timer, SIGNAL(timeout()), this, SLOT(stepModel()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::shortCutEnter()
{
if(timer->isActive()){
timer->stop();
}
else {
timer->start(FPS);
}
}
void MainWindow::stepModel()
{
// Вывод информации на форму
roomPlan->isEvacuation() ? ui->evacuationLabel->setText("true") : ui->evacuationLabel->setText("false");
roomPlan->isIgnition() ? ui->ignitionLabel->setText("true") : ui->ignitionLabel->setText("false");
ui->peopleCountLabel->setText(QString::number(roomPlan->getPeopleCount()));
ui->deadCountLabel->setText(QString::number(roomPlan->getDeathCount()));
// Если количество людей = 0
if(roomPlan->getPeopleCount() == 0){
// Если идет эвакуация или заблокирован выход,
// остановка модели
if(roomPlan->isEvacuation() ||
!roomPlan->isFreeCoordinate(roomPlan->getExitX(), roomPlan->getExitY())){
timer->stop();
}
}
// Случайное добавление человека
if(roomPlan->getPeopleCount() < roomPlan->getMaxHumanInRoom()){
int chance = rand() % 100;
if(chance >= 95){
roomPlan->addHuman();
}
}
// Шаг модели и отрисовка
roomPlan->step();
roomPlanDrawer->draw();
}
void MainWindow::on_closeButton_clicked()
{
close();
}
void MainWindow::on_startButton_clicked()
{
timer->start(FPS);
}
void MainWindow::on_stopButton_clicked()
{
timer->stop();
}
void MainWindow::on_updateButton_clicked()
{
roomPlan->updateRoom();
}