-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEndOfGameDialog.qml
169 lines (155 loc) · 6.09 KB
/
EndOfGameDialog.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
166
167
168
169
import QtQuick 2.9
import QtQuick.Controls 2.5
import QtQuick.Window 2.3
import QtQuick.Dialogs 1.2
Dialog {
id: endOfGame
title: persian.checked ? "پایان بازی" : "End of Game"
height: parent.height * 0.17
width: parent.width * 0.3
//-------------------------- an alert for canceling game
Dialog {
id: cancelAlert
title: persian.checked ? "آیا مطمعنید؟" : "Are you sure?"
Text {
id: alertCancelText
text: persian.checked ? "همه ی اطلاعات بازی حذف خواهند شد" : "All of game data will be lost"
}
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: {
mystack.pop()
bknd.endGame()
endOfGame.close()
window.width = Screen.width * 0.5
window.height = Screen.height * 0.75
}
onRejected: cancelAlert.close()
}
//------------------------- an alert for restaring game
Dialog {
id: restartAlert
title: persian.checked ? "آیا مطمعنید؟" : "Are you sure?"
Text {
id: alertRestartText
text: persian.checked ? "اطلاعات بازی حذف خواهند شد" : "Game data will be lost"
}
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: {
bknd.restartGame()
mystack.replace("GamePage.qml")
}
onRejected: restartAlert.close()
}
contentItem: Rectangle {
border.color: "#7c6d43"
anchors.fill: parent
//BackGround
Image {
id: name
source: "qrc:/Assets/Images/Wood2.jpg"
width: parent.width - 2
height: parent.height - 2
anchors.centerIn: parent
}
Rectangle {
width: parent.width * 0.6
height: parent.height * 0.35
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: parent.height * 0.07
border.color: "#7c6d43"
color: "#00000000"
Text {
id: endGameText
text: ""
color: "white"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
height: parent.height - 2
width: parent.width - 2
textFormat: Text.StyledText
fontSizeMode: Text.Fit
minimumPixelSize: 3
font.pixelSize: 25
Component.onCompleted: {
//------------------------------------------------------------------ title
switch (bknd.gameStatus()) {
case 2:
endOfGame.title = persian.checked ? "پات" : "Stalemate"
break
case 3:
endOfGame.title = persian.checked ? "کیش و مات" : "Checkmate"
break
}
//------------------------------------------------------------------ text
// winner : user 1
if (bknd.winner() === 0)
this.text = persian.checked ? "برنده: " + bknd.getP1Name(
) : "Winner: " + bknd.getP1Name()
// winner : user 2
else if (bknd.winner() === 1)
this.text = persian.checked ? "برنده: " + bknd.getP2Name(
) : "Winner: " + bknd.getP2Name()
// draw
else if (bknd.getCanceler() === 2 && bknd.winner() === 2)
this.text = persian.checked ? "مساوی" : "Draw"
}
Connections {
target: bknd
onCancel: {
endOfGame.title = persian.checked ? "تسلیم" : "Surrend"
// winner : user 1
if (bknd.getCanceler() === 1)
endGameText.text
= persian.checked ? "برنده: " + bknd.getP1Name(
) : "Winner: " + bknd.getP1Name()
// winner : user 2
else if (bknd.getCanceler() === 0)
endGameText.text
= persian.checked ? "برنده: " + bknd.getP2Name(
) : "Winner: " + bknd.getP2Name()
}
}
}
}
Row {
anchors.bottom: parent.bottom
anchors.bottomMargin: parent.height * 0.07
anchors.horizontalCenter: parent.horizontalCenter
spacing: this.width * 0.03
width: parent.width * 0.9
height: parent.height * 0.4
Button {
id: dialogUndoButton
text: persian.checked ? "بازگشت" : "Undo"
width: parent.width * 0.3
height: parent.height
font.pixelSize: this.width * 0.1
onClicked: {
bknd.undo()
mystack.replace("GamePage.qml")
}
}
Button {
id: dialogEndGameButton
text: persian.checked ? "اتمام بازی" : "End game"
width: parent.width * 0.3
height: parent.height
font.pixelSize: this.width * 0.1
onClicked: {
cancelAlert.open()
}
}
Button {
id: dialogRestartButton
text: persian.checked ? "شروع مجدد" : "Restart"
width: parent.width * 0.3
height: parent.height
font.pixelSize: this.width * 0.1
onClicked: {
restartAlert.open()
}
}
}
}
}