From c615c53525ba3f8d1b039e566af9a53037c3af99 Mon Sep 17 00:00:00 2001
From: jbreitwi <josephine.breitwiller@etu.ec-lyon.fr>
Date: Mon, 17 Mar 2025 10:57:31 +0100
Subject: [PATCH] =?UTF-8?q?arriv=C3=A9e=20de=20sara?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 applicationQT2048/CMakeLists.txt  |   3 +
 applicationQT2048/Main.qml        | 137 +++++++++++++++++++++++++++++-
 applicationQT2048/MonElement.qml  |   5 ++
 applicationQT2048/gamemanager.cpp |  36 ++++++++
 applicationQT2048/gamemanager.h   |  26 ++++++
 5 files changed, 204 insertions(+), 3 deletions(-)
 create mode 100644 applicationQT2048/MonElement.qml
 create mode 100644 applicationQT2048/gamemanager.cpp
 create mode 100644 applicationQT2048/gamemanager.h

diff --git a/applicationQT2048/CMakeLists.txt b/applicationQT2048/CMakeLists.txt
index 9c7e2ff..fff8260 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 41424f8..ef20818 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 0000000..5560aee
--- /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 0000000..f58a0d5
--- /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 0000000..d0dbbdc
--- /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
-- 
GitLab