C

Qt Quick Ultralite loader Example

/****************************************************************************** ** ** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
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() } } }