C
Qt Quick Ultralite loader Example
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
import QtQuick 2.15
pragma Singleton
QtObject {
property int bestScore: 0
property int streak: 0
property int score: 0
property ColorsQueue colorsQueue: ColorsQueue {}
property bool running: false
property bool takeInput: false
signal roundStarted
signal gameOver
function resetStreak() {
streak = 0
}
function prepareRound() {
colorsQueue.generateColors(streak + 1)
score = 0
takeInput = false
}
function selectColor(c : color) {
var expectedColor = colorsQueue.dequeue()
if (c == expectedColor) {
score++
} else {
takeInput = false
gameOver()
return
}
if (colorsQueue.isEmpty()) {
if (score > streak) {
streak = score
}
if (streak > bestScore) {
bestScore = streak
}
prepareRound()
roundStarted()
}
}
}