-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamewidget.cpp
More file actions
164 lines (136 loc) · 3.54 KB
/
gamewidget.cpp
File metadata and controls
164 lines (136 loc) · 3.54 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "gamewidget.h"
#include "game/pet.h"
#include "game/health.h"
#include "pointsbar.h"
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QDebug>
#include <QGraphicsProxyWidget>
GameWidget::GameWidget(QWidget *parent): QWidget(parent),
m_scene(new QGraphicsScene(this)), m_view(new QGraphicsView(m_scene, this)){
count_ref = 0;
ref = false;
QGridLayout *layout = new QGridLayout(NULL);
m_timer = new QTimer(this);
m_scene->setSceneRect(0,0,400,220);
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
layout->setMargin(0);
m_view->setFixedSize(400,220);
layout->addWidget(m_view, 0, 0, 1, 1);
settings = new QSettings("gameSettings");
m_pet = new Pet();
m_pet->move(150,60);
m_pet->action(Nothing);
connect(m_pet, SIGNAL(chHealthSgn(int)), this,SLOT(chHealthSlt(int)));
connect(m_pet, SIGNAL(chEnSgn(int)), this, SLOT(chEnSlt(int)));
connect(m_pet, SIGNAL(chHapSgn(int)), this, SLOT(chHapSlt(int)));
connect(m_pet, SIGNAL(chSatSgn(int)), this, SLOT(chSatSlt(int)));
connect(m_timer, SIGNAL(timeout()), this, SLOT(setRefuse()));
connect(m_pet, SIGNAL(death()), this, SLOT(toKillPet()));
connect(m_pet, SIGNAL(count_ref(int)), this, SLOT(setRefuses(int)));
m_scene->addWidget(m_pet);
m_timer->start(1800000);
setStyleSheet(
"* { background-color: rgba(176, 196, 222, 255); }"
);
settings = new QSettings("gameSettings");
// count_ref = settings->value(m_pet->getPlayer() + "/count_ref").toInt();
// qDebug() <<"ffffffffff"<< settings->allKeys();
// for(int i = 0; i < count_ref; i++)
// setRefuse();
}
Pet *GameWidget::getPet()
{
return m_pet;
}
GameWidget::~GameWidget()
{
settings->setValue(m_pet->getPlayer() + "/count_ref", count_ref);
settings->sync();
}
void GameWidget::chHealthSlt(int level)
{
emit chHealthSgn(level);
}
void GameWidget::chHapSlt(int level)
{
emit chHapSgn(level);
}
void GameWidget::chSatSlt(int level)
{
emit chSatSgn(level);
}
void GameWidget::chEnSlt(int level)
{
emit chEnSgn(level);
}
void GameWidget::toFeed()
{
m_pet->feed(20);
}
void GameWidget::toSleep()
{
m_pet->sleep();
m_timer->stop();
}
void GameWidget::toWash()
{
m_pet->wash(20);
}
void GameWidget::toCure()
{
m_pet->cure();
}
void GameWidget::toWakeUp()
{
m_pet->wakeup();
m_timer->start(1800000);
}
void GameWidget::toPlay(int happynessPoint)
{
m_pet->play(happynessPoint);
}
void GameWidget::toKillPet()
{
m_pet->deleteLater();
}
void GameWidget::setRefuse()
{
count_ref ++;
Refuse *ref = new Refuse(NULL);
connect(ref, SIGNAL(deleted(Refuse*)),this, SLOT(destroyRefuse(Refuse *)));
QGraphicsProxyWidget *proxy = m_scene->addWidget(ref);
int x = rand()%370;
int y = rand()%40+160;
proxy->setPos(x,y);
m_pet->refuseExists();
if(!ref)
emit sendMes("Ugh, there is dirty! It would not hurt to clean.");
}
void GameWidget::setRefuses(int count)
{
ref = true;
for(int i = 0; i < count; i++)
{
setRefuse();
if(i+1 >= count) emit sendMes("Ugh, there is dirty! It would not hurt to clean.");
}
ref = false;
}
void GameWidget::destroyRefuse(Refuse *ref)
{
count_ref--;
m_scene->removeItem(m_scene->focusItem());
ref->deleteLater();
m_pet->refuseDestroyed();
}
void GameWidget::createPet()
{
m_pet = new Pet();
m_pet->action(Nothing);
}