Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Laser + jeu complet
Browse files Browse the repository at this point in the history
  • Loading branch information
AngryLama committed Jan 24, 2016
1 parent 720e4a8 commit 4babb15
Show file tree
Hide file tree
Showing 2 changed files with 219 additions and 16 deletions.
223 changes: 209 additions & 14 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ MainWindow::MainWindow(QWidget *parent) :

texteGagne=new QGraphicsTextItem("GAGNE");
texteGagne->setDefaultTextColor(QColor(Qt::white));
texteGagne->setPos(width()/4,height()/2);
texteGagne->setFont(QFont("Spylord Laser",250));
texteGagne->setPos(width()/10,height()/3);
texteGagne->setFont(QFont("Spylord Laser",80));
sceneGagne->addItem(texteGagne);

retourMenuGagne=new QGraphicsRectItem(0,0,120,120);
Expand Down Expand Up @@ -229,6 +229,8 @@ MainWindow::MainWindow(QWidget *parent) :

MainWindow::~MainWindow()
{
sceneGagne->clear();
delete sceneGagne;
sceneEditeur->clear();
delete sceneEditeur;
delete pen;
Expand All @@ -243,6 +245,121 @@ MainWindow::~MainWindow()
delete ui;
}

void MainWindow::calculLaser(short x, short y, short sens)
{
bool verifObjet=false;
switch (sens) {
case GD:
{
while(x<TAILLE && !verifObjet)
{
if(currentPattern[x][y]=="")
{
tableauJeu[x][y]->setBrush(QBrush(QPixmap(":/Laser/Laser droit H.png").scaledToHeight(tableauJeu[x][depart]->rect().height())));
x++;
}else{
verifObjet=true;
}
}
break;
}
case DG:
{
while(x>0 && !verifObjet)
{
if(currentPattern[x][y]=="")
{
tableauJeu[x][y]->setBrush(QBrush(QPixmap(":/Laser/Laser droit H.png").scaledToHeight(tableauJeu[x][depart]->rect().height())));
x--;
}else{
verifObjet=true;
}
}
break;
}
case HB:
{
while(y<TAILLE && !verifObjet)
{
if(currentPattern[x][y]=="")
{
tableauJeu[x][y]->setBrush(QBrush(QPixmap(":/Laser/Laser droit V.png").scaledToHeight(tableauJeu[x][depart]->rect().height())));
y++;
}else{
verifObjet=true;
}
}
break;
}
case BH:
{
while(y>0 && !verifObjet)
{
if(currentPattern[x][y]=="")
{
tableauJeu[x][y]->setBrush(QBrush(QPixmap(":/Laser/Laser droit V.png").scaledToHeight(tableauJeu[x][depart]->rect().height())));
y--;
}else{
verifObjet=true;
}
}
break;
}
default:
break;
}
if(verifObjet)
{
if(currentPattern[x][y]=="GH")
{
tableauJeu[x][y]->setBrush(QBrush(QPixmap(":/Laser/Miroir GH laser.png").scaledToHeight(tableauJeu[x][y]->rect().height())));
if(sens==GD)
calculLaser(x,y-1,BH);
if(sens==HB)
calculLaser(x-1,y,DG);
}
if(currentPattern[x][y]=="DH")
{
tableauJeu[x][y]->setBrush(QBrush(QPixmap(":/Laser/Miroir DH laser.png").scaledToHeight(tableauJeu[x][y]->rect().height())));
if(sens==HB)
calculLaser(x+1,y,GD);
if(sens==DG)
calculLaser(x,y-1,BH);
}
if(currentPattern[x][y]=="GB")
{
tableauJeu[x][y]->setBrush(QBrush(QPixmap(":/Laser/Miroir GB laser.png").scaledToHeight(tableauJeu[x][y]->rect().height())));
if(sens==GD)
calculLaser(x,y+1,HB);
if(sens==BH)
calculLaser(x-1,y,DG);
}
if(currentPattern[x][y]=="DB")
{
tableauJeu[x][y]->setBrush(QBrush(QPixmap(":/Laser/Miroir DB laser.png").scaledToHeight(tableauJeu[x][y]->rect().height())));
if(sens==BH)
calculLaser(x+1,y,GD);
if(sens==DG)
calculLaser(x,y+1,HB);
}
if(currentPattern[x][y]=="TIE")
{
for(int x=0;x<TAILLE;x++)
{
for(int y=0;y<TAILLE;y++)
{
tableauJeu[x][y]->setBrush(QBrush());
}
}
for(int x=0;x<4;x++)
affNbSelection[x]->hide();
sceneGagne->addItem(retourMenuGagne);
sceneGagne->addItem(curseur);
jeu->setScene(sceneGagne);
}
}
}

