correct
This commit is contained in:
parent
9ea691f7e6
commit
9894198f01
@ -71,7 +71,7 @@ Game::Game() {
|
|||||||
std::shuffle(all_words.begin(), all_words.end(), rng);
|
std::shuffle(all_words.begin(), all_words.end(), rng);
|
||||||
word = all_words.back();
|
word = all_words.back();
|
||||||
all_words.pop_back();
|
all_words.pop_back();
|
||||||
guess_corrector = GuessCorrector(word);
|
guess_corrector = std::make_unique<GuessCorrector>(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::handle_key(SDL_Keycode event) {
|
void Game::handle_key(SDL_Keycode event) {
|
||||||
|
@ -11,7 +11,7 @@ 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;
|
||||||
GuessCorrector guess_corrector;
|
std::unique_ptr<GuessCorrector> guess_corrector;
|
||||||
const char *word;
|
const char *word;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
GuessCorrector::GuessCorrector(const char *word)
|
GuessCorrector::GuessCorrector(const char *word)
|
||||||
: m_word(word),
|
: m_word(word),
|
||||||
m_word_length(strlen(word)),
|
m_word_length(strlen(word)),
|
||||||
m_parts_guessed(std::make_unique<std::optional<char>[]>(m_word_length)) {
|
m_parts_guessed(std::make_shared<std::optional<char>[]>(m_word_length)) {
|
||||||
for (size_t i = 0; i < m_word_length; i++) {
|
for (std::ptrdiff_t i = 0; i < m_word_length; i++) {
|
||||||
m_parts_guessed[i] = std::nullopt;
|
m_parts_guessed[i] = std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ bool GuessCorrector::is_filled_out() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::weak_ptr<std::optional<char>[]> GuessCorrector::guessed() const {
|
std::weak_ptr<std::optional<char>[]> GuessCorrector::guessed() const {
|
||||||
m_parts_guessed;
|
return m_parts_guessed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,13 +6,11 @@
|
|||||||
class GuessCorrector {
|
class GuessCorrector {
|
||||||
const char *m_word;
|
const char *m_word;
|
||||||
size_t m_word_length;
|
size_t m_word_length;
|
||||||
std::unique_ptr<std::optional<char>[]> m_parts_guessed;
|
std::shared_ptr<std::optional<char>[]> m_parts_guessed;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GuessCorrector(const char *word);
|
GuessCorrector(const char *word);
|
||||||
|
|
||||||
GuessCorrector() = default;
|
|
||||||
|
|
||||||
[[nodiscard]] bool has_char(char to_check) const;
|
[[nodiscard]] bool has_char(char to_check) const;
|
||||||
|
|
||||||
void add(char to_add);
|
void add(char to_add);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user