-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
166 lines (163 loc) · 4.65 KB
/
main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Controls.Styles 1.4
import "logic.js" as Logic
Window {
visible: true
title: qsTr("15 Puzzle")
width: 600
height: 400
Rectangle{
id: win
width: parent.width
height: parent.height
visible: true
color: "powderblue"
}
Rectangle {
id: mainwin
width: parent.width - parent.width / 4
height: parent.height
border.width: 3
border.color: "grey"
color: "snow"
ListModel{
id: appModel
ListElement{txt: 1}
ListElement{txt: 2}
ListElement{txt: 3}
ListElement{txt: 4}
ListElement{txt: 5}
ListElement{txt: 6}
ListElement{txt: 7}
ListElement{txt: 8}
ListElement{txt: 9}
ListElement{txt: 10}
ListElement{txt: 11}
ListElement{txt: 12}
ListElement{txt: 13}
ListElement{txt: 14}
ListElement{txt: 15}
ListElement{txt: 0}
}
GridView {
id: gv
width: parent.width
height: parent.height
cellWidth: gv.width / 4
cellHeight: gv.height / 4
model: appModel
interactive: false
delegate :
Rectangle {
id: rect
height: gv.cellHeight - 3
width: gv.cellWidth - 3
color: "lightskyblue"
border.color: "cadetblue"
border.width: 2
radius: 10
Text {
id:txt1
text: txt
font.family: "Helvetica"
font.pixelSize: 25
anchors.centerIn: parent
}
visible: (txt1.text === "0") ? false : true
}
MouseArea {
visible: false
onClicked: {
Logic.swap(gv.indexAt(mouseX, mouseY))
}
id: gameArea
anchors.fill: parent
}
move: Transition {
NumberAnimation { duration: 200; properties: "x,y" }
}
}
}
Button {
id: newgame
anchors{left: mainwin.right; leftMargin: 20; top: mainwin.top; topMargin: 70;
right: win.right; rightMargin: 20;}
width: parent.width / 4
height: parent.height / 5
Text{
text: qsTr("New Game")
anchors.centerIn: parent
font.family: "Calibri"
font.bold: true
}
MouseArea {
onClicked: {
gameArea.visible = true;
appModel.clear();
Logic.shuffle();
}
anchors.fill: parent
}
}
Button {
id: quit
anchors{left: mainwin.right; leftMargin: 20; top: mainwin.top;
topMargin: 200; right: win.right; rightMargin: 20}
width: parent.width / 4
height: parent.height / 5
Text{
text: qsTr("Quit")
anchors.centerIn: parent
font.family: "Calibri"
font.bold: true
}
MouseArea {
onClicked: {
Qt.quit()
}
anchors.fill: parent
}
}
Dialog {
id: winner
visible: false
contentItem: Rectangle {
color: "lightseagreen"
implicitWidth: mainwin.width - 100
implicitHeight: mainwin.height / 4
border.color: "black"
Text {
id: dialogTxt
text: qsTr("You win!")
color: "mintcream"
font.bold: true
font.family: "Helvetica"
font.pixelSize: 30
anchors.centerIn: parent
}
Button{
id: newGame
text: qsTr("New Game")
anchors{top: dialogTxt.bottom;topMargin: 10; left: parent.left; leftMargin: 20}
height: parent.height / 5
onClicked: {
appModel.clear();
Logic.shuffle();
winner.close();
}
}
Button{
id: exit
text: qsTr("Exit")
anchors{top: dialogTxt.bottom; topMargin: 10; right: parent.right; rightMargin: 20}
height: parent.height / 5
onClicked: {
Qt.quit();
}
}
}
}
}