simple utils
This commit is contained in:
parent
3a831b0099
commit
5eb7c59019
@ -10,8 +10,8 @@
|
|||||||
#include "random.h"
|
#include "random.h"
|
||||||
#include "shuffle.h"
|
#include "shuffle.h"
|
||||||
#include "strlib.h"
|
#include "strlib.h"
|
||||||
#include <sstream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
// The res folder isn't copied the same way on macOS
|
// The res folder isn't copied the same way on macOS
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@ -22,7 +22,8 @@ const std::string Boggle::DICTIONARY_FILE = "EnglishWords.dat";
|
|||||||
|
|
||||||
static const int NUM_CUBES = 16; // the number of cubes in the game
|
static const int NUM_CUBES = 16; // the number of cubes in the game
|
||||||
static const int CUBE_SIDES = 6; // the number of sides on each cube
|
static const int CUBE_SIDES = 6; // the number of sides on each cube
|
||||||
static std::string CUBES[NUM_CUBES] = { // the letters on all 6 sides of every cube
|
static std::string CUBES[NUM_CUBES] =
|
||||||
|
{ // the letters on all 6 sides of every cube
|
||||||
"AAEEGN", "ABBJOO", "ACHOPS", "AFFKPS", "AOOTTW", "CIMOTU",
|
"AAEEGN", "ABBJOO", "ACHOPS", "AFFKPS", "AOOTTW", "CIMOTU",
|
||||||
"DEILRX", "DELRVY", "DISTTY", "EEGHNW", "EEINSU", "EHRTVW",
|
"DEILRX", "DELRVY", "DISTTY", "EEGHNW", "EEINSU", "EHRTVW",
|
||||||
"EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"};
|
"EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"};
|
||||||
@ -41,8 +42,13 @@ std::array<std::string, NUM_ROLLED_CUBES> rollSides() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Boggle::Boggle()
|
Boggle::Boggle()
|
||||||
: showingSides(rollSides()), englishWords(Boggle::DICTIONARY_FILE) {}
|
: m_showingSides(rollSides()), m_englishWords(Boggle::DICTIONARY_FILE) {}
|
||||||
|
|
||||||
bool Boggle::insertWordIfValid() {
|
|
||||||
|
|
||||||
|
bool Boggle::isWordValid(const std::string &word) const {
|
||||||
|
return m_englishWords.contains(word);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Boggle::isWordPlayed(const string &word) const {
|
||||||
|
return std::find(m_playedWords.begin(), m_playedWords.end(), word) !=
|
||||||
|
m_playedWords.end();
|
||||||
}
|
}
|
||||||
|
12
src/Boggle.h
12
src/Boggle.h
@ -22,14 +22,12 @@ public:
|
|||||||
|
|
||||||
Boggle();
|
Boggle();
|
||||||
|
|
||||||
/**
|
bool isWordValid(const std::string &word) const;
|
||||||
* @return true if the word read was valid, false if not
|
bool isWordPlayed(const std::string &word) const;
|
||||||
*/
|
|
||||||
bool insertWordIfValid();
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> userWords;
|
std::vector<std::string> m_playedWords;
|
||||||
std::array<std::string, 4> showingSides;
|
std::array<std::string, 4> m_showingSides;
|
||||||
Lexicon englishWords;
|
Lexicon m_englishWords;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user