-
Notifications
You must be signed in to change notification settings - Fork 0
/
bingowindow.cpp
276 lines (248 loc) · 8.03 KB
/
bingowindow.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
#include "bingowindow.h"
#include "ui_bingowindow.h"
#include <QFileDialog>
#include <QList>
#include <QTextStream>
#include <QDebug>
#include <algorithm>
#include <random>
#include <time.h>
#include <QtMath>
#include <QPoint>
#include <QMovie>
#include <QTimer>
#include <QSound>
#include <QTcpServer>
#include <QRandomGenerator>
#include "bingoitem.h"
#define SizeX 128
#define SizeY 128
#define AmmSFX 2
std::string SFX[] = {
":/Bazoopie/DriesBazooper.wav",
":/Bazoopie/Bazooper.wav"
};
void BingoWindow::SetupBingo()
{
scene = new QGraphicsScene();
ui->BingoBord->setScene(scene);
BI = new QList<BingoItem*>();
BingoStates = new QList<bool>();
ui->stackedWidget->setCurrentIndex(0);
}
BingoWindow::BingoWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::BingoWindow)
{
ui->setupUi(this);
this->BingoItems = new QList<QString>();
qsrand(time(NULL));
SetupBingo();
}
BingoWindow::~BingoWindow()
{
delete ui;
}
void BingoWindow::on_horizontalSlider_valueChanged(int value)
{
ui->SliderValueLabel->setText(QString::number(value));
if(this->BingoItems->count() > ui->horizontalSlider->value() * ui->horizontalSlider->value())
{
ui->StartBingoButton->setEnabled(true);
}
else
{
ui->StartBingoButton->setEnabled(false);
}
}
void BingoWindow::on_LoadBingoStuffButton_clicked()
{
QStringList filters({"Text files (*.txt)",
"Any files (*)"
});
//load in bingo information
QFileDialog Diag(this);
Diag.setNameFilters(filters);
if(Diag.exec())
{
//Diag worked, get input file :)
ui->FilePath->setText(Diag.selectedFiles().first());
QFile InputFile(Diag.selectedFiles().first());
if (InputFile.open(QIODevice::ReadOnly))
{
QTextStream in(&InputFile);
while (!in.atEnd())
{
//read every line
QString line = in.readLine();
if(line != "")
{
//qDebug() << line;
this->BingoItems->append(line);
}
}
InputFile.close();
}
if(this->BingoItems->count() > ui->horizontalSlider->value() * ui->horizontalSlider->value())
{
ui->StartBingoButton->setEnabled(true);
}
else
{
ui->StartBingoButton->setEnabled(false);
}
}
}
void BingoWindow::on_StartBingoButton_clicked()
{
//shuffle list, grab top X²
std::random_shuffle(this->BingoItems->begin(), this->BingoItems->end());
ui->stackedWidget->setCurrentIndex(1);
scene->setSceneRect(0,0, ui->horizontalSlider->value() * SizeX, ui->horizontalSlider->value() * SizeY);
for(int x = 0; x < ui->horizontalSlider->value(); x++)
{
for(int y = 0; y < ui->horizontalSlider->value(); y++)
{
BingoItem* Bingo = new BingoItem(x,y, ui->horizontalSlider->value() ,this->BingoItems->at(x + y * ui->horizontalSlider->value()));
BI->append(Bingo);
BingoStates->append(false);
ui->BingoBord->scene()->addItem(Bingo);
connect(Bingo, &BingoItem::MePressed, this, &BingoWindow::OnBingoButtonClicked);
connect(this, &BingoWindow::Bazooper, Bingo, &BingoItem::Bazoopered);
}
}
}
void BingoWindow::OnBingoButtonClicked(bool State, int ID)
{
//separate array????? yes :chad:
BingoStates->replace(ID,State);
//iterate over these BAD BOYS and see if there's any lines or some idk
int Size = ui->horizontalSlider->value();
int BingoType = 0;
int StartPos = -1;
int EndPos = -1;
//horrible and ugly code but I'm lazy so deal with it
bool Bazooper = false;
//go over X first I guess aye
for(int i = 0; i < BingoStates->count(); i+= Size)
{
if(!Bazooper)
{
StartPos = i;
Bazooper = true;
for(int x = i; x < i + Size; x++)
{
BingoType = 0;
Bazooper &= BingoStates->at(x);
EndPos = x;
}
}
}
if(!Bazooper) //skip if already bazoopered
{
//do Y now
for(int i = 0; i < Size; i++)
{
if(!Bazooper)
{
Bazooper = true;
for(int y = 0; y < Size; y++)
{
StartPos = i;
Bazooper &= BingoStates->at(y * Size + i);
BingoType = 1;
EndPos = (y * Size + i);
}
}
}
}
if(!Bazooper) //skip AGAIN if already bazoopered
{
//now do schuine zijdekes
Bazooper = true;
StartPos = 0;
for(int i = 0; i < Size * Size; i += Size + 1)
{
Bazooper &= BingoStates->at(i);
EndPos = i;
BingoType = 2;
}
if(!Bazooper) //break didn't want to work here so I'm crying :(
{
Bazooper = true;
StartPos = Size * Size - (Size);
for(int i = Size * Size - (Size); i > 0; i -= Size - 1)
{
Bazooper &= BingoStates->at(i);
EndPos = i;
BingoType = 3;
}
}
}
if(Bazooper)
{
QGraphicsLineItem *line;
//I really do be writing jank doe
QPen pen;
pen.setWidth(8);
pen.setCapStyle(Qt::RoundCap);
switch(BingoType)
{
case 0: //horizontal
{
line = scene->addLine((StartPos % Size) * SizeX, qFloor((float)StartPos / (float)Size) * SizeY + SizeY / 2
, (EndPos % Size) * SizeX + SizeX, qFloor((float)EndPos / (float)Size) * SizeY + SizeY / 2, pen);
break;
}
case 1: //vertigo
{
line = scene->addLine((StartPos % Size) * SizeX + SizeX / 2, qFloor((float)StartPos / (float)Size) * SizeY
, (EndPos % Size) * SizeX + SizeX / 2, qFloor((float)EndPos / (float)Size) * SizeY + SizeY, pen);
break;
}
case 2:
{
line = scene->addLine((StartPos % Size) * SizeX, qFloor((float)StartPos / (float)Size) * SizeY
, (EndPos % Size) * SizeX + SizeX, qFloor((float)EndPos / (float)Size) * SizeY + SizeY, pen);
break;
}
case 3:
{
line = scene->addLine((StartPos % Size) * SizeX, qFloor((float)StartPos / (float)Size) * SizeY + SizeY
, (EndPos % Size) * SizeX + SizeX, qFloor((float)EndPos / (float)Size) * SizeY, pen);
break;
}
}
QLabel *gif_anim = new QLabel();
QMovie *movie = new QMovie(":/Bazoopie/out.GIF");
QSound::play(QString::fromStdString(SFX[QRandomGenerator::global()->bounded(AmmSFX)]));
movie->setBackgroundColor(Qt::white);
if (!movie->isValid())
{
// Something went wrong :(
qDebug() << "oops";
}
gif_anim->setMovie(movie);
movie->start();
connect(movie, &QMovie::frameChanged, this, [=](){
if(movie->currentFrameNumber() == (movie->frameCount() - 1))
{
movie->stop();
QTimer::singleShot(2000, this, [=](){
gif_anim->hide();
delete gif_anim;
QTimer::singleShot(5000, this, [=]{
SetupBingo();
});
});
}
});
QGraphicsProxyWidget *proxy = scene->addWidget(gif_anim);
//ui->BingoBord->fitInView(proxy);
QPointF center = ui->BingoBord->mapToScene(ui->BingoBord->viewport()->rect().center());
proxy->setPos(center.x()-movie->frameRect().width()/2, center.y()-movie->frameRect().height()/3);
gif_anim->setAttribute(Qt::WA_NoSystemBackground);
emit this->Bazooper();
}
//qDebug() << Bazooper;
}