Skip to content

Commit 23ee7f1

Browse files
Add files via upload
1 parent 34c374e commit 23ee7f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3214
-0
lines changed

Odev1/Homework/Balon.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <QRandomGenerator>
2+
#include "clickablelabel.h"
3+
4+
class Balon{
5+
6+
public:
7+
8+
// Constructor
9+
Balon(ClickableLabel *label_temp, int wid){
10+
11+
x= 9 + (QRandomGenerator::global()->generate() % (wid-68));
12+
label=label_temp;
13+
14+
label->setFixedWidth(50);
15+
label->setFixedHeight(50);
16+
17+
label->move(x,80);
18+
19+
int a=QRandomGenerator::global()->generate()%7;
20+
QString temp = ":/images/images/"+QString::number(a)+".jpg";
21+
22+
QPixmap pix(temp);
23+
label->setPixmap(pix.scaled(50,50,Qt::KeepAspectRatio));
24+
25+
label->show();
26+
}
27+
28+
// balonun konumunu asagiya kaydirma
29+
void new_move(){
30+
31+
getLabel()->move(x, getLabel()->pos().y()+6);
32+
33+
}
34+
35+
// balon disari ciktimi kontrolu
36+
static int check(Balon *bal, int H){
37+
38+
if(bal->label->pos().y()>H+4){
39+
return 1;
40+
}
41+
42+
else{
43+
return 0;
44+
}
45+
46+
}
47+
48+
ClickableLabel * getLabel(){
49+
return label;
50+
}
51+
52+
private:
53+
54+
// balon konumu
55+
int x;
56+
57+
// tiklanabilir label
58+
ClickableLabel *label;
59+
60+
};

Odev1/Homework/Homework.pro

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
QT += core gui
2+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
3+
4+
CONFIG += c++11
5+
6+
# The following define makes your compiler emit warnings if you use
7+
# any Qt feature that has been marked deprecated (the exact warnings
8+
# depend on your compiler). Please consult the documentation of the
9+
# deprecated API in order to know how to port your code away from it.
10+
DEFINES += QT_DEPRECATED_WARNINGS
11+
12+
# You can also make your code fail to compile if it uses deprecated APIs.
13+
# In order to do so, uncomment the following line.
14+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
15+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
16+
17+
SOURCES += \
18+
Balon.cpp \
19+
clickablelabel.cpp \
20+
main.cpp \
21+
mainwindow.cpp
22+
23+
HEADERS += \
24+
clickablelabel.h \
25+
mainwindow.h
26+
27+
FORMS += \
28+
mainwindow.ui
29+
30+
# Default rules for deployment.
31+
qnx: target.path = /tmp/$${TARGET}/bin
32+
else: unix:!android: target.path = /opt/$${TARGET}/bin
33+
!isEmpty(target.path): INSTALLS += target
34+
35+
RESOURCES += \
36+
images.qrc

Odev1/Homework/Homework.pro.user

+321
Large diffs are not rendered by default.

Odev1/Homework/clickablelabel.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "clickablelabel.h"
2+
3+
ClickableLabel::ClickableLabel(QWidget* parent, Qt::WindowFlags f)
4+
: QLabel(parent) {
5+
6+
}
7+
8+
ClickableLabel::~ClickableLabel() {}
9+
10+
void ClickableLabel::mousePressEvent(QMouseEvent* event) {
11+
emit clicked();
12+
}

Odev1/Homework/clickablelabel.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef CLICKABLELABEL_H
2+
#define CLICKABLELABEL_H
3+
4+
#include <QLabel>
5+
#include <QWidget>
6+
#include <Qt>
7+
8+
class ClickableLabel : public QLabel {
9+
Q_OBJECT
10+
11+
public:
12+
explicit ClickableLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
13+
~ClickableLabel();
14+
15+
signals:
16+
void clicked();
17+
18+
protected:
19+
void mousePressEvent(QMouseEvent* event);
20+
21+
};
22+
23+
#endif // CLICKABLELABEL_H

Odev1/Homework/images.qrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<RCC>
2+
<qresource prefix="/images">
3+
<file>images/0.jpg</file>
4+
<file>images/1.jpg</file>
5+
<file>images/2.jpg</file>
6+
<file>images/3.jpg</file>
7+
<file>images/4.jpg</file>
8+
<file>images/5.jpg</file>
9+
<file>images/6.jpg</file>
10+
<file>images/arkaplan.jpg</file>
11+
<file>images/patlama.jpg</file>
12+
</qresource>
13+
</RCC>

