-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtile.cpp
99 lines (89 loc) · 2.51 KB
/
qtile.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
#include "qtile.h"
#include <QString>
#include <QDebug>
#include "game.h"
// Constructeur de Qtile
Qtile::Qtile(QObject *parent) : QObject(parent)
{
currentGame = new Game;
}
// Lancement d'une nouvelle partie
void Qtile::restartGame()
{
currentGame->restartGame();
gameIsWon = false;
gameIsOver = false;
emit ChangeWinStatus();
emit ChangeOverStatus();
}
// Renvoie le nombre contenu dans une case sous forme de QString pour l'affichage
QString Qtile::readValue(int index)
{
QString qValue = currentGame->getGameBoard()->getTileValue(index);
return (qValue);
}
// Renvoie la couleur à afficher dans une case selon la valeur qu'elle contient
QColor Qtile::readColor(int index)
{
int valueForColor = currentGame->getGameBoard()->getTileValueForColor(index);
QColor color;
switch(valueForColor)
{
case 0: color = "#ccc0b2"; break;
case 2: color = "#F4ECE4"; break;
case 4: color = "#ece0c8"; break;
case 8: color = "#f2b179"; break;
case 16: color = "#f59563"; break;
case 32: color = "#f57c5f"; break;
case 64: color = "#f95c3b"; break;
case 128: color = "#edce71"; break;
case 256: color = "#eecc61"; break;
case 512: color = "#ebc850"; break;
case 1024: color = "#edc53f"; break;
case 2048: color = "#eec22e"; break;
case 4096: color = "#3d3a33"; break;
case 8192: color = "#3d3a33"; break;
case 16384: color = "#3d3a33"; break;
default: color = "#ccc0b2"; break;
}
return color;
}
// Renvoie le score pour l'afficher
QString Qtile::getScore()
{
int gameScore = currentGame->getGameScore();
return (QString::number(gameScore));
}
// Effectue un mouvement de case selon la direction du mouvement
void Qtile::performMove(int direction)
{
if (direction == 1){
currentGame->move(UP);
}
if (direction == 2){
currentGame->move(DOWN);
}
if (direction == 3){
currentGame->move(LEFT);
}
if (direction == 4){
currentGame->move(RIGHT);
}
gameIsWon = currentGame->isGameWon();
if (gameIsWon) emit ChangeWinStatus();
gameIsOver = currentGame->isGameOver();
if (gameIsOver)
{
emit ChangeOverStatus();
}
}
// Renvoie la variable qui permet de savoir si le jeu est gagné (2048 est atteint)
bool Qtile::GameIsWon()
{
return gameIsWon;
}
// Renvoie la variable qui permet de savoir si le jeu est fini( plus de coups possibles)
bool Qtile::GameIsOver()
{
return gameIsOver;
}