-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamescreen.cpp
More file actions
100 lines (85 loc) · 3.45 KB
/
gamescreen.cpp
File metadata and controls
100 lines (85 loc) · 3.45 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
#include "gamescreen.h"
#include "ui_gamescreen.h"
#include "game/racing/racing.h"
#include "menuforgames.h"
#include <QPushButton>
#include <QFont>
#include <QPixmap>
#include <QPalette>
GameScreen::GameScreen(QWidget *parent) :
QWidget(parent),
ui(new Ui::GameScreen)
{
ui->setupUi(this);
QFont font;
font.setPointSize(12);
QPushButton *btn = new QPushButton("Play", this);
btn->setFont(font);
ui->verticalLayout->addWidget(btn);
ui->healthLvl->setLevel(ui->widget->getPet()->getHealth());
ui->energyLvl->setLevel(ui->widget->getPet()->getEnergy());
ui->happinessLvl->setLevel(ui->widget->getPet()->getHealth());
ui->satietyLvl->setLevel(ui->widget->getPet()->getSatiety());
ui->toWakeUp->hide();
connect(ui->toSleep, SIGNAL(clicked()),btn, SLOT(hide()));
connect(ui->toWakeUp, SIGNAL(clicked()), btn, SLOT(show()));
connect(this, SIGNAL(sendPlayer(QString)), ui->widget->getPet(), SLOT(setPlayer(QString)));
connect(ui->widget->getPet(), SIGNAL(ageChange(qlonglong)), this, SLOT(setAge(qlonglong)));
connect(ui->widget->getPet(), SIGNAL(death()), this, SLOT(gameOver()));
connect(ui->toMainBtn, SIGNAL(clicked()), this, SLOT(mainWindow()));
connect(ui->widget->getPet(), SIGNAL(need(QString)), this, SLOT(petNeeds(QString)));
connect(ui->widget, SIGNAL(sendMes(QString)), this, SLOT(petNeeds(QString)));
MenuForGames * miniGameMenu = new MenuForGames(NULL);
connect(btn,SIGNAL(clicked()),miniGameMenu,SLOT(show()));
connect(miniGameMenu,SIGNAL(addHappy(int)),ui->widget,SLOT(toPlay(int)));
connect(ui->widget->getPet(), SIGNAL(sleepSgn(int)), ui->toCure, SLOT(hide()));
connect(ui->widget->getPet(), SIGNAL(sleepSgn(int)), ui->toFeed, SLOT(hide()));
connect(ui->widget->getPet(), SIGNAL(sleepSgn(int)), ui->toWash, SLOT(hide()));
connect(ui->widget->getPet(), SIGNAL(sleepSgn(int)), btn, SLOT(hide()));
connect(ui->widget->getPet(), SIGNAL(sleepSgn(int)), ui->toSleep, SLOT(hide()));
connect(ui->widget->getPet(), SIGNAL(sleepSgn(int)), ui->toWakeUp, SLOT(show()));
connect(ui->widget->getPet(), SIGNAL(wakeupSgn(int)), ui->toCure, SLOT(show()));
connect(ui->widget->getPet(), SIGNAL(wakeupSgn(int)), ui->toFeed, SLOT(show()));
connect(ui->widget->getPet(), SIGNAL(wakeupSgn(int)), ui->toWash, SLOT(show()));
connect(ui->widget->getPet(), SIGNAL(wakeupSgn(int)), btn, SLOT(show()));
connect(ui->widget->getPet(), SIGNAL(wakeupSgn(int)), ui->toWakeUp, SLOT(hide()));
connect(ui->widget->getPet(), SIGNAL(wakeupSgn(int)), ui->toSleep, SLOT(show()));
/* QPixmap pix;
pix.load("H:\\img.jpg");
QPalette pal;
pal.setBrush(this->backgroundRole(), QBrush(pix));
this->setPalette(pal);*/
}
GameScreen::~GameScreen()
{
delete ui;
}
void GameScreen::receivePlayer(QString name)
{
emit sendPlayer(name);
ui->birthLbl->setText(ui->widget->getPet()->getLife().toString("dd.MM.yyyy hh:mm"));
ui->birthLbl->update();
}
void GameScreen::setAge(qlonglong s)
{
ui->ageLbl->setText(QString::number(s/1440) + " days " + QString::number(s/60) +
" hours " + QString::number(s - s/60 * 60) + " minutes");
ui->ageLbl->update();
}
void GameScreen::newGame(QString name)
{
ui->widget->createPet();
ui->widget->getPet()->newGame(name);
}
void GameScreen::gameOver()
{
emit toGameOver();
}
void GameScreen::mainWindow()
{
emit toMainWindow();
}
void GameScreen::petNeeds(QString words)
{
emit petSaid(words);
}