diff --git a/applicationQT2048/GamePage.qml b/applicationQT2048/GamePage.qml index eb6512dbde633ebda78353a2d2a1a197ddb76a5c..ebb7ca09555f9860c5b09869a7df41046a5c6de4 100644 --- a/applicationQT2048/GamePage.qml +++ b/applicationQT2048/GamePage.qml @@ -46,6 +46,7 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier text: "Fusionnez les nombres pour atteindre 2048!" font.bold: true + font.family: gameManager.police color:"grey" anchors.horizontalCenter: parent.horizontalCenter y:145 @@ -61,6 +62,7 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier Text { text:"2048" + font.family: gameManager.police color: "white" font.bold: true font.pixelSize: 30 @@ -78,6 +80,7 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier Text{ text: "MEILLEUR" + font.family: gameManager.police color:"lightgrey" font.pixelSize: 14 font.bold: true @@ -90,6 +93,7 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier id: bestScore text:gameManager.bestScore color:"white" + font.family: gameManager.police font.bold: true font.pixelSize: 25 anchors.centerIn:parent @@ -109,6 +113,7 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier Text{ text: "SCORE" color:"lightgrey" + font.family: gameManager.police font.pixelSize: 14 font.bold: true anchors.horizontalCenter: parent.horizontalCenter @@ -119,6 +124,7 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier Text{ id: score text:gameManager.score + font.family: gameManager.police color:"white" font.bold: true font.pixelSize: 25 @@ -142,6 +148,7 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier text: "NOUVEAU " color:"white" font.bold: true + font.family: gameManager.police } MouseArea{ @@ -167,6 +174,7 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier text: "ANNULER " color:"white" font.bold: true + font.family: gameManager.police } MouseArea{ @@ -199,22 +207,24 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier Rectangle { width: 78 height: 78 - color: modelData == 2 ? "#EEE4DA" : - modelData == 4 ? "#EDE0C8" : - modelData == 8 ? "#F2B179" : - modelData == 16 ? "#F59563" : - modelData == 32 ? "#F67C5F" : - modelData == 64 ? "#F65E3B" : - modelData == 128 ? "#EDCF72" : - modelData == 256 ? "#EDCC61" : - modelData == 512 ? "#EDC850" : - modelData == 1024 ? "#EDC53F" : - modelData == 2048 ? "#EDC22E" : "#BBADA0" + property var colors: gameManager.tileColorsMap + color: modelData == 2 ? colors["2"] : + modelData == 4 ? colors["4"] : + modelData == 8 ? colors["8"] : + modelData == 16 ? colors["16"] : + modelData == 32 ? colors["32"] : + modelData == 64 ? colors["64"] : + modelData == 128 ? colors["128"] : + modelData == 256 ? colors["256"] : + modelData == 512 ? colors["512"] : + modelData == 1024 ? colors["1024"] : + modelData == 2048 ? colors["2048"] : colors["autre"] radius: 5 Text { text: modelData > 0 ? modelData : "" anchors.centerIn: parent font.bold: true + font.family: gameManager.police font.pixelSize: 30 color: "grey" } @@ -236,6 +246,7 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier text: "MENU " color:"white" font.bold: true + font.family: gameManager.police } MouseArea{ diff --git a/applicationQT2048/Main.qml b/applicationQT2048/Main.qml index e00517ffa36af3da06835350b2ca1aa08124b2c5..b04fb17c185b30aa58fe5b03e6d2e6ee44041d1a 100644 --- a/applicationQT2048/Main.qml +++ b/applicationQT2048/Main.qml @@ -7,6 +7,10 @@ ApplicationWindow { height: 600 title: qsTr("Application 2048") + + + + StackView { id: stackView anchors.fill: parent diff --git a/applicationQT2048/MenuPage.qml b/applicationQT2048/MenuPage.qml index 3ac9b705f0c6e17a21bf7e3c5c3d37e1522fc32b..029718b5ab0dccf0940db12794a139163431c84e 100644 --- a/applicationQT2048/MenuPage.qml +++ b/applicationQT2048/MenuPage.qml @@ -7,6 +7,7 @@ Rectangle { color: "#FAF8EF" Text{ text: "Menu" + font.family: gameManager.police font.bold: true color:"grey" font.pixelSize: 40 @@ -16,6 +17,7 @@ Rectangle { Text{ text: "Design du jeu" + font.family: gameManager.police font.bold: true color:"grey" font.pixelSize: 25 @@ -35,9 +37,48 @@ Rectangle { MenuItem { text: "Arial" + font.family:"Arial" background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changePolice("Helvetica") + + } + + + MenuItem { + text: "Helvetica" + font.family:"Helvetica" + background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changePolice("Helvetica") + + } + + MenuItem { + text: "Times New Roman" + font.family: "Times New Roman" + background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changePolice("Times New Roman") + + } + MenuItem { + text: "Georgia" + font.family: "Georgia" + background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changePolice("Georgia") + + } + + MenuItem { + text: "Calibri" + font.family: "Calibri" + background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changePolice("Calibri") + + } + + + + - } } } @@ -49,12 +90,58 @@ Rectangle { Menu{ title:"couleurs du jeu" + font.family: gameManager.police + + MenuItem { + text: "Normal (Orange)" + font.family: gameManager.police + background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changerCouleur("normal") + + } + + MenuItem { + text: "Rouge/Rose" + font.family: gameManager.police + background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changerCouleur("rouge") + + } + MenuItem { + text: "Vert" + font.family: gameManager.police + background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changerCouleur("vert") + + } + MenuItem { + text: "Bleu" + font.family: gameManager.police + background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changerCouleur("bleu") + + } + MenuItem { + text: "Violet" + font.family: gameManager.police + background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changerCouleur("violet") + + } + MenuItem { + text: "Noir et Blanc" + font.family: gameManager.police + background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis + onTriggered: gameManager.changerCouleur("noirblanc") + + } } } Text{ text: "Fonctionnalitées" + font.family: gameManager.police font.bold: true color:"grey" font.pixelSize: 25 @@ -63,49 +150,30 @@ Rectangle { } - MenuBar { - anchors.horizontalCenter: parent.horizontalCenter - y:350 - background: Rectangle { color: "#BBADA0"; radius: 5 } - - Menu{ - title:"mode de jeu" - MenuItem { - text: "Grille 4x4" - background: Rectangle { color: "grey"; radius: 5 } // Fond et coins arrondis - onTriggered: gameManager.modeDeJeu(1) - } - - MenuItem { - text: "Grille 8x8" - background: Rectangle { color: "grey"; radius: 5 } - onTriggered: gameManager.modeDeJeu(2) - } - - } - } Text{ text: "accès à l'historique des parties" - + font.family: gameManager.police color:"grey" font.pixelSize: 20 anchors.horizontalCenter: parent.horizontalCenter - y:390 + y:350 } MenuBar{ anchors.horizontalCenter: parent.horizontalCenter - y:450 + y:410 background: Rectangle { color: "#BBADA0"; radius: 5 } Menu { title: "Charger une ancienne partie" + font.family: gameManager.police Repeater { model: gameManager.partieHistorique MenuItem { text: modelData + font.family: gameManager.police background: Rectangle { color: "grey"; radius: 5 } onTriggered: gameManager.chargerPartie(modelData) } @@ -119,12 +187,13 @@ Rectangle { color:"#BBADA0" width: 150; height: 30 anchors.horizontalCenter: parent.horizontalCenter - y:510 + y:470 radius:5 Text{ anchors.centerIn: parent text: "Supprimer l'historique" + font.family: gameManager.police color:"black" } @@ -140,12 +209,13 @@ Rectangle { color:"blue" width: 90; height: 30 anchors.horizontalCenter: parent.horizontalCenter - y:560 + y:550 radius:5 Text{ anchors.centerIn: parent text: "Retour " + font.family: gameManager.police color:"white" font.bold: true } diff --git a/applicationQT2048/PopupDialogue.qml b/applicationQT2048/PopupDialogue.qml index 6ccbcdfcd7deec9cd38f5aba891fa282d450d87b..f09f3398b7ac311de72eddea9b7f0116f3a4fb80 100644 --- a/applicationQT2048/PopupDialogue.qml +++ b/applicationQT2048/PopupDialogue.qml @@ -1,50 +1,93 @@ import QtQuick import QtQuick.Controls +import QtQuick.Layouts Popup { id: partieNameDialogue - width: 250 - height: 150 + width: 300 + height: 180 + x: (400 - 300) / 2 + y: (600 - 180) / 2 modal: true + focus: true closePolicy: Popup.CloseOnEscape onOpened: textInput.text = "" + background: Rectangle { + color: "#FAF8EF" + radius: 16 + border.color: "#BBADA0" + border.width: 2 + } - Column { - spacing: 10 - width: parent.width - padding: 10 + ColumnLayout { + spacing: 12 + anchors.fill: parent + anchors.margins: 16 Label { - text: "Pour enregistrer la partie précédente, entrez un nom pour la partie.\nSi vous ne souhaitez pas enregistrer, appuyez sur Annuler." + text: "Pour enregistrer la partie précédente,\nentrez un nom pour la partie. \nSi vous ne souhaitez pas enregistrer la pertie \nappuyez sur annuler." + font.family: gameManager.police wrapMode: Text.Wrap - width: parent.width + font.pixelSize: 14 + + color: "#776E65" + Layout.fillWidth: true } TextField { id: textInput - width: parent.width placeholderText: "Ex: Partie 1" + font.family: gameManager.police + font.pixelSize: 14 + color: "#776E65" + background: Rectangle { + radius: 8 + color: "white" + border.color: "#CCC0B3" + border.width: 1 + } + Layout.fillWidth: true } - Row { - spacing: 10 - width: parent.width + RowLayout { + spacing: 12 + Layout.alignment: Qt.AlignRight Button { - text: "OK" + text: "Annuler" + font.family: gameManager.police + font.pixelSize: 14 + background: Rectangle { + radius: 8 + color: "#EEE4DA" + } onClicked: { - gameManager.restartGame(textInput.text); + gameManager.restartGame("false"); partieNameDialogue.close(); } } Button { - text: "Annuler" + text: "OK" + font.pixelSize: 14 + background: Rectangle { + radius: 8 + color: "#8F7A66" + } + contentItem: Text { + text: qsTr("OK") + font.family: gameManager.police + color: "white" + font.pixelSize: 14 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } onClicked: { - gameManager.restartGame("false"); + gameManager.restartGame(textInput.text); partieNameDialogue.close(); } } } } } + diff --git a/applicationQT2048/gamemanager.cpp b/applicationQT2048/gamemanager.cpp index cb790fca5e2fdfcc9af78348cff1b523e2d22d84..42267eada51fec10be9175a77e6bad7deb85c611 100644 --- a/applicationQT2048/gamemanager.cpp +++ b/applicationQT2048/gamemanager.cpp @@ -5,6 +5,8 @@ GameManager::GameManager(QObject *parent) : QObject(parent), grid(4, std::vector<int>(4, 0)),m_score(0), m_gameOver(false) { chercherBestScore(); + emit colorsChanged(); + restartGame("false"); // intialisation d'une partie au démarrage } void GameManager::moveLeft() { @@ -556,4 +558,105 @@ void GameManager::endGame() { } +//Gestion des couleurs +void GameManager::changerCouleur(QString couleur){ + color = couleur; + emit colorsChanged(); +} + +QVariantMap GameManager::getTileColorsMap() { + QVariantMap colorMap; + + if (color == "bleu") { + colorMap["2"] = "#E0F7FA"; + colorMap["4"] = "#B2EBF2"; + colorMap["8"] = "#81D4FA"; + colorMap["16"] = "#4FC3F7"; + colorMap["32"] = "#29B6F6"; + colorMap["64"] = "#03A9F4"; + colorMap["128"] = "#039BE5"; + colorMap["256"] = "#0288D1"; + colorMap["512"] = "#0277BD"; + colorMap["1024"] = "#01579B"; + colorMap["2048"] = "#003F72"; + colorMap["autre"] = "#BBADA0"; + } else if (color == "vert") { + colorMap["2"] = "#E8F5E9"; + colorMap["4"] = "#C8E6C9"; + colorMap["8"] = "#A5D6A7"; + colorMap["16"] = "#81C784"; + colorMap["32"] = "#66BB6A"; + colorMap["64"] = "#4CAF50"; + colorMap["128"] = "#43A047"; + colorMap["256"] = "#388E3C"; + colorMap["512"] = "#2E7D32"; + colorMap["1024"] = "#1B5E20"; + colorMap["2048"] = "#103914"; + colorMap["autre"] = "#BBADA0"; + } else if (color == "rouge") { + colorMap["2"] = "#FFEBEE"; + colorMap["4"] = "#FFCDD2"; + colorMap["8"] = "#EF9A9A"; + colorMap["16"] = "#E57373"; + colorMap["32"] = "#EF5350"; + colorMap["64"] = "#F44336"; + colorMap["128"] = "#E53935"; + colorMap["256"] = "#D32F2F"; + colorMap["512"] = "#C62828"; + colorMap["1024"] = "#B71C1C"; + colorMap["2048"] = "#8E1313"; + colorMap["autre"] = "#BBADA0"; + } else if (color == "violet") { + colorMap["2"] = "#F3E5F5"; + colorMap["4"] = "#E1BEE7"; + colorMap["8"] = "#CE93D8"; + colorMap["16"] = "#BA68C8"; + colorMap["32"] = "#AB47BC"; + colorMap["64"] = "#9C27B0"; + colorMap["128"] = "#8E24AA"; + colorMap["256"] = "#7B1FA2"; + colorMap["512"] = "#6A1B9A"; + colorMap["1024"] = "#4A148C"; + colorMap["2048"] = "#320963"; + colorMap["autre"] = "#BBADA0"; + } else if (color == "noirblanc") { + colorMap["2"] = "#FFFFFF"; + colorMap["4"] = "#F0F0F0"; + colorMap["8"] = "#D9D9D9"; + colorMap["16"] = "#BFBFBF"; + colorMap["32"] = "#A6A6A6"; + colorMap["64"] = "#8C8C8C"; + colorMap["128"] = "#737373"; + colorMap["256"] = "#595959"; + colorMap["512"] = "#404040"; + colorMap["1024"] = "#262626"; + colorMap["2048"] = "#0D0D0D"; + colorMap["autre"] = "#BBADA0"; + } else { // thème "normal" ou inconnu + colorMap["2"] = "#EEE4DA"; + colorMap["4"] = "#EDE0C8"; + colorMap["8"] = "#F2B179"; + colorMap["16"] = "#F59563"; + colorMap["32"] = "#F67C5F"; + colorMap["64"] = "#F65E3B"; + colorMap["128"] = "#EDCF72"; + colorMap["256"] = "#EDCC61"; + colorMap["512"] = "#EDC850"; + colorMap["1024"] = "#EDC53F"; + colorMap["2048"] = "#EDC22E"; + colorMap["autre"] = "#BBADA0"; + } + + return colorMap; +} +// Changement de police + +QString GameManager::getPolice(){ + return police; +} + +void GameManager::changePolice(QString font){ + police = font; + emit policeChanged(); +} diff --git a/applicationQT2048/gamemanager.h b/applicationQT2048/gamemanager.h index ae284e7bdae652d7faa1304a699c0531e6e84f54..16f43cef1266f579bd04a7aeca9e39500bb888bb 100644 --- a/applicationQT2048/gamemanager.h +++ b/applicationQT2048/gamemanager.h @@ -18,7 +18,8 @@ class GameManager : public QObject Q_PROPERTY(QStringList partieHistorique READ getPartieHistorique NOTIFY historiqueChanged) Q_PROPERTY(int score READ getScore NOTIFY scoreChanged) Q_PROPERTY(int bestScore READ getBestScore NOTIFY bestScoreChanged) - + Q_PROPERTY(QVariantMap tileColorsMap READ getTileColorsMap NOTIFY colorsChanged) + Q_PROPERTY(QString police READ getPolice NOTIFY policeChanged) public: explicit GameManager(QObject *parent = nullptr); Q_INVOKABLE void moveLeft(); @@ -29,6 +30,9 @@ public: Q_INVOKABLE void undo(); Q_INVOKABLE void chargerPartie(QString partieName); Q_INVOKABLE void supprimerHistorique(); + Q_INVOKABLE void changerCouleur(QString couleur); + Q_INVOKABLE void changePolice(QString font); + QVariantMap getTileColorsMap(); bool isGameOver(); QVector<int> getGridValues() const; @@ -40,10 +44,8 @@ private: QJsonArray historyArray; int m_score; int m_bestScore; - - QMap<int, QColor> tileColors; // Dictionnaire des couleurs (couleurs sélécctionées initaliser a normal) - - Q_INVOKABLE void initializeTileColors(); // Initialisation des QMap pour les différents jeux de couleurs et intialisation aux couleur normal + QString color = "normal" ; + QString police = "Arial"; Q_INVOKABLE void addRandomElement(); @@ -54,6 +56,7 @@ private: Q_INVOKABLE int getScore() ; Q_INVOKABLE int getBestScore() ; Q_INVOKABLE void chercherBestScore() ; + Q_INVOKABLE QString getPolice(); QJsonArray gridToJsonArray(); @@ -67,6 +70,8 @@ signals: void historiqueChanged(); void scoreChanged(); void bestScoreChanged(); + void colorsChanged(); + void policeChanged(); };