-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
112 lines (97 loc) · 2.99 KB
/
mainwindow.cpp
File metadata and controls
112 lines (97 loc) · 2.99 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
string file = "../Projet_2021_2022_Sokoban_0.3/data/LVL/Niveau"+to_string(niveau)+".txt";
cout << file<< endl;
pl = new Plateau(file,1);
this->repaint();
}
MainWindow::~MainWindow()
{
delete ui;
delete pl;
}
void MainWindow::paintEvent(QPaintEvent* e){
QWidget::paintEvent(e);
QPainter painter(this);
pl->afficher_Plateau(&painter, perso);
}
void MainWindow::keyPressEvent ( QKeyEvent * event ) {
int reponse;
string line;
switch(event->key())
{
case Qt::Key_Up :
pl->deplacerPerso(pl->getPersonnage()->getPosition(),"haut");
break;
case Qt::Key_Down :
pl->deplacerPerso(pl->getPersonnage()->getPosition(),"bas");
break;
case Qt::Key_Left :
pl->deplacerPerso(pl->getPersonnage()->getPosition(),"gauche");
break;
case Qt::Key_Right :
pl->deplacerPerso(pl->getPersonnage()->getPosition(),"droite");
break;
}
this->repaint();
if (pl->Niveau_terminee()==true){
reponse= QMessageBox::question(this, "Titre de la fenêtre", "Bravo!! \n Niveau suivant?", QMessageBox::Yes | QMessageBox::No);
if (reponse == QMessageBox::Yes)
{
hide();
niveau++;
gestionPlateau(niveau);
show();
}
else if (reponse == QMessageBox::No){
string file = "../Projet_2021_2022_Sokoban_0.3/data/LVL/level.txt";
cout << file<< endl;
ifstream fichier(file.c_str(), ios::in);
int i =1;
fichier>>line;
if(!fichier.fail())
{
while (fichier.eof() == false and i!=niveau+1){
fichier>>line;
i++;
}
string msg ="Merci d'avoir joué.\n Pour accéder directement au niveau "+to_string(i)+"\n utilisez le code : "+line;
QMessageBox mgb;
mgb.setText(QString::fromStdString(msg));
mgb.exec();
}
close();
}
}
}
void MainWindow::on_actionNouvelle_Partie_triggered()
{
niveau=1;
gestionPlateau(niveau);
//this->repaint();
}
void MainWindow::gestionPlateau(int niveau){
string file = "../Projet_2021_2022_Sokoban_0.3/data/LVL/Niveau"+to_string(niveau)+".txt";
cout << file<< endl;
pl = new Plateau(file,niveau);
this->setFixedSize(pl->getLargeur()*50, 25+pl->getLongueur()*50);
this->repaint();
}
void MainWindow::on_actionRecommencer_triggered()
{
gestionPlateau(niveau);
//this->repaint();
}
void MainWindow::setNiveau(int niv){
niveau = niv;
}
int MainWindow::getNiveau(){
return niveau;
}
void MainWindow::setDeco(int val){deco = val;}
void MainWindow::setPerso(int val){perso = val;}