Odev1/Homework/images/0.jpg

82.3 KB
Loading

Odev1/Homework/images/1.jpg

56.5 KB
Loading

Odev1/Homework/images/2.jpg

6.02 KB
Loading

Odev1/Homework/images/3.jpg

14.2 KB
Loading

Odev1/Homework/images/4.jpg

4.78 KB
Loading

Odev1/Homework/images/5.jpg

16.8 KB
Loading

Odev1/Homework/images/6.jpg

4.84 KB
Loading

Odev1/Homework/images/arkaplan.jpg

429 KB
Loading

Odev1/Homework/images/patlama.jpg

19.3 KB
Loading

Odev1/Homework/main.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "mainwindow.h"
2+
#include <QApplication>
3+
4+
// monitorun boyutu
5+
int heightH;
6+
int widthW;
7+
8+
int main(int argc, char *argv[])
9+
{
10+
QApplication a(argc, argv);
11+
MainWindow w;
12+
w.showFullScreen();
13+
return a.exec();
14+
}

Odev1/Homework/mainwindow.cpp

+219
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
#include "mainwindow.h"
2+
#include "ui_mainwindow.h"
3+
#include "clickablelabel.h"
4+
#include <QRandomGenerator>
5+
6+
// Constructor function
7+
MainWindow::MainWindow(QWidget *parent)
8+
: QMainWindow(parent)
9+
, ui(new Ui::MainWindow)
10+
{
11+
ui->setupUi(this);
12+
13+
// monitore gore oyun ekrani duzenlenir
14+
displaySettings();
15+
16+
// zaman labeli guncelleme
17+
time = 1;
18+
timer_time = new QTimer(this);
19+
connect(timer_time, SIGNAL(timeout()), this, SLOT(time_update()));
20+
timer_time->start(1000);
21+
22+
// otomatik balon cikartma
23+
timer_BalonSpawn = new QTimer(this);
24+
connect(timer_BalonSpawn, SIGNAL(timeout()), this, SLOT(spawn()));
25+
timer_BalonSpawn->start(700);
26+
27+
// balonlari asagi kaydirma signal&slot
28+
// balonlarin ekrandan cikma kontrolu
29+
timer_label = new QTimer(this);
30+
connect(timer_label, SIGNAL(timeout()), SLOT(move_update()));
31+
timer_label->start(40);
32+
33+
// durumu ekranda yazdirmak icin kullanilan labeller.
34+
vurulan=0;
35+
kacan=0;
36+
37+
// oyun ekran ayari
38+
flagWindow=0;
39+
40+
}
41+
42+
MainWindow::~MainWindow()
43+
{
44+
delete ui;
45+
}
46+
47+
// tum ekranlar ile uyumlu olmasini sagliyorum (1920x1080, 1366x768, vb..)
48+
void MainWindow::displaySettings(){
49+
50+
QScreen *screen = QGuiApplication::primaryScreen();
51+
QRect screenGeometry = screen->geometry();
52+
int height_res = screenGeometry.height();
53+
int width_res = screenGeometry.width();
54+
heightH=height_res;
55+
widthW=width_res;
56+
57+
this->resize(width_res, height_res);
58+
59+
ui->label_4->resize(width_res+2, height_res+2);
60+
61+
QPixmap pix(":/images/images/arkaplan.jpg");
62+
ui->label_4->setPixmap(pix.scaled(width_res+2,width_res+2,Qt::KeepAspectRatio));
63+
64+
ui->pushButton->move(width_res-40, 10);
65+
ui->pushButton_2->move(width_res-76, 10);
66+
67+
ui->horizontalLayoutMain->setStretch(0,width_res*0.009);
68+
69+
}
70+
71+
// balonlari asagiya kaydirir ayni zamanda kacan balonlari kontrol eder.
72+
void MainWindow::move_update(){
73+
74+
int count = -1;
75+
76+
foreach(Balon *bal, balon_list){
77+
78+
count++;
79+
80+
// konum guncelleme
81+
bal->new_move();
82+
83+
// balon kacti
84+
if(bal->check(bal, heightH)){
85+
86+
kacan+=1;
87+
QString format("Kaçan Balon Sayısı : <font color='red'>%1</font>");
88+
ui->label_3->setText(format.arg(QString::number(kacan)));
89+
90+
balon_list.at(count)->getLabel()->hide();
91+
delete balon_list.at(count);
92+
balon_list.removeAt(count);
93+
}
94+
}
95+
96+
}
97+
98+
// balonu belirlenen sure sonunda tamamen ortadan kaldirir (patlama efektinden sonra).
99+
void MainWindow::balon_hide(){
100+
101+
if(QueBalon_list.count()!=0){
102+
103+
QueBalon_list.at(0)->getLabel()->hide();
104+
delete QueBalon_list.at(0);
105+
QueBalon_list.removeAt(0);
106+
}
107+
108+
109+
}
110+
111+
// balona tıklanma eventi
112+
void MainWindow::click_balon(){
113+
114+
QObject *balon_label = QObject::sender();
115+
116+
int count = -1;
117+
foreach(Balon *temp, balon_list){
118+
119+
count+=1;
120+
121+
// vurulan balonu&labeli bulduk
122+
if(balon_label==temp->getLabel()){
123+
124+
// label update
125+
vurulan+=1;
126+
QString format("Vurulan Balon Sayısı : <font color='green'>%1</font>");
127+
ui->label_2->setText(format.arg(QString::number(vurulan)));
128+
129+
// patlama efekti
130+
QPixmap pix(":/images/images/patlama.jpg");
131+
balon_list.at(count)->getLabel()->setPixmap(pix.scaled(50,50,Qt::KeepAspectRatio));
132+
133+
// patlama efekti bittikten sonra silinmesi için temp bir liste
134+
QueBalon_list.append(balon_list.at(count));
135+
136+
// ana yapidan cikartilir
137+
balon_list.removeAt(count);
138+
139+
// patlama efekti timeri
140+
QTimer::singleShot(2500, this, SLOT(balon_hide()));
141+
142+
}
143+
}
144+
145+
}
146+
147+
// balonları random spawn
148+
void MainWindow::spawn(){
149+
150+
ClickableLabel *label = new ClickableLabel(this);
151+
connect(label, SIGNAL(clicked()), this, SLOT(click_balon()));
152+
153+
Balon *bal = new Balon(label, widthW);
154+
balon_list.append(bal);
155+
156+
}
157+
158+
// sure labelini guncelleme fonksiyonu
159+
void MainWindow::time_update(){
160+
161+
QString format("Süre : <font color='blue'>%1</font>");
162+
ui->label->setText(format.arg(QString::number(time)));
163+
164+
time+=1;
165+
166+
}
167+
168+
// ESC tusuna basilir ise oyundan cikilir
169+
// (ALT+Tab ile otomatik asagiya alir). veya sag ustteki tuslari kullanabilirsiniz.
170+
void MainWindow::keyReleaseEvent(QKeyEvent *event){
171+
172+
if(event->key()==Qt::Key_Escape){
173+
exit(0);
174+
}
175+
176+
}
177+
178+
// pencere secilince oyun ekranini tekrardan buyultmek icin fonksiyon.
179+
// oyunun durmasini ve baslamsini saglar, boylece arka planda kendi kendine oynamaz ve kullanici balonlari kacirmaz
180+
void MainWindow::changeEvent(QEvent * event){
181+
182+
183+
if(flagWindow!=3){
184+
flagWindow+=1;
185+
}
186+
187+
188+
if(this->isMinimized() || (flagWindow==3 && !(this->isActiveWindow()))){
189+
timer_time->stop();
190+
timer_label->stop();
191+
timer_BalonSpawn->stop();
192+
}
193+
194+
else if(this->isFullScreen() && flagWindow==3){
195+
196+
this->showFullScreen();
197+
timer_time->start();
198+
timer_label->start();
199+
timer_BalonSpawn->start();
200+
}
201+
202+
}
203+
204+
205+
// oyunu (pencereyi kapatmak)
206+
void MainWindow::on_pushButton_clicked()
207+
{
208+
exit(0);
209+
}
210+
211+
// ekrani kucultmek
212+
void MainWindow::on_pushButton_2_clicked()
213+
{
214+
215+
timer_time->stop();
216+
timer_label->stop();
217+
timer_BalonSpawn->stop();
218+
this->showMinimized();
219+
}

0 commit comments

Comments
 (0)