-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildgame.cpp
executable file
·320 lines (251 loc) · 11.3 KB
/
buildgame.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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#include "buildgame.h"
#include <QSound>
#include <QFont>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <QSpacerItem>
#include <QApplication>
#include <QHeaderView>
#include <QIcon>
#include "xmlreader.h"
#include "gamewindow.h"
using namespace std;
BuildGame::BuildGame(Game* game, QWidget* parent): QDesktopWidget() {
MyGame=game;
players_game.clear();
game_players.clear();
//------------------------------------play music
music=new QSound("music/1.wav");
music->play();
music->setLoops(100);
int width=QApplication::desktop()->width();
int height=QApplication::desktop()->height();
//------------------------------------set flag
this->setWindowFlags(Qt::FramelessWindowHint);
QIcon icon("start/2.jpg");
this->setWindowIcon(icon);
//------------------------------------table
table=new QTableWidget(11,7,this);
QPalette* palette = new QPalette();
palette->setBrush(QPalette::Base,*(new QBrush(*(new QPixmap("map/5.jpg")))));
table->setPalette(*palette);
table->resize(width,height*0.94);
table->setColumnWidth(0,table->width()*0.30);
table->setColumnWidth(1,table->width()*0.08);
table->setColumnWidth(2,table->width()*0.12);
table->setColumnWidth(3,table->width()*0.12);
table->setColumnWidth(4,table->width()*0.12);
table->setColumnWidth(5,table->width()*0.12);
table->setColumnWidth(6,table->width()*0.14);
table->setRowHeight(0,0.2*table->height());
for(int i=1; i<11; i++)
table->setRowHeight(i,0.73*height/10);
table->horizontalHeader()->hide();
table->verticalHeader()->hide();
//------------------------------------money and map
table->setSpan(0,0,1,3);
table->setSpan(0,3,1,4);
QVBoxLayout* Vlay=new QVBoxLayout;
QHBoxLayout* Hlay=new QHBoxLayout;
QLabel* label_map=new QLabel("Map");
label_map->setAlignment(Qt::AlignCenter);
QLabel* labelRow=new QLabel(" Row count");
labelRow->setAlignment(Qt::AlignCenter);
QLabel* labelCol=new QLabel(" Col count");
labelCol->setAlignment(Qt::AlignCenter);
map_frame=new QFrame;
map_frame->setLayout(Vlay);
map_colcount=new QSpinBox(map_frame);
map_colcount->setRange(1,1000);
map_colcount->resize(40,30);
map_colcount->setValue(60);
map_rowcount=new QSpinBox(map_frame);
map_rowcount->setRange(1,1000);
map_rowcount->resize(40,30);
map_rowcount->setValue(60);
Vlay->addWidget(label_map);
Vlay->addLayout(Hlay);
Hlay->addSpacerItem(new QSpacerItem(50,200, QSizePolicy::Fixed, QSizePolicy::Maximum));
Hlay->addWidget(labelRow);
Hlay->addWidget(map_rowcount);
Hlay->addSpacerItem(new QSpacerItem(50,200, QSizePolicy::Fixed, QSizePolicy::Maximum));
Hlay->addWidget(labelCol);
Hlay->addWidget(map_colcount);
Hlay->addSpacerItem(new QSpacerItem(60,200, QSizePolicy::Fixed, QSizePolicy::Maximum));
Vlay->addSpacerItem(new QSpacerItem(40,30, QSizePolicy::Maximum, QSizePolicy::Fixed));
table->setCellWidget(0,0,map_frame);
//------------------------------------money
QFrame* money_frame=new QFrame;
QVBoxLayout* v_lay=new QVBoxLayout;
QHBoxLayout* h_lay=new QHBoxLayout;
QLabel* money_label=new QLabel("Money");
money_label->setAlignment(Qt::AlignCenter);
QLabel* money=new QLabel("Set first money");
money->setAlignment(Qt::AlignCenter);
money_spin=new QSpinBox;
money_spin->setRange(0,100000);
money_spin->setValue(10000);
money_spin->setAlignment(Qt::AlignCenter);
money_frame->setLayout(v_lay);
v_lay->addWidget(money_label);
h_lay->addSpacerItem(new QSpacerItem(140,200, QSizePolicy::Fixed, QSizePolicy::Maximum));
h_lay->addWidget(money);
h_lay->addSpacerItem(new QSpacerItem(50,200, QSizePolicy::Fixed, QSizePolicy::Maximum));
h_lay->addWidget(money_spin);
h_lay->addSpacerItem(new QSpacerItem(100,200, QSizePolicy::Fixed, QSizePolicy::Maximum));
v_lay->addLayout(h_lay);
v_lay->addSpacerItem(new QSpacerItem(30,30, QSizePolicy::Maximum, QSizePolicy::Fixed));
table->setCellWidget(0,3,money_frame);
//-----------------------------------select player
//------------------------------------------------new label and set in table
Lplayer_name=new QLabel("Player name");
Lplayer_name->setAlignment(Qt::AlignCenter);
table->setCellWidget(2,0,Lplayer_name);
Lplayer_team=new QLabel("team");
Lplayer_team->setAlignment(Qt::AlignCenter);
table->setCellWidget(2,1,Lplayer_team);
Lplayer_x=new QLabel("start row");
Lplayer_x->setAlignment(Qt::AlignCenter);
table->setCellWidget(2,2,Lplayer_x);
Lplayer_y=new QLabel("start col");
Lplayer_y->setAlignment(Qt::AlignCenter);
table->setCellWidget(2,3,Lplayer_y);
Lplayer_rowcount=new QLabel("row count");
Lplayer_rowcount->setAlignment(Qt::AlignCenter);
table->setCellWidget(2,4,Lplayer_rowcount);
Lplayer_colcount=new QLabel("colcount");
Lplayer_colcount->setAlignment(Qt::AlignCenter);
table->setCellWidget(2,5,Lplayer_colcount);
char str[100];
for(int i=2; i<10; i++){
//-----------------------------------------------name line edit
sprintf(str,"player %d",i-1);
player_name[i]=new QLineEdit(str);
table->setCellWidget(i+1,0,player_name[i]);
//-----------------------------------------------team comboBox
int team_count=2;
player_team[i]=new QComboBox;
for(int j=0; j<team_count; j++){
sprintf(str,"team %d",j+1);
player_team[i]->addItem(str);
}
table->setCellWidget(i+1,1,player_team[i]);
//-----------------------------------------------strat x
sprintf(str,"%d",0);
player_x[i]=new QLineEdit(str);
table->setCellWidget(i+1,2,player_x[i]);
//-----------------------------------------------start y
sprintf(str,"%d",(i-2)*30);
player_y[i]=new QLineEdit(str);
table->setCellWidget(i+1,3,player_y[i]);
//-----------------------------------------------row count
sprintf(str,"%d",30);
player_rowcount[i]=new QLineEdit(str);
table->setCellWidget(i+1,4,player_rowcount[i]);
//-----------------------------------------------col count
sprintf(str,"%d",30);
player_colcount[i]=new QLineEdit(str);
table->setCellWidget(i+1,5,player_colcount[i]);
}
//-------------------------------------------------row = 0
Lplayer_count=new QLabel("Count of Player");
player_count=new QComboBox;
for(int i=0; i<9; i++){
sprintf(str,"%d",i);
player_count->addItem(str);
}
Lplayer_count->setAlignment(Qt::AlignCenter);
table->setCellWidget(1,0,Lplayer_count);
table->setCellWidget(1,1,player_count);
//-----------------------------------start and quit
QTableWidget* tableButton=new QTableWidget(1,9,this);
palette->setBrush(QPalette::Base,*(new QBrush(*(new QPixmap("map/5.jpg")))));
tableButton->setPalette(*palette);
tableButton->resize(width,height*0.059);
tableButton->horizontalHeader()->hide();
tableButton->verticalHeader()->hide();
tableButton->move(0,height*0.94);
tableButton->setShowGrid(false);
tableButton->setRowHeight(0,height*0.057);
for(int i=0; i<6; i++)
tableButton->setColumnWidth(i,table->width()/9);
start=new QPushButton("Start");
quit=new QPushButton("Quit");
tableButton->setCellWidget(0,3,start);
tableButton->setCellWidget(0,5,quit);
for(int i=3; i<11; i++)
table->hideRow(i);
//---------------------------------------------------change font all label
QFont f("Arial", 12, QFont::Bold);
Lplayer_count->setStyleSheet("QLabel { color : rgb(200,150,50); }");
Lplayer_count->setFont(f);
Lplayer_name->setStyleSheet("QLabel { color : rgb(200,150,50); }");
Lplayer_team->setStyleSheet("QLabel { color : rgb(200,150,50); }");
Lplayer_x->setStyleSheet("QLabel { color : rgb(200,150,50); }");
Lplayer_y->setStyleSheet("QLabel { color : rgb(200,150,50); }");
Lplayer_rowcount->setStyleSheet("QLabel { color : rgb(200,150,50); }");
Lplayer_colcount->setStyleSheet("QLabel { color : rgb(200,150,50); }");
label_map->setStyleSheet("QLabel { color : rgb(200,150,50); }");
label_map->setFont(f);
labelRow->setStyleSheet("QLabel { color : rgb(200,150,50); }");
labelCol->setStyleSheet("QLabel { color : rgb(200,150,50); }");
money_label->setStyleSheet("QLabel { color : rgb(200,150,50); }");
money_label->setFont(f);
money->setStyleSheet("QLabel { color : rgb(200,150,50); }");
//-------------------------------------------------change spin
QPalette myPalette;
myPalette.setColor(QPalette::Active, QPalette::Base, QColor(200,150,50));
map_rowcount->setPalette(myPalette);
map_colcount->setPalette(myPalette);
money_spin->setPalette(myPalette);
player_count->setStyleSheet("QComboBox { background-color: rgb(200,150,50); }");
player_count->setPalette(myPalette);
//----------------------------------------------------signals
connect(start,SIGNAL(clicked()),this,SLOT(Start()));
connect(quit,SIGNAL(clicked()),this,SLOT(Quit()));
connect(player_count,SIGNAL(currentIndexChanged(int)),this,SLOT(ShowPlayer()));
}
void BuildGame::ShowPlayer(){
for(int i=3; i<11; i++)
table->showRow(i);
for(int i=3+player_count->currentIndex(); i<11; i++)
table->hideRow(i);
}
void BuildGame::Start(){
if(player_count->currentIndex()==0 || player_count->currentIndex()==1)
return;
map=new Map(map_rowcount->value(),map_colcount->value());
//-------------------------------------------------------build zombie team
vector <Block*> t1;
Player zombie_player("zombie",-1,0,-1,t1);
players_game.push_back(zombie_player);
for(int i=1; i<player_count->currentIndex()+1; i++){
Player temp;
vector< Block*> area;
int team_id=player_team[i+1]->currentIndex();
int money=money_spin->value();
QString str_name=player_name[i+1]->text();
//-----------------------------------------------set area block
int start_row=player_x[i+1]->text().toInt();
int start_col=player_y[i+1]->text().toInt();
int count_row=player_rowcount[i+1]->text().toInt();
int count_col=player_colcount[i+1]->text().toInt();
for(int j=start_row; j<start_row+count_row; j++)
for(int k=start_col; k<start_col+count_col; k++)
if(j>0 && k>0 && j<map->GetRowcount() && k<map->GetColcount())
area.push_back(map->getBlock(j,k));
players_game.push_back(Player(str_name,team_id,money,i,area));
}
for(unsigned int i=0; i<players_game.size(); i++)
game_players.push_back(&players_game[i]);
XmlReader reader(game_players);
//------------------------------------------------------build new game
MyGame->newGame(game_players,map);
music->stop();
game_window=new GameWindow(MyGame,game_players);
game_window->showMaximized();
}
void BuildGame::Quit(){
exit(0);
}