diff --git a/applicationQT2048/CMakeLists.txt b/applicationQT2048/CMakeLists.txt index fff826072f3b52776badd7580a13b77efa0dde0b..2a14d4c3e060dd437a3e6a97bfb8a7a462656651 100644 --- a/applicationQT2048/CMakeLists.txt +++ b/applicationQT2048/CMakeLists.txt @@ -16,10 +16,11 @@ qt_add_qml_module(appapplicationQT2048 URI applicationQT2048 VERSION 1.0 QML_FILES - Main.qml - QML_FILES MonElement.qml + GamePage.qml + QML_FILES MenuPage.qml SOURCES gamemanager.h gamemanager.cpp SOURCES gamemanager.h gamemanager.cpp + QML_FILES Main.qml ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. diff --git a/applicationQT2048/GamePage.qml b/applicationQT2048/GamePage.qml new file mode 100644 index 0000000000000000000000000000000000000000..44a7b055ec3aef1a3e693162132a93bd421b67f8 --- /dev/null +++ b/applicationQT2048/GamePage.qml @@ -0,0 +1,228 @@ +import QtQuick +import QtQuick.Controls + +Rectangle { + width: 400 + height: 600 + color: "#FAF8EF" + + + Text { + + text: "Fusionnez les nombres pour atteindre 2048!" + font.bold: true + color:"grey" + anchors.horizontalCenter: parent.horizontalCenter + y:145 + } + + Rectangle{ + width:105;height:105 + color:"orange" + x:35 + y:10 + radius:4 + + Text { + + text:"2048" + color: "white" + font.bold: true + font.pixelSize: 30 + anchors.centerIn: parent + } + } + + Rectangle{ + + color:"grey" + width: 90; height: 90 + x:270 + y:10 + radius:5 + + Text{ + text: "MEILLEUR" + color:"lightgrey" + font.pixelSize: 14 + font.bold: true + anchors.horizontalCenter: parent.horizontalCenter + y:10 + + } + + Text{ + id: bestScore + text:"0" + color:"white" + font.bold: true + font.pixelSize: 25 + anchors.centerIn:parent + + + } + } + + Rectangle{ + + color:"grey" + width: 90; height: 90 + x:170 + y:10 + radius:5 + + Text{ + text: "SCORE" + color:"lightgrey" + font.pixelSize: 14 + font.bold: true + anchors.horizontalCenter: parent.horizontalCenter + y:10 + + } + + Text{ + id: score + text:"0" + color:"white" + font.bold: true + font.pixelSize: 25 + anchors.centerIn:parent + + + } + } + + Rectangle { + id: buttonNew + color:"#F65E3B" + width: 90; height: 30 + x:170 + y:105 + radius:5 + + Text{ + id: buttonLabel + anchors.centerIn: parent + text: "NOUVEAU " + color:"white" + font.bold: true + } + + MouseArea{ + id: buttonMouseArea + + anchors.fill: parent + onClicked: gameManager.restartGame() + } + } + + Rectangle { + id: undo + color: "#F65E3B" + width: 90; height: 30 + x:270 + y:105 + radius:5 + + + Text{ + + anchors.centerIn: parent + text: "ANNULER " + color:"white" + font.bold: true + } + + MouseArea{ + id: undoMouseArea + + anchors.fill: parent + onClicked: gameManager.undo() + } + } + + Rectangle{ + width:350; height:350 + anchors.horizontalCenter: parent.horizontalCenter + y:170 + color:"grey" + radius: 5 + + + Grid { + id: gameGrid + columns: 4 + rows: 4 + anchors.centerIn: parent + spacing: 8 + padding:8 + + + Repeater { + model: gameManager.gridValues + 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" + radius: 5 + Text { + text: modelData > 0 ? modelData : "" + anchors.centerIn: parent + font.bold: true + font.pixelSize: 30 + color: "grey" + } + } + } + } + } + + Rectangle { + id: menu + color:"#F65E3B" + width: 180; height: 30 + anchors.horizontalCenter: parent.horizontalCenter + y:540 + radius:5 + + Text{ + anchors.centerIn: parent + text: "MENU " + color:"white" + font.bold: true + } + + MouseArea{ + anchors.fill: parent + onClicked: stackView.push("MenuPage.qml") + } + } + + + Item{ + id: keyHandler + focus: true + + Keys.onPressed: { + if (event.key === Qt.Key_Left) gameManager.moveLeft(); + else if (event.key === Qt.Key_Right) gameManager.moveRight(); + else if (event.key === Qt.Key_Up) gameManager.moveUp(); + else if (event.key === Qt.Key_Down) gameManager.moveDown(); + } + } + + +} + + diff --git a/applicationQT2048/Main.qml b/applicationQT2048/Main.qml index 7b57da9b5b824f9659074a1f012df933eaf8b1a2..1a9bf686e14c525f5697a196f613ee1b9bda31df 100644 --- a/applicationQT2048/Main.qml +++ b/applicationQT2048/Main.qml @@ -1,208 +1,15 @@ -import QtQuick +import QtQuick 2.15 +import QtQuick.Controls 2.15 - -Window { +ApplicationWindow { visible: true width: 400 height: 600 title: qsTr("Application 2048") - Text { - - text: "Fusionnez les nombres pour atteindre 2048!" - font.bold: true - color:"grey" - anchors.horizontalCenter: parent.horizontalCenter - y:145 - } - - Rectangle{ - width:105;height:105 - color:"orange" - x:35 - y:10 - radius:4 - - Text { - - text:"2048" - color: "white" - font.bold: true - font.pixelSize: 30 - anchors.centerIn: parent - } - } - - Rectangle{ - - color:"grey" - width: 90; height: 90 - x:270 - y:10 - radius:5 - - Text{ - text: "MEILLEUR" - color:"lightgrey" - font.pixelSize: 14 - font.bold: true - anchors.horizontalCenter: parent.horizontalCenter - y:10 - - } - - Text{ - id: bestScore - text:"0" - color:"white" - font.bold: true - font.pixelSize: 25 - anchors.centerIn:parent - - - } - } - - Rectangle{ - - color:"grey" - width: 90; height: 90 - x:170 - y:10 - radius:5 - - Text{ - text: "SCORE" - color:"lightgrey" - font.pixelSize: 14 - font.bold: true - anchors.horizontalCenter: parent.horizontalCenter - y:10 - - } - - Text{ - id: score - text:"0" - color:"white" - font.bold: true - font.pixelSize: 25 - anchors.centerIn:parent - - - } - } - - Rectangle { - id: buttonNew - color:"#F65E3B" - width: 90; height: 30 - x:170 - y:105 - radius:5 - - Text{ - id: buttonLabel - anchors.centerIn: parent - text: "NOUVEAU " - color:"white" - font.bold: true - } - - MouseArea{ - id: buttonMouseArea - - anchors.fill: parent - onClicked: gameManager.restartGame() - } - } - - Rectangle { - id: undo - color: "#F65E3B" - width: 90; height: 30 - x:270 - y:105 - radius:5 - - - Text{ - - anchors.centerIn: parent - text: "ANNULER " - color:"white" - font.bold: true - } - - MouseArea{ - id: undoMouseArea - - anchors.fill: parent //anchor all sides of the mouse area to the rectangle's anchors - //onClicked handles valid mouse button clicks - onClicked: gameManager.undo() - } - } - - Rectangle{ - width:350; height:350 - anchors.horizontalCenter: parent.horizontalCenter - y:170 - color:"grey" - radius: 5 - - - Grid { - id: gameGrid - columns: 4 - rows: 4 - anchors.centerIn: parent - spacing: 8 - padding:8 - - - Repeater { - model: gameManager.gridValues - 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" - radius: 5 - Text { - text: modelData > 0 ? modelData : "" - anchors.centerIn: parent - font.bold: true - font.pixelSize: 30 - color: "grey" - } - } - } - } - } - - - Item{ - id: keyHandler - focus: true - - Keys.onPressed: { - if (event.key === Qt.Key_Left) gameManager.moveLeft(); - else if (event.key === Qt.Key_Right) gameManager.moveRight(); - else if (event.key === Qt.Key_Up) gameManager.moveUp(); - else if (event.key === Qt.Key_Down) gameManager.moveDown(); - } + StackView { + id: stackView + anchors.fill: parent + initialItem: "GamePage.qml" // Charge la page du jeu } - - } - - diff --git a/applicationQT2048/MenuPage.qml b/applicationQT2048/MenuPage.qml new file mode 100644 index 0000000000000000000000000000000000000000..dd718bd73ca87aacbffc5a58035cd5389761f5ee --- /dev/null +++ b/applicationQT2048/MenuPage.qml @@ -0,0 +1,94 @@ +import QtQuick +import QtQuick.Controls + +Rectangle { + width: 400 + height: 600 + color: "#FAF8EF" + Text{ + text: "Menu" + font.bold: true + color:"grey" + font.pixelSize: 40 + anchors.horizontalCenter: parent.horizontalCenter + y:70 + } + + + MenuBar{ + y:220 + anchors.horizontalCenter: parent.horizontalCenter + background: Rectangle { color: "#BBADA0"; radius: 5 } + + Menu{ + title:"police" + + MenuItem { + text: "Arial" + background: Rectangle { color: "black"; radius: 5 } // Fond et coins arrondis + + } + } + + } + + MenuBar{ + y:300 + anchors.horizontalCenter: parent.horizontalCenter + background: Rectangle { color: "#BBADA0"; radius: 5 } + + Menu{ + title:"couleurs du jeu" + } + + } + + + Rectangle { + color:"red" + width: 90; height: 30 + anchors.horizontalCenter: parent.horizontalCenter + y:150 + radius:5 + + MenuBar{ + + 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) + } + + } + } + } + + Rectangle { + + color:"blue" + width: 90; height: 30 + anchors.horizontalCenter: parent.horizontalCenter + y:510 + radius:5 + + Text{ + anchors.centerIn: parent + text: "Retour " + color:"white" + font.bold: true + } + + MouseArea{ + anchors.fill: parent + onClicked: stackView.pop() + } + } +} diff --git a/applicationQT2048/MonElement.qml b/applicationQT2048/MonElement.qml deleted file mode 100644 index 5560aee72760e390f8f001f3163d06bc2ed5d055..0000000000000000000000000000000000000000 --- a/applicationQT2048/MonElement.qml +++ /dev/null @@ -1,5 +0,0 @@ -import QtQuick - -Item { - -}