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
| #include"fen_jeu.h"
fen_jeu::fen_jeu() : QWidget() { //constructeur
mot_secret = "MARRON"; //mot secret (fixé au départ)
setWindowIcon(QIcon("Corde.gif"));
setStyleSheet("background-color: white;");
nbre_vies = "6";
vies = nbre_vies.toInt();//convertion de QString en int
image = new QLabel;
image->setPixmap(QPixmap("pendu" +nbre_vies+".jpg"));//l'image variera avec nbre_vies
mot_affiche = "";
for (int i = 0; i<mot_secret.size(); i++){
mot_affiche += "*"; //hello
}
mot = new QLabel(mot_affiche);//le mot que voit l'utilisateur...
QColor couleur;
couleur.setRgb(255,0,0);
mot->setPalette(QPalette(couleur));
mot->setFont(QFont("Purisa", 30));
texte = new QLabel("il vous reste " + nbre_vies + " vies,\ntrouvez le mot suivant:");
texte->setPalette(QPalette(couleur));
texte->setFont(QFont("Purisa", 18));
A = new QPushButton("A");//le clavier virtuel...
A->setStyleSheet("background-color: red;");
B = new QPushButton("B");
B->setStyleSheet("background-color: red;");
C = new QPushButton("C");
C->setStyleSheet("background-color: red;");
D = new QPushButton("D");
D->setStyleSheet("background-color: red;");
E = new QPushButton("E");
E->setStyleSheet("background-color: red;");
F = new QPushButton("F");
F->setStyleSheet("background-color: red;");
G = new QPushButton("G");
G->setStyleSheet("background-color: red;");
H = new QPushButton("H");
H->setStyleSheet("background-color: red;");
I = new QPushButton("I");
I->setStyleSheet("background-color: red;");
J = new QPushButton("J");
J->setStyleSheet("background-color: red;");
K = new QPushButton("K");
K->setStyleSheet("background-color: red;");
L = new QPushButton("L");
L->setStyleSheet("background-color: red;");
M = new QPushButton("M");
M->setStyleSheet("background-color: red;");
N = new QPushButton("N");
N->setStyleSheet("background-color: red;");
O = new QPushButton("O");
O->setStyleSheet("background-color: red;");
P = new QPushButton("P");
P->setStyleSheet("background-color: red;");
Q = new QPushButton("Q");
Q->setStyleSheet("background-color: red;");
R = new QPushButton("R");
R->setStyleSheet("background-color: red;");
S = new QPushButton("S");
S->setStyleSheet("background-color: red;");
T = new QPushButton("T");
T->setStyleSheet("background-color: red;");
U = new QPushButton("U");
U->setStyleSheet("background-color: red;");
V = new QPushButton("V");
V->setStyleSheet("background-color: red;");
W = new QPushButton("W");
W->setStyleSheet("background-color: red;");
X = new QPushButton("X");
X->setStyleSheet("background-color: red;");
Y = new QPushButton("Y");
Y->setStyleSheet("background-color: red;");
Z = new QPushButton("Z");
Z->setStyleSheet("background-color: red;");
QGridLayout* layout = new QGridLayout; //positionnement dans la fenêtre...
layout->addWidget(texte,0,0,3,8);
layout->addWidget(mot,3,0,3,8);
layout->addWidget(A,6,0);
layout->addWidget(B,6,1);
layout->addWidget(C,6,2);
layout->addWidget(D,6,3);
layout->addWidget(E,6,4);
layout->addWidget(F,6,5);
layout->addWidget(G,7,0);
layout->addWidget(H,7,1);
layout->addWidget(I,7,2);
layout->addWidget(J,7,3);
layout->addWidget(K,7,4);
layout->addWidget(L,7,5);
layout->addWidget(M,8,0);
layout->addWidget(N,8,1);
layout->addWidget(O,8,2);
layout->addWidget(P,8,3);
layout->addWidget(Q,8,4);
layout->addWidget(R,8,5);
layout->addWidget(S,9,0);
layout->addWidget(T,9,1);
layout->addWidget(U,9,2);
layout->addWidget(V,9,3);
layout->addWidget(W,9,4);
layout->addWidget(X,9,5);
layout->addWidget(Y,10,2);
layout->addWidget(Z,10,3);
layout->addWidget(image,0,8,16,8);
setLayout(layout);
QObject::connect(A, SLOT(clicked()), this,SIGNAL(analyseA()));//et la p*t**n de connexion
}
bool fen_jeu::test_victoire(){
bool victoire = false;
if(mot_secret.compare(mot_affiche)==0)//si le mot secret = la suite de lettres trouvées par l'utilisateur
victoire = true;//on gagne!
return victoire;
}
void fen_jeu::analyseA(){
A->setStyleSheet("background-color: green;");//ça c'est pour tester si le slot marche...
if (mot_secret.contains("A")){ //si le mot secret contient "A"
for(int i = 0; i<mot_secret.size();i++){
if((QString)mot_secret.at(i)=="A") //remplacer le "*" affiché
mot_affiche.replace(i, 1,"A"); //par la lettre du mot secret
}
}
else if (vies == 0 || this->test_victoire()){//si le joueur a perdu ou gagné,
this->close();//fermer la fenêtre(j'améliorerai ça plus tard...)
}
else{
vies--; //sinon, retirer une vie
}
} |
Partager