// ============================================================================ // TIC-TAC-TOE GAME HEADER // ============================================================================ // Concrete implementation of the Game interface for Tic-Tac-Toe #ifndef TIC_TAC_TOE_H #define TIC_TAC_TOE_H #include "../lib/game.h" /** * @brief Tic-Tac-Toe game implementation * * Classic two-player Tic-Tac-Toe game with: * - Touch input: Tap cells to place pieces * - Button input: KEY0 moves selection, KEY1 places piece * - Win detection: Rows, columns, and diagonals * - Statistics tracking: Wins, ties, total moves * - Visual feedback: Selection highlight, turn indicator */ class TicTacToeGame : public Game { public: /** * @brief Construct a new Tic-Tac-Toe 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 * @param input_manager Pointer to input manager for capability queries */ TicTacToeGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager); /** * @brief Initialize game state (reset board, keep statistics) */ void init() override; /** * @brief Update game state based on input event * @param event Input event from InputManager * @return true if screen redraw is needed */ bool update(const InputEvent& event) override; /** * @brief Draw the game to the display buffer */ void draw() override; private: // Game state struct GameState { uint8_t board[3][3]; // 0=empty, 1=X, 2=O uint8_t current_player; // 1=X, 2=O uint8_t winner; // 0=none, 1=X wins, 2=O wins, 3=tie uint8_t selected_row; // Currently selected cell (for button navigation) uint8_t selected_col; bool game_over; // Game statistics uint32_t x_wins; uint32_t o_wins; uint32_t ties; uint32_t total_moves; } state; /** * @brief Check if there's a winner on the board * @return 0=no winner, 1=X wins, 2=O wins, 3=tie */ uint8_t check_winner(); // Board layout constants static const int BOARD_SIZE = 200; static const int CELL_SIZE = BOARD_SIZE / 3; static const int BOARD_Y = 80; // Y position below title }; #endif // TIC_TAC_TOE_H