refactored to multiple games implementation
This commit is contained in:
82
lib/game.h
Normal file
82
lib/game.h
Normal file
@@ -0,0 +1,82 @@
|
||||
// ============================================================================
|
||||
// ABSTRACT GAME BASE CLASS
|
||||
// ============================================================================
|
||||
// Defines the interface all games must implement
|
||||
// Provides polymorphic game architecture for modular design
|
||||
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "input_event.h"
|
||||
#include "display/low_level_render.h"
|
||||
#include "display/low_level_gui.h"
|
||||
|
||||
/**
|
||||
* @brief Abstract base class for all games
|
||||
*
|
||||
* Games inherit from this class and implement the three core methods:
|
||||
* - init(): Set up initial game state
|
||||
* - update(): Process input events and update game logic
|
||||
* - draw(): Render the game to the display buffer
|
||||
*
|
||||
* The main loop in basic1.cpp calls these methods polymorphically,
|
||||
* allowing different games to run with the same infrastructure.
|
||||
*/
|
||||
class Game {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Game
|
||||
* @param width Display width in pixels
|
||||
* @param height Display height in pixels
|
||||
* @param renderer Pointer to low-level rendering interface
|
||||
* @param gui Pointer to GUI drawing primitives
|
||||
*/
|
||||
Game(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui)
|
||||
: width(width), height(height), renderer(renderer), gui(gui) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Virtual destructor for proper cleanup of derived classes
|
||||
*/
|
||||
virtual ~Game() {}
|
||||
|
||||
/**
|
||||
* @brief Initialize game state
|
||||
*
|
||||
* Called once when the game starts. Set up initial values,
|
||||
* reset statistics, prepare the game board, etc.
|
||||
*/
|
||||
virtual void init() = 0;
|
||||
|
||||
/**
|
||||
* @brief Update game state based on input event
|
||||
*
|
||||
* Process the input event and update game logic accordingly.
|
||||
* This is where game rules, win conditions, state transitions happen.
|
||||
*
|
||||
* @param event Input event from InputManager
|
||||
* @return true if screen redraw is needed, false otherwise
|
||||
*/
|
||||
virtual bool update(const InputEvent& event) = 0;
|
||||
|
||||
/**
|
||||
* @brief Draw the game to the display buffer
|
||||
*
|
||||
* Render all game graphics using the renderer and gui objects.
|
||||
* This is called after update() returns true.
|
||||
* The actual screen refresh happens in the main loop on Core 1.
|
||||
*/
|
||||
virtual void draw() = 0;
|
||||
|
||||
protected:
|
||||
// Display dimensions
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
|
||||
// Rendering interfaces (provided by basic1.cpp)
|
||||
LowLevelRenderer* renderer;
|
||||
LowLevelGUI* gui;
|
||||
};
|
||||
|
||||
#endif // GAME_H
|
||||
Reference in New Issue
Block a user