/
Kotopeska
/
RiseUpGame
Обзор
Документация
Войти
/
Kotopeska
/
RiseUpGame
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
model/GameModel.h
85 строк
2 KB
Kotopeska
init
10 май 2025, 17:31
10 май 2025, 17:31
dd8efb4
Код
Авторство
О чём код?
#ifndef GAME_MODEL_H #define GAME_MODEL_H #include <vector> #include <memory> #include <random> #include "Ball.h" #include "Obstacle.h" #include "Shield.h" #include "Background.h" #include "Subject.h" namespace Model { enum class GameState { MENU, PLAYING, GAME_OVER, ABOUT }; class GameModel : public Subject { private: GameState m_state; std::unique_ptr<Ball> m_ball; std::vector<Obstacle> m_obstacles; std::unique_ptr<Shield> m_shield; std::unique_ptr<Background> m_background; int m_score; int m_highScore; int m_frameCounter; int m_nextObstacleSpawn; static constexpr int MIN_OBSTACLE_INTERVAL = 60; static constexpr int MAX_OBSTACLE_INTERVAL = 120; static constexpr int OBSTACLE_INTERVAL_VARIATION = 30; int m_screenWidth; int m_screenHeight; float m_scrollSpeed; std::mt19937 m_rng; void spawnObstacle(); bool checkCollisions(); void updateScore(); void dumpGameState(); public: GameModel(int width, int height); ~GameModel(); void update(); void resetGame(); void resize(int width, int height); void handleKeyPress(int key); void handleMouseDown(int x, int y); void handleMouseUp(int x, int y); void handleMouseMove(int x, int y); void startGame(); void gameOver(); void showMenu(); void showAbout(); GameState getState() const { return m_state; } const Ball &getBall() const { return *m_ball; } const std::vector<Obstacle> &getObstacles() const { return m_obstacles; } const Shield &getShield() const { return *m_shield; } const Background &getBackground() const { return *m_background; } int getScore() const { return m_score; } int getHighScore() const { return m_highScore; } int getFrameCounter() const { return m_frameCounter; } int getScreenWidth() const { return m_screenWidth; } int getScreenHeight() const { return m_screenHeight; } }; } // namespace Model #endif // GAME_MODEL_H