From af675cf96d4d13b066a669eae847ad56485927d0 Mon Sep 17 00:00:00 2001 From: mae Date: Mon, 16 Aug 2010 10:11:20 +0200 Subject: Fix game could not be restarted Task-number: QT-3668 --- demos/declarative/snake/content/snake.js | 5 ++++- demos/declarative/snake/snake.qml | 16 +--------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/demos/declarative/snake/content/snake.js b/demos/declarative/snake/content/snake.js index 0f0dbf7..fab7834 100644 --- a/demos/declarative/snake/content/snake.js +++ b/demos/declarative/snake/content/snake.js @@ -35,9 +35,12 @@ function startNewGame() if (heartbeat.running) { endGame(); startNewGameTimer.running = true; + state = "starting"; return; } + state = "starting"; + numRows = numRowsAvailable; numColumns = numColumnsAvailable; board = new Array(numRows * numColumns); @@ -80,7 +83,6 @@ function startNewGame() waitForCookie = 5; score = 0; startHeartbeatTimer.running = true; - heartbeat.running = true; } function endGame() @@ -94,6 +96,7 @@ function endGame() } lastScore = score; highScores.saveScore(lastScore); + state = ""; } function move() { diff --git a/demos/declarative/snake/snake.qml b/demos/declarative/snake/snake.qml index b1344af..ed3bac9 100644 --- a/demos/declarative/snake/snake.qml +++ b/demos/declarative/snake/snake.qml @@ -94,6 +94,7 @@ Rectangle { Timer { id: startHeartbeatTimer; interval: 1000 ; + onTriggered: { state = "running"; heartbeat.running = true; } } @@ -208,21 +209,6 @@ Rectangle { Keys.onUpPressed: if (state == "starting" || direction != 2) Logic.scheduleDirection(0); Keys.onDownPressed: if (state == "starting" || direction != 0) Logic.scheduleDirection(2); - Connections { - target: startHeartbeatTimer - onRunningChanged: { - if (startHeartbeatTimer.running) - screen.state = "starting"; - else - screen.state = "running" - } - } - Connections { - target: heartbeat - onRunningChanged: if (!heartbeat.running) screen.state = ""; - } - - states: [ State { name: "starting" -- cgit v0.12