summaryrefslogtreecommitdiffstats
path: root/examples/declarative/minehunt/minehunt.qml
blob: 9454f2fce57cd7012be12b31ea0e7edff107cc17 (plain)
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
Item {
    id: field
    width: 370
    height: 480
    properties: Property {
        name: "clickx"
        type: "Int"
        value: 0
    }
    properties: Property {
        name: "clicky"
        type: "Int"
        value: 0
    }
    resources: [
        Component {
            id: tile
            Flipable {
                id: flipable
                width: 40
                height: 40
                transform: [
                    Axis {
                        id: axis
                        xStart: 20
                        xEnd: 20
                        yStart: 20
                        yEnd: 0
                    }
                ]
                front: Image {
                    src: "pics/front.png"
                    width: 40
                    height: 40
                    Image {
                        anchors.horizontalCenter: parent.horizontalCenter
                        anchors.verticalCenter: parent.verticalCenter
                        src: "pics/flag.png"
                        opacity: modelData.hasFlag
                        opacity: Behaviour {
                            NumericAnimation {
                                property: "opacity"
                                duration: 250
                            }
                        }
                    }
                }
                back: Image {
                    src: "pics/back.png"
                    width: 40
                    height: 40
                    Text {
                        anchors.horizontalCenter: parent.horizontalCenter
                        anchors.verticalCenter: parent.verticalCenter
                        text: modelData.hint
                        color: "white"
                        font.bold: true
                        opacity: modelData.hasMine == false && modelData.hint > 0
                    }
                    Image {
                        anchors.horizontalCenter: parent.horizontalCenter
                        anchors.verticalCenter: parent.verticalCenter
                        src: "pics/bomb.png"
                        opacity: modelData.hasMine
                    }
                    Explosion {
                        anchors.horizontalCenter: parent.horizontalCenter
                        anchors.verticalCenter: parent.verticalCenter
                        explode: modelData.hasMine==true && modelData.flipped==true
                    }
                }
                states: [
                    State {
                        name: "back"
                        when: modelData.flipped == true
                        SetProperty {
                            target: axis
                            property: "rotation"
                            value: 180
                        }
                    }
                ]
                transitions: [
                    Transition {
                        SequentialAnimation {
                            PauseAnimation {
                                duration: {
                                      var ret = Math.abs(flipable.parent.x-field.clickx) +
                                                Math.abs(flipable.parent.y-field.clicky);

                                      ret > 0
                                        ? (modelData.hasMine==true && modelData.flipped==true) ? ret * 3 : ret
                                        : 0
                                }
                            }
                            NumericAnimation {
                                easing: "easeInOutQuad"
                                properties: "rotation"
                            }
                        }
                    }
                ]
                MouseRegion {
                    anchors.fill: parent
                    onClicked: {
                        field.clickx = flipable.parent.x;
                        field.clicky = flipable.parent.y;
                        row = Math.floor(index/9);
                        col = index - (Math.floor(index/9) * 9);
                        if (mouseButton==undefined || mouseButton=='Right') {
                            flag(row, col);
                        } else{
                            flip(row, col);
                        }
                    }
                }
            }
        }
    ]
    Image {
        src: "pics/No-Ones-Laughing-3.jpg"
        tile: true
    }
    Description {
        text: "Use the 'minehunt' executable to run this demo!"
        width: 300
        opacity: tiles?0:1
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
    }
    Repeater {
        dataSource: tiles
        x: 1
        y: 1
        Component {
            ComponentInstance {
                component: tile
                x: (index - (Math.floor(index/9) * 9)) * 41
                y: Math.floor(index/9) * 41
            }
        }
    }
    Item {
        id: gamedata
        width: 370
        height: 100
        y: 380
        Text {
            color: "white"
            font.size: 18
            x: 20
            y: 20
        }
        Image {
            x: 100
            y: 20
            src: "pics/bomb-color.png"
        }
        Text {
            x: 100
            y: 60
            color: "white"
            text: numMines
        }
        Image {
            x: 140
            y: 20
            src: "pics/flag-color.png"
        }
        Text {
            x: 140
            y: 60
            color: "white"
            text: numFlags
        }
        Image {
            x: 240
            y: 0
            src: if(isPlaying==true){'pics/smile.png'}else{if(hasWon==true){'pics/glee.png'}else{'pics/frown.png'}}
            MouseRegion {
                anchors.fill: parent
                onClicked: { reset() }
            }
        }
    }
}