Skip to content
Snippets Groups Projects
game.cpp 709 B
Newer Older

GameState::GameState() : word(), tries(0), guesses() {}

GameState::GameState(const std::string &w) : word(w), tries(0), guesses() {}

void GameState::setWord(const std::string &w) { word = w; }

std::array<GameState::matchType, WORD_LENGTH>
GameState::guess(const std::string &guessedWord) {
  std::array<matchType, WORD_LENGTH> matchStatus;
  // iterate over the word character by character
  for (std::string::size_type i = 0; i < guessedWord.size(); i++) {
    if (word[i] == guessedWord[i]) {
      matchStatus[i] = EXACT_MATCH;
    } else if (word.find(guessedWord[i])) {
      matchStatus[i] = MATCH;
    } else {
      matchStatus[i] = NO_MATCH;
    }
  }
  return matchStatus;
}