Skip to content
Snippets Groups Projects
Select Git revision
  • f8ad2a730e3731249a0ca258b501d8334a387b2c
  • main default protected
2 results

Main.qml

Blame
  • Main.qml 2.98 KiB
    import QtQuick
    
    
    Window {
        visible: true
        width: 400
        height: 500
        title: qsTr("Application 2048")
    
        Rectangle{
            width:100;height:100
            color:"orange"
            x:25
            y:10
            radius:10
    
            Text {
    
                    text:"2048"
                    color: "white"
    
                    anchors.centerIn: parent
                }
        }
    
        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();
        }
    }