-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhome_window.cpp
391 lines (329 loc) · 11 KB
/
home_window.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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#include "home_window.h"
#include "ui_home_window.h"
#include <QMessageBox>
#include <ctime>
#include <cstdlib>
#include <QThread>
#include <QTimer>
home_window::home_window(QString login, QWidget *parent) :
QWidget(parent),
ui(new Ui::home_window)
{
ui->setupUi(this);
connect(ui->button_send_messege,SIGNAL(clicked()),this, SIGNAL(change_wnd_to_swnd()));
this->setWindowTitle("Мастер-класс Криптография");
int level = 1;
ui->button_overhear_messege->setEnabled(level>=2);
ui->button_assimetry->setEnabled(level>=5);
srand(time(NULL));//это для случайных чисел
login_name = login;
ui->lbl_login_value->setText(login_name);
ui->lbl_level_value->setText("1");
add_new_player(login_name);
ui->lbl_new_intercepted_msg->setPixmap(QPixmap::fromImage(QImage(":/images/new_messege.png")).scaled(
ui->lbl_new_intercepted_msg->size()));
ui->lbl_new_intercepted_msg->setVisible(false);
timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(rotate_rulet()));
}
home_window::~home_window()
{
delete ui;
}
void home_window:: set_lvl_label(QString lvl)
{
ui->lbl_level_value->setText(lvl);
}
vector <vector<QImage>> cut_image(QImage &image, int n, int m)
{
vector<vector<QImage>> cut;
for (int i = 0; i<m; i++)
{
vector<QImage> str_image;
for (int j = 0; j<n; j++)
{
QImage temp(100,100,image.format());
int wid_temp = j*100+100;
for (int wid = j*100; wid<wid_temp; wid++)
{
int hei_temp = i*100+100;
for (int hei = i*100; hei < hei_temp; hei++)
{
QRgb t = image.pixel(wid,hei);
temp.setPixel(wid%100, hei%100, t);
}
}
str_image.push_back(temp);
}
cut.push_back(str_image);
}
return cut;
}
void home_window::create_img_buttons(vector<vector<QImage>> cut,
int n, int m, vector<vector<QString>> codes,
vector<vector<QString>> mess, QIcon icon_test)
{
for (int i = 0; i < n; i++)
{
vector<QPB_modify*> pb_vec;
for (int j = 0; j < m; j++)
{
QPB_modify *pb = new QPB_modify;
pb->i = i;
pb->j = j;
pb->rune_code = codes[i][j];
pb->reverse_img = cut[i][j];
pb->was_opening = false;
pb->str = mess[i][j];
QSize button_size(50,50);
pb->setMaximumSize(button_size);
pb->setMinimumSize(button_size);
pb->setIcon(icon_test);
QSize icon_size(40,40);
pb->setIconSize(icon_size);
connect(pb, &QPushButton::clicked, [this, pb]()
{
if (count_777 == 0)
{
QMessageBox::information(this, "Азино 777", "Вращайте барабан!");
return;
}
count_777--;
QPB_modify *pb2 = new QPB_modify;
pb2->setIcon(QPixmap::fromImage(pb->reverse_img));
pb2->setIconSize(pb->size());
pb2->setMaximumSize(pb->size());
pb2->str = pb->str;
pb2->was_sending = false;
pb2->was_opening = true;
pb2->i = pb->i;
pb2->j = pb->j;
connect(pb2, &QPushButton::clicked, [this, pb2]()
{
if (pb2->was_sending == false)
QMessageBox::information(this, "info", "Не удалось отправить сообщение в штаб");
else
QMessageBox::information(this, "info", pb2->str);
});
emit i_opend(pb->reverse_img, pb->i, pb->j, pb->rune_code);
ui->componate_custom_buttons_img->addWidget(pb2, pb->i, pb->j);
delete icons[pb2->i][pb2->j];
icons[pb2->i][pb2->j] = pb2;
});
emit do_it(pb->i, pb->j);
ui->componate_custom_buttons_img->addWidget(pb,i,j);
pb_vec.push_back(pb);
}
icons.push_back(pb_vec);
}
}
void home_window::add_new_player(QString new_player_login)
{
players.push_back(new_player_login);
ui->user_list->addItem(new_player_login);
}
void home_window::on_button_overhear_messege_clicked()
{
ui->lbl_new_intercepted_msg->setVisible(false);
emit this->show_intercept_wnd_please();
}
void home_window::on_button_inercept_clicked()
{
QString intercepting_player;
for (int i = 0; i < (int)ui->user_list->count(); i++)
{
QListWidgetItem *it = ui->user_list->item(i);
if (it->isSelected())
{
intercepting_player = ui->user_list->item(i)->text();
break;
}
}
int player_size = players.size();
for (int i = 0; i < player_size; i++)
if (intercepting_player == players[i])
{
emit this->i_want_intercept(intercepting_player);
ui->lbl_overhere_value->setText(intercepting_player);
return;
}
QMessageBox::information(this, "error", "Такого игрока нет");
}
void home_window::set_visibale_new_messege(bool vis)
{
ui->lbl_new_intercepted_msg->setVisible(vis);
}
/* ------ */
void home_window::on_automat_clicked()
{
ui->automat->setEnabled(false);
int iRand = rand() % 2;
rand_image(iRand);
count_timer = 0;
timer->start(450);
}
void home_window::rand_image(int c)
{
QImage img;
switch (c)
{
case 3:
{
int image_num = rand()%5;
img=runes[image_num];
ui->rand_image1->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image1->size()));
ui->rand_image2->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image2->size()));
ui->rand_image3->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image3->size()));
break;
}
case 2:
{
int count_runes = 5;
int runes2[] = { 0,1,2,3,4 };
int new_runes[] = { 0,1 };
for (int i = 0; i < 2; i++)
{
int Rand_index = rand() % count_runes;
new_runes[i] = runes2[Rand_index];
int last = runes2[count_runes - 1];
runes2[Rand_index] = last;
count_runes--;
}
int place = rand() % 3;
switch (place)
{
case 0:
//натянуть на 2 и 3
img=runes[new_runes[0]];
ui->rand_image2->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image2->size()));
ui->rand_image3->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image3->size()));
img=runes[new_runes[1]];
ui->rand_image1->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image1->size()));
break;
case 1:
//натянуть на 1 и 3
img=runes[new_runes[0]];
ui->rand_image1->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image1->size()));
ui->rand_image3->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image3->size()));
img=runes[new_runes[1]];
ui->rand_image2->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image2->size()));
break;
case 2:
//натянуть на 1 и 2
img=runes[new_runes[0]];
ui->rand_image1->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image1->size()));
ui->rand_image2->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image2->size()));
img=runes[new_runes[1]];
ui->rand_image3->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image3->size()));
break;
}
break;
}
case 1:
{
int count_runes = 5;
int runes2[] = { 0,1,2,3,4 };
int new_runes[] = { 0,1,2 };
for (int i = 0; i < 3; i++)
{
int Rand_index = rand() % count_runes;
new_runes[i] = runes2[Rand_index];
int last = runes2[count_runes - 1];
runes2[Rand_index] = last;
count_runes--;
}
//сделать одно
img=runes[new_runes[0]];
ui->rand_image1->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image1->size()));
//второе
img=runes[new_runes[1]];
ui->rand_image2->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image2->size()));
//третье
img=runes[new_runes[2]];
ui->rand_image3->setPixmap(QPixmap::fromImage(img).scaled(ui->rand_image3->size()));
break;
}
}
}
void home_window::i_find_image_bf(int i, int j)
{
QPB_modify *pb = icons[i][j];
if (pb->was_opening == false)
{
count_777++; // Компенсация перехваченного сообщения
emit pb->clicked();
}
}
/* ------ */
void home_window::on_button_assimetry_clicked()
{
emit this->from_home_wnd_to_rsa_wnd();
}
void home_window::up_level(int level)
{
ui->button_overhear_messege->setEnabled(level>=2);
ui->button_assimetry->setEnabled(level>=7);
}
void home_window::set_button_was_sending(int i, int j)
{
QPB_modify* pb = icons[i][j];
pb->was_sending = true;
ui->componate_custom_buttons_img->addWidget(pb, pb->i, pb->j);
icons[pb->i][pb->j] = pb;
}
void home_window::rotate_rulet()
{
int iRand = rand() % 2;
rand_image(iRand);
count_timer++;
if (count_timer == 17)
{
timer->stop();
ui->automat->setEnabled(true);
count_timer = 0;
int luck;
if (flag_offline)
luck = 99;
else
luck = rand() % 100;
if (luck<82)
{
//3 случайные картинки, не совпадающие
rand_image(1);
QMessageBox::information(this,"LOSE", "К сожалению, вам не повезло. Попробуйте еще раз.");
}
else if (luck<92)
{
//открыть 2 одинаковые
rand_image(2);
count_777++;
QMessageBox::information(this,"WIN", "Поздравляем! Вы можете открыть одно изображение!");
}
else
{
//открыть 3 одинаковые
rand_image(3);
count_777+=2;
QMessageBox::information(this,"WIN", "Вы сказочный везунчик! Вы можете открыть целых два изображения!");
}
}
}
void home_window::delete_player(QString login)
{
for (int i = 0; i < (int)ui->user_list->count(); i++)
{
if (login == ui->user_list->item(i)->text())
{
delete ui->user_list->takeItem(i);
break;
}
}
for (int i = 0; i < (int)players.size(); i++)
{
if (login == players[i])
{
players.erase(players.begin()+i);
break;
}
}
}