diff --git a/src/Game.cpp b/src/Game.cpp index db011c7..d934347 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1,11 +1,13 @@ #include #include #include +#include #include "Game.hpp" #include "SDL.h" #include "SDL_ttf.h" #include "words.hpp" #include "utils.hpp" +#include "default_font.hpp" const int CHAR_SIZE = 30; const int STEP_SIZE = CHAR_SIZE + CHAR_SIZE / 2; @@ -65,6 +67,23 @@ void Game::Run() { } Game::Game() { + const char *defaultFontPath = getDefaultFontPath(); + if (defaultFontPath == nullptr) { + std::stringstream ss; + ss << "Font path is not set for this platform (null)"; + auto s = ss.str(); + std::cerr << s << std::endl; + throw std::runtime_error(s); + } + font = TTF_OpenFont(defaultFontPath, CHAR_SIZE); + if (font == nullptr) { + std::stringstream ss; + ss << "Failed to load font: " << TTF_GetError(); + auto s = ss.str(); + std::cerr << s << std::endl; + throw std::runtime_error(s); + } + std::random_device random_device{}; std::mt19937 rng(random_device()); diff --git a/src/Game.hpp b/src/Game.hpp index cc6918c..4f47190 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -1,10 +1,11 @@ #pragma once -#include -#include #include #include -#include +#include "SDL_rect.h" +#include "SDL_events.h" +#include "SDL_render.h" +#include "SDL_ttf.h" #include "GuessCorrector.hpp" const SDL_Point SCREEN_SIZE{800, 800}; @@ -14,6 +15,7 @@ private: std::vector all_words; std::unique_ptr guess_corrector; const char *word; + const _TTF_Font *font; public: static void Run();