Select Git revision
GamePage.qml
GamePage.qml 4.77 KiB
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();
}
}
}