void MainWindow::on_sourisBougee(QPoint position)
{
if(jeu->scene()==sceneMenu){
Expand All @@ -260,7 +377,7 @@ void MainWindow::on_sourisBougee(QPoint position)
else boutonMenu[1]->setBrush(QBrush(QPixmap(":/Images/boutonEditeur.png").scaledToHeight(boutonMenu[0]->rect().height())));
}
}
if(jeu->scene()==sceneEditeur || jeu->scene()==sceneJeu || jeu->scene()==sceneNiveaux)
if(jeu->scene()==sceneEditeur || jeu->scene()==sceneJeu || jeu->scene()==sceneNiveaux || jeu->scene()==sceneGagne)
{
curseur->setPos(position);
}
Expand Down Expand Up @@ -379,12 +496,19 @@ void MainWindow::on_sourisCliquee(int touche)
for(int y=0;y<TAILLE;y++)
{
currentPattern[x][y].clear();
if(pattern[x][y]=="TIE")
{
currentPattern[x][y]="TIE";
tableauJeu[x][y]->setBrush(QBrush(QPixmap(":/Images/chasseur.png").scaledToHeight(tableauJeu[x][y]->rect().height())));
}
}
}
for(int x=0;x<4;x++)
{
affNbSelection[x]->show();
}
calculLaser(0,depart,GD);
sceneJeu->addItem(retourMenuGagne);
sceneJeu->addItem(curseur);
jeu->setScene(sceneJeu);
}else{
Expand Down Expand Up @@ -521,7 +645,7 @@ void MainWindow::on_sourisCliquee(int touche)
isOffiSelectionNiveaux=verifOffi;
currentSelectionNiveaux=memX;
QSqlQuery query;
query.prepare("select grille0,grille1,grille2,grille3,grille4,grille5,grille6,grille7 from Niveaux where nom=:nom and off=:off;");
query.prepare("select grille0,grille1,grille2,grille3,grille4,grille5,grille6,grille7,depart from Niveaux where nom=:nom and off=:off;");
if(verifOffi){
sceneNiveaux->removeItem(boutonNiveaux[1]);
sceneNiveaux->removeItem(boutonNiveaux[2]);
Expand All @@ -537,6 +661,10 @@ void MainWindow::on_sourisCliquee(int touche)
{
while(query.next())
{
for(int y=0;y<TAILLE;y++)
departJeu[y]->setBrush(QBrush());
departJeu[query.value(8).toInt()]->setBrush(QBrush(QPixmap(":/Images/fighter.png").scaledToHeight(departJeu[query.value(8).toInt()]->rect().height())));
depart=query.value(8).toInt();
for(int x=0;x<TAILLE;x++)
{
QStringList temp=query.value(x).toString().split(";");
Expand Down Expand Up @@ -589,6 +717,20 @@ void MainWindow::on_sourisCliquee(int touche)
if(verifSelection){
curseur->setBrush(selectionEditeur[currentSelectionJeu]->brush());
}
if(listeItem.last()==retourMenuGagne)
{
for(int x=0;x<TAILLE;x++)
{
for(int y=0;y<TAILLE;y++)
{
tableauJeu[x][y]->setBrush(QBrush());
}
}
for(int x=0;x<4;x++)
affNbSelection[x]->hide();
sceneMenu->addItem(curseur);
jeu->setScene(sceneMenu);
}
}
}else{
if(jeu->scene()==sceneGagne)
Expand Down Expand Up @@ -640,6 +782,64 @@ void MainWindow::on_sourisCliquee(int touche)
}
}
}
}else{
if(jeu->scene()==sceneJeu)
{
QList<QGraphicsItem*> listeItem;
listeItem = curseur->collidingItems();
listeItem.removeOne(cadreJeu);
if (listeItem.length()>0)
{
bool verifTableau=false;
int cx,cy;
for(int x=0;x<TAILLE;x++)
{
for(int y=0;y<TAILLE;y++)
{
if(listeItem.last()==tableauJeu[x][y])
{
if(currentPattern[x][y]!="" && currentPattern[x][y]!="M" && currentPattern[x][y]!="TIE")
{
verifTableau=true;
cx=x;
cy=y;
}
}
}
}
if(verifTableau)
{
if(currentPattern[cx][cy]=="GH")
{
affNbSelection[0]->setText(QString::number(affNbSelection[0]->text().toInt()+1));
}
if(currentPattern[cx][cy]=="DH")
{
affNbSelection[1]->setText(QString::number(affNbSelection[1]->text().toInt()+1));
}
if(currentPattern[cx][cy]=="GB")
{
affNbSelection[2]->setText(QString::number(affNbSelection[2]->text().toInt()+1));
}
if(currentPattern[cx][cy]=="DB")
{
affNbSelection[3]->setText(QString::number(affNbSelection[3]->text().toInt()+1));
}
currentPattern[cx][cy].clear();
tableauJeu[cx][cy]->setBrush(QBrush());

}
for(int x=0;x<TAILLE;x++)
{
for(int y=0;y<TAILLE;y++)
{
if(currentPattern[x][y]=="")
tableauJeu[x][y]->setBrush(QBrush());
}
}
calculLaser(0,depart,GD);
}
}
}
}
}
Expand Down Expand Up @@ -708,7 +908,7 @@ void MainWindow::on_sourisRelachee()
for(int y=0;y<TAILLE;y++)
indicDepart[y]->setBrush(QBrush(QPixmap(":/Images/depart.png").scaledToHeight(indicDepart[y]->rect().height())));
indicDepart[cx]->setBrush(QBrush(QPixmap(":/Images/fighter.png").scaledToHeight(indicDepart[cx]->rect().height())));
depart=cx;
departEditeur=cx;
}else{
currentSelectionEditeur=-1;
curseur->setBrush(QBrush(QPixmap(":/Images/curseurVert.png").scaledToHeight(curseur->rect().height())));
Expand Down Expand Up @@ -760,20 +960,15 @@ void MainWindow::on_sourisRelachee()
default:
break;
}
bool verifGagne=true;
for(int x=0;x<TAILLE;x++)
{
for(int y=0;y<TAILLE;y++)
{
if(pattern[x][y]!=currentPattern[x][y])
verifGagne=false;
if(currentPattern[x][y]=="")
tableauJeu[x][y]->setBrush(QBrush());
}
}
if(verifGagne)
{
sceneGagne->addItem(curseur);
jeu->setScene(sceneGagne);
}
calculLaser(0,depart,GD);
}
}
}
Expand Down Expand Up @@ -810,7 +1005,7 @@ void MainWindow::on_DialogAccepted(QString nom)
temp=temp.left(temp.length()-1);
query.bindValue(":grille"+QString::number(x),temp);
}
query.bindValue(":depart",depart);
query.bindValue(":depart",departEditeur);
if(query.exec()){
qDebug() << "Requete réussie";
} else qDebug() << "Echec de la requete";
Expand Down
12 changes: 10 additions & 2 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

#define TAILLE 8

enum{
GD,
DG,
HB,
BH
};

namespace Ui {
class MainWindow;
}
Expand All @@ -28,6 +35,7 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void calculLaser(short x,short y,short sens);

private slots:
void on_sourisBougee(QPoint position);
Expand All @@ -46,12 +54,12 @@ private slots:
QGraphicsRectItem *cadreJeu, *tableauJeu[TAILLE][TAILLE],*departJeu[TAILLE], *selectionJeu[4];
QString pattern[TAILLE][TAILLE],currentPattern[TAILLE][TAILLE];
QLabel *affNbSelection[4];
short currentSelectionJeu;
short currentSelectionJeu,depart;

//Editeur
QGraphicsRectItem *tableauEditeur[TAILLE][TAILLE], *indicDepart[TAILLE], *selectionEditeur[6], *btnSave, *btnMP;
QString base[TAILLE][TAILLE];
short currentSelectionEditeur,depart;
short currentSelectionEditeur,departEditeur;
QPen *pen;
DialogNomNiveau *dialNomNiv;

Expand Down

0 comments on commit 4babb15

Please sign in to comment.