diff --git a/applicationQT2048/CMakeLists.txt b/applicationQT2048/CMakeLists.txt index 9c7e2ffa9838a8ee4f4e22ee64170800edf63be5..fff826072f3b52776badd7580a13b77efa0dde0b 100644 --- a/applicationQT2048/CMakeLists.txt +++ b/applicationQT2048/CMakeLists.txt @@ -17,6 +17,9 @@ qt_add_qml_module(appapplicationQT2048 VERSION 1.0 QML_FILES Main.qml + QML_FILES MonElement.qml + SOURCES gamemanager.h gamemanager.cpp + SOURCES gamemanager.h gamemanager.cpp ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. diff --git a/applicationQT2048/Main.qml b/applicationQT2048/Main.qml index 41424f88973df650d0672dfdc62f670e86708de2..ef208182373598b2310924eac37e4c661364f755 100644 --- a/applicationQT2048/Main.qml +++ b/applicationQT2048/Main.qml @@ -1,8 +1,139 @@ import QtQuick + Window { - width: 640 - height: 480 visible: true - title: qsTr("Hello World") + width: 400 + height: 500 + title: qsTr("Application 2048") + + Rectangle{ + width:150;height:150 + color:"orange" + x:25 + y:10 + } + + Rectangle{ + + color:"black" + width: 90; height: 50 + x:270 + y:10 + radius:10 + + Text{ + text: "meilleur score" + color:"white" + anchors.horizontalCenter: parent.horizontalCenter + y:5 + + } + + Text{ + id: bestScore + text:"0" + color:"white" + font.bold: true + font.pixelSize: 20 + anchors.horizontalCenter: parent.horizontalCenter + y:20 + + } + } + + Rectangle { + id: buttonNew + color:"#F65E3B" + width: 90; height: 40 + x:160 + y:65 + radius:10 + + Text{ + id: buttonLabel + anchors.centerIn: parent + text: "NOUVEAU " + color:"white" + font.bold: true + } + + MouseArea{ + id: buttonMouseArea + + anchors.fill: parent //anchor all sides of the mouse area to the rectangle's anchors + //onClicked handles valid mouse button clicks + onClicked: gameManager.restartGame() + } + } + + Rectangle { + id: undo + color: "#F65E3B" + width: 90; height: 40 + x:270 + y:65 + radius:10 + + + 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:120 + color:"brown" + radius: 10 + + + Grid { + id: gameGrid + columns: 4 + rows: 4 + anchors.centerIn: parent + spacing: 5 + + + Repeater { + model: 16 + Rectangle { + width: 80 + height: 80 + color: "lightgrey" + border.color: "black" + radius:10 + Text { + anchors.centerIn: parent + text: "" + } + } + } + } + } + + + + 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/MonElement.qml b/applicationQT2048/MonElement.qml new file mode 100644 index 0000000000000000000000000000000000000000..5560aee72760e390f8f001f3163d06bc2ed5d055 --- /dev/null +++ b/applicationQT2048/MonElement.qml @@ -0,0 +1,5 @@ +import QtQuick + +Item { + +} diff --git a/applicationQT2048/gamemanager.cpp b/applicationQT2048/gamemanager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f58a0d569d5401545b32f5409473b0094c8d6602 --- /dev/null +++ b/applicationQT2048/gamemanager.cpp @@ -0,0 +1,36 @@ +#include "gamemanager.h" + +GameManager::GameManager(QObject *parent) : QObject(parent), grid(4, std::vector<int>(4, 0)) { + generateTile(); + generateTile(); +} + +void GameManager::moveLeft() { + // Implémentation du mouvement vers la gauche +} + +void GameManager::moveRight() { + // Implémentation du mouvement vers la droite +} + +void GameManager::moveUp() { + // Implémentation du mouvement vers le haut +} + +void GameManager::moveDown() { + // Implémentation du mouvement vers le bas +} + +void GameManager::restartGame() { + grid.assign(4, std::vector<int>(4, 0)); + generateTile(); + generateTile(); +} + +void GameManager::generateTile() { + // Implémentation de la génération de tuiles +} + +void GameManager::mergeTiles() { + // Implémentation de la fusion des tuiles +} diff --git a/applicationQT2048/gamemanager.h b/applicationQT2048/gamemanager.h new file mode 100644 index 0000000000000000000000000000000000000000..d0dbbdc0c9edb82829412cbc68749febb1962c4b --- /dev/null +++ b/applicationQT2048/gamemanager.h @@ -0,0 +1,26 @@ +#ifndef GAMEMANAGER_H +#define GAMEMANAGER_H + +#include <QObject> +#include <vector> + +class GameManager : public QObject +{ + Q_OBJECT +public: + explicit GameManager(QObject *parent = nullptr); + Q_INVOKABLE void moveLeft(); + Q_INVOKABLE void moveRight(); + Q_INVOKABLE void moveUp(); + Q_INVOKABLE void moveDown(); + Q_INVOKABLE void restartGame(); + +private: + std::vector<std::vector<int>> grid; + void generateTile(); + void mergeTiles(); + + +}; + +#endif // GAMEMANAGER_H