Qt Quick Ultralite swipe_game Demo

#ifndef GLOBALS_H
#define GLOBALS_H
/****************************************************************************** ** ** Copyright (C) 2021 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$ ** ******************************************************************************/
#include <qul/singleton.h> #include <qul/property.h> #include <platforminterface/screen.h> #include <string> #include <array> #include <random> #include <platforminterface/allocator.h> typedef std::basic_string<char, std::char_traits<char>, Qul::PlatformInterface::Allocator<char> > QulString; class Globals : public Qul::Singleton<Globals> { public: using distribution = std::uniform_int_distribution<std::mt19937::result_type>; enum GameMode { Numbers, Countries }; Globals(); Qul::Property<std::uint16_t> gameStartNumber; Qul::Property<std::uint16_t> gameCurrentNumber; Qul::Property<QulString> gameStartCountry; Qul::Property<QulString> gameCurrentCountry; Qul::Property<GameMode> currentGameMode; Qul::Property<std::uint16_t> score; Qul::Property<std::uint8_t> fails; // time in milliseconds Qul::Property<int> time; Qul::Property<std::uint16_t> tries; Qul::Property<bool> useSmallTouchAreas; Qul::Property<bool> showTouchAreas; Qul::Property<bool> useViewAnimations; void increaseTime(); void decreaseTime(); void increaseTries(); void decreaseTries(); void switchGameMode(); bool isNumberMode(); void requestNewValue(); void initGameData(); void checkAnswer(bool guessedGreater); void addFail(); private: int generateNewNumber(); std::mt19937 m_randGenerator; distribution m_newNumberDistribution; distribution m_startNumberDistribution; std::array<QulString, 56> m_countries; int m_startNumber{0}; int m_currentNumber{0}; }; #endif // GLOBALS_H