init word aswell

This commit is contained in:
Love 2024-08-02 16:18:15 +02:00
parent 7eab5371ce
commit 7d992f3b30
2 changed files with 8 additions and 12 deletions

View File

@ -64,17 +64,15 @@ Game::Game() : guessed() {
std::mt19937 rng(random_device()); std::mt19937 rng(random_device());
size_t words_len = array_len(words); size_t words_len = array_len(words);
this->all_words = std::vector<const char *>(); all_words = std::vector<const char *>();
this->all_words.reserve(words_len); all_words.reserve(words_len);
for (int i = 0; i < words_len; i++) for (int i = 0; i < words_len; i++)
all_words.push_back(words[i]); all_words.push_back(words[i]);
std::shuffle(all_words.begin(), all_words.end(), rng); std::shuffle(all_words.begin(), all_words.end(), rng);
word = all_words.back();
all_words.pop_back();
} }
void Game::handle_key(SDL_Keycode event) { void Game::handle_key(SDL_Keycode event) {
} }
void Game::select_word() {
}

View File

@ -3,14 +3,15 @@
#include <SDL_rect.h> #include <SDL_rect.h>
#include <SDL_events.h> #include <SDL_events.h>
#include <vector> #include <vector>
#include <optional>
const SDL_Point SCREEN_SIZE{800, 800}; const SDL_Point SCREEN_SIZE{800, 800};
class Game { class Game {
private: private:
std::vector<const char *> all_words; std::vector<const char *> all_words;
std::vector<std::string> guessed; std::vector<std::optional<char>> guessed;
std::string word; const char *word;
public: public:
static void Run(); static void Run();
@ -18,8 +19,5 @@ public:
Game(); Game();
void handle_key(SDL_Keycode event); void handle_key(SDL_Keycode event);
private:
void select_word();
}; };