input manager provides ground of truth on device input choise

This commit is contained in:
Adolfo Reyna
2026-01-30 22:07:31 -05:00
parent 436245a7a2
commit f860d4f5e6
10 changed files with 97 additions and 44 deletions

View File

@@ -4,15 +4,15 @@
// Game logic, input handling, and rendering for Tic-Tac-Toe
#include "tic_tac_toe.h"
#include "board_config.h"
#include "input_manager.h"
#include <stdio.h>
#include <string.h>
// Font reference from display system
extern Font font_5x5_obj;
TicTacToeGame::TicTacToeGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui)
: Game(width, height, renderer, gui) {
TicTacToeGame::TicTacToeGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager)
: Game(width, height, renderer, gui, input_manager) {
// Initialize statistics to zero
state.x_wins = 0;
state.o_wins = 0;
@@ -220,20 +220,20 @@ void TicTacToeGame::draw() {
} else {
renderer->draw_string(20, 40, "TIE GAME!", true);
}
#ifdef BUTTON_KEY0_PIN
renderer->draw_string(20, 55, "Touch or KEY0 to restart", true);
#else
renderer->draw_string(20, 55, "Touch to restart", true);
#endif
if (input_manager->has_buttons()) {
renderer->draw_string(20, 55, "Touch or KEY0 to restart", true);
} else {
renderer->draw_string(20, 55, "Touch to restart", true);
}
} else {
char turn_text[30];
snprintf(turn_text, sizeof(turn_text), "Turn: %s", state.current_player == 1 ? "X" : "O");
renderer->draw_string(20, 40, turn_text, true);
#ifdef BUTTON_KEY0_PIN
renderer->draw_string(20, 55, "Touch cell or use keys", true);
#else
renderer->draw_string(20, 55, "Touch cell to play", true);
#endif
if (input_manager->has_buttons()) {
renderer->draw_string(20, 55, "Touch cell or use keys", true);
} else {
renderer->draw_string(20, 55, "Touch cell to play", true);
}
}
// Draw game board (use same layout as touch detection!)