-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.qml
More file actions
executable file
·264 lines (216 loc) · 7.22 KB
/
main.qml
File metadata and controls
executable file
·264 lines (216 loc) · 7.22 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Dialogs 1.1
import QtQuick.Window 2.1
import CppToQml 2.0 // The Library I create in c++ codes // main.cpp
ApplicationWindow
{
id: mainWindow
visible: true
width: 550
height: 740
title: qsTr(" Project-2 2048 Game");
x: (Screen.width - width) / 2
y: (Screen.height - height) / 2
ExclusiveGroup { id: labelSettingsGroup }
ExclusiveGroup { id: languageSettingsGroup }
menuBar: MenuBar {
Menu { // Menu 1
title: qsTr("FILE")
MenuItem {
text: qsTr("New Game")
shortcut: "Ctrl+N"
onTriggered: {
game.startUpFunction()
origin.qmlShow();
origin.focus = true;
}
}
MenuItem {
text: qsTr("Exit")
shortcut: "Ctrl+Q"
onTriggered:{
game.finishGame()
}
}
MenuItem {
text: qsTr("Undo")
shortcut: "Ctrl+Z"
onTriggered: {
game.undo();
origin.qmlShow();
if(!game.GetStep) {
footer.marcheArriere = true;
}
}
}
}//Menu 1 Closed
Menu {// Menu 2
title: qsTr("LANGUAGE")
MenuItem {
text: "English"
checkable: true
exclusiveGroup: languageSettingsGroup
checked: settings.value("language") === "en_US" ? true : false
onTriggered: {
if (settings.value("language") !== "en_US") {
settings.setValue("language", "en_US");
game.restartGame()
}
}
}
MenuItem {
text: "简体中文"
checkable: true
exclusiveGroup: languageSettingsGroup
checked: settings.value("language") === "zh_TW" ? true : false
onTriggered: {
if (settings.value("language") !== "zh_TW") {
settings.setValue("language", "zh_TW");
game.restartGame()
}
}
}
MenuItem {
text: "Francais"
checkable: true
exclusiveGroup: languageSettingsGroup
checked: settings.value("language") === "fr_FR" ? true : false
onTriggered: {
if (settings.value("language") !== "fr_FR") {
settings.setValue("language", "fr_FR");
game.restartGame();
}
}
}
} // Menu 2 closed
Menu { //Menu 3
id: helpMenu
title: qsTr("CONTACT")
MenuItem {
text: qsTr("About Me")
onTriggered: aboutDialog.open();
}
} //Menu 3Closed
} //MenuBar CLosed
/**************************************************************************/
Item {
id: origin
property int casier
function qmlClear()
{
for(casier = 0 ; casier < 16; casier++)
{
myBoard.numInterieur.itemAt(casier).numero = "";
myBoard.numInterieur.itemAt(casier).color = "#cdc0b4";
myBoard.numInterieur.itemAt(casier).eNumColor= "black";
}
}
function qmlShow()
{
qmlClear();
for(casier = 0; casier < 16; casier++) {
if(game.showBoard(casier))
{
myBoard.numInterieur.itemAt(casier).numero = game.showBoard(casier);
myBoard.numInterieur.itemAt(casier).color = game.color(casier);
myBoard.numInterieur.itemAt(casier).eNumColor = game.numColor(casier);
}
}
infomation.myScore = game.getScore;
infomation.myStep = game.getStep;
infomation.myBestScore= game.getBestScore;
infomation.myTotalStep= game.getTotalStep;
if( game.getStep > 0)
{
footer.marcheArriere = true;
}
}
width: 550 ; height: 740
Keys.onPressed: {
switch(event.key) {
case Qt.Key_Up:
game.moveDir(GamePlay.Move_Up);
origin.qmlShow();
break;
case Qt.Key_Down:
game.moveDir(GamePlay.Move_Down);
origin.qmlShow();
break;
case Qt.Key_Left:
game.moveDir(GamePlay.Move_Left);
origin.qmlShow();
break;
case Qt.Key_Right:
game.moveDir(GamePlay.Move_Right);
origin.qmlShow();
break;
default:
break;
}
}
GamePlay { id: game }
Rectangle {
id: container
anchors.fill: parent
color: "#faf8ef" // the body color
Display { id: infomation }
BoardBody{
id: myBoard //panel
anchors.centerIn: parent
}
Foot {
id: footer
anchors.bottom: parent.bottom
onEStart: {
game.startUpFunction()
origin.qmlShow();
origin.focus = true;
footer.marcheArriere = true;
}
onEBack: {
game.undo();
origin.qmlShow();
if(!game.GetStep) {
footer.marcheArriere = true;
}
}
}
}
MessageDialog
{
id: aboutDialog
title: qsTr("About 2048-Qt")
text: qsTr("<p style='font-weight: bold; font-size: 24px'>2048-Qt</p><p>Version " + settings.getVersion() + "</p><p>F74027036 皮宜恩 <trens552@gmail.com></p>")
standardButtons: StandardButton.Ok
}
MessageDialog
{
id:gameOver
title: qsTr("Game Over")
text: qsTr("Game Over!")
standardButtons: StandardButton.Retry | StandardButton.Abort
onAccepted: {
game.startUpFunction();
}
onRejected: game.finishGame();
}
MessageDialog {
id: gamWin
title: qsTr("You Win")
text: qsTr("You win! do you want to Continue playing?")
standardButtons: StandardButton.Yes | StandardButton.No
onYes: {
game.addPoint = false;
close()
}
onNo: game.startUpFunction();
onRejected: {
MyScript.checkTargetFlag = false;
close()
}
}
FontLoader { id: localFont; source: "qrc:///fonts/DroidSansFallback.ttf" }
}
} // End Of ApplicationWindow