1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 import "content" as Content
44 import "content/snake.js" as Logic
48 SystemPalette { id: activePalette }
49 color: activePalette.window
50 property bool activeGame: false
52 property int gridSize : 34
53 property int margin: 4
54 property int numRowsAvailable: Math.floor((height-32-2*margin)/gridSize)
55 property int numColumnsAvailable: Math.floor((width-2*margin)/gridSize)
57 property int lastScore : 0
59 property int score: 0;
60 property int heartbeatInterval: 200
61 property int halfbeatInterval: 160
66 property int direction
67 property int headDirection
69 property variant head;
71 Content.HighScoreModel {
78 interval: heartbeatInterval;
81 onTriggered: { Logic.move() }
85 interval: halfbeatInterval;
87 running: heartbeat.running
88 onTriggered: { Logic.moveSkull() }
91 id: startNewGameTimer;
93 onTriggered: { Logic.startNewGame(); }
97 id: startHeartbeatTimer;
99 onTriggered: { state = "running"; activeGame = true; }
105 source: "content/pics/pause.png"
106 anchors.centerIn: parent;
107 //opacity is deliberately not animated
108 opacity: 0 //Was !Qt.application.active && activeGame, but application doesn't work (QTBUG-23331)
115 source: "content/pics/snake.jpg"
116 fillMode: Image.PreserveAspectCrop
118 anchors.horizontalCenter: parent.horizontalCenter
119 anchors.verticalCenter: parent.verticalCenter
123 anchors.verticalCenter: parent.verticalCenter;
124 anchors.left: parent.left;
125 anchors.right: parent.right;
133 anchors.horizontalCenter: parent.horizontalCenter;
139 anchors.horizontalCenter: parent.horizontalCenter;
140 //horizontalAlignment: Text.AlignHCenter
141 text: "Last Score:\t" + lastScore + "\nHighscore:\t" + highScores.topScore;
146 source: "content/pics/background.png"
147 fillMode: Image.PreserveAspectCrop
149 anchors.left: parent.left
150 anchors.right: parent.right
151 anchors.top: parent.top
152 anchors.bottom: toolbar.top
157 border.color: "white"
159 anchors.horizontalCenter: parent.horizontalCenter
160 y: (screen.height - 32 - height)/2;
161 width: numColumnsAvailable * gridSize + 2*margin
162 height: numRowsAvailable * gridSize + 2*margin
172 if (screen.state == "") {
173 Logic.startNewGame();
176 if (direction == 0 || direction == 2)
177 Logic.scheduleDirection((mouseX > (head.x + head.width/2)) ? 1 : 3);
179 Logic.scheduleDirection((mouseY > (head.y + head.height/2)) ? 2 : 0);
189 Behavior on opacity { NumberAnimation { duration: 200 } }
192 border.color: "#221edd"
197 anchors.horizontalCenter: parent.horizontalCenter
198 anchors.verticalCenter: parent.verticalCenter
199 anchors.verticalCenterOffset: 40
202 id: progressIndicator
211 color: activePalette.window
212 height: 32; width: parent.width
213 anchors.bottom: screen.bottom
216 id: btnA; text: "New Game"; onClicked: Logic.startNewGame();
217 anchors.left: parent.left; anchors.leftMargin: 3
218 anchors.verticalCenter: parent.verticalCenter
223 anchors { left: btnA.right; leftMargin: 3; verticalCenter: parent.verticalCenter }
224 onClicked: Qt.quit();
228 color: activePalette.text
229 text: "Score: " + score; font.bold: true
230 anchors.right: parent.right; anchors.rightMargin: 3
231 anchors.verticalCenter: parent.verticalCenter
236 Keys.onSpacePressed: Logic.startNewGame();
237 Keys.onLeftPressed: if (state == "starting" || direction != 1) Logic.scheduleDirection(3);
238 Keys.onRightPressed: if (state == "starting" || direction != 3) Logic.scheduleDirection(1);
239 Keys.onUpPressed: if (state == "starting" || direction != 2) Logic.scheduleDirection(0);
240 Keys.onDownPressed: if (state == "starting" || direction != 0) Logic.scheduleDirection(2);
245 PropertyChanges {target: progressIndicator; width: 200}
246 PropertyChanges {target: title; opacity: 0}
247 PropertyChanges {target: progressBar; opacity: 1}
251 PropertyChanges {target: progressIndicator; width: 200}
252 PropertyChanges {target: title; opacity: 0}
253 PropertyChanges {target: skull; row: 0; column: 0; }
254 PropertyChanges {target: skull; spawned: 1}
262 NumberAnimation { target: progressIndicator; property: "width"; duration: 1000 }
263 NumberAnimation { property: "opacity"; duration: 200 }
267 NumberAnimation { target: progressIndicator; property: "width"; duration: 1000 }
268 NumberAnimation { property: "opacity"; duration: 200 }