From 1ecfd365986ab88aa0331c7caf530e502526321d Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Thu, 12 Dec 2024 20:02:12 +0100 Subject: [PATCH] Restart the timer on game restar --- qml/Main.qml | 10 ++++++++-- qml/ScoreBar.qml | 7 ++++++- qml/WinOverlay.qml | 7 ++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/qml/Main.qml b/qml/Main.qml index 0442717..f89df78 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -53,7 +53,7 @@ ApplicationWindow { Timer { id: gameTimer interval: 1000 - running: true + running: GameState.gameWon === false repeat: true onTriggered: scoreBar.time += 1 } @@ -68,6 +68,8 @@ ApplicationWindow { anchors.top: parent.top anchors.left: parent.left anchors.right: parent.right + + onRestart: time = 0 } // Show the foundation piles, throwaway pile & the draw stack on the first row @@ -123,5 +125,9 @@ ApplicationWindow { cardHeight: app.cardHeight } - WinOverlay {} + WinOverlay { + onRestart: { + scoreBar.time = 0 + } + } } diff --git a/qml/ScoreBar.qml b/qml/ScoreBar.qml index cfbbfe5..3057d7e 100644 --- a/qml/ScoreBar.qml +++ b/qml/ScoreBar.qml @@ -10,10 +10,15 @@ Rectangle { property int time: 0 property int moves: 0 + signal restart + color: "lightgray" RoundButton { - onClicked: GameState.dealCards() + onClicked: { + GameState.dealCards() + scoreBarRoot.restart() + } anchors.left: parent.left anchors.leftMargin: parent.width * 0.02 diff --git a/qml/WinOverlay.qml b/qml/WinOverlay.qml index 30c964f..f80ee96 100644 --- a/qml/WinOverlay.qml +++ b/qml/WinOverlay.qml @@ -10,6 +10,8 @@ Rectangle { visible: GameState.gameWon === true anchors.fill: parent + signal restart + Text { id: winText @@ -23,7 +25,10 @@ Rectangle { Button { text: "Restart" - onClicked: GameState.dealCards() + onClicked: { + GameState.dealCards(); + winOverlay.restart(); + } anchors.top: winText.bottom anchors.horizontalCenter: parent.horizontalCenter }