Skip to content

Commit

Permalink
Finished refactoring project to use new TextFileReader class and Play…
Browse files Browse the repository at this point in the history
…erScore class
  • Loading branch information
cbedrosian1 committed Apr 23, 2019
1 parent fd7b63c commit 8876172
Show file tree
Hide file tree
Showing 29 changed files with 98 additions and 78 deletions.
48 changes: 27 additions & 21 deletions GroupHWordScramble.depend
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

1555800365 D

1556027547 source:/home/csuser/GroupHWordScramble/controller/WordScrambleController.cpp
1556035797 source:/home/csuser/GroupHWordScramble/controller/WordScrambleController.cpp
"WordScrambleController.h"

1555808571 bleController.h"
Expand All @@ -175,16 +175,14 @@
<vector>
<string>

1556027547 /home/csuser/GroupHWordScramble/controller/WordScrambleController.h
1556034205 /home/csuser/GroupHWordScramble/controller/WordScrambleController.h
<string>
<vector>
<unordered_set>
<map>
"GameLogic.h"
"SettingsFileReader.h"
"PlayerScore.h"
"SettingsFileWriter.h"
"DictionaryFileReader.h"
"HighScoreFileReader.h"
"TextFileReader.h"
"OutputFormatter.h"
"Utils.h"

Expand All @@ -196,7 +194,7 @@
<set>
<map>

1556027547 /home/csuser/GroupHWordScramble/io/SettingsFileReader.h
1556033198 /home/csuser/GroupHWordScramble/io/SettingsFileReader.h
<iostream>
<iterator>
<sstream>
Expand All @@ -223,11 +221,11 @@

1555793152 shed changes

1556027547 /home/csuser/GroupHWordScramble/io/SettingsFileWriter.h
1556034709 /home/csuser/GroupHWordScramble/io/SettingsFileWriter.h
<iostream>
<fstream>
<string>
"SettingsFileReader.h"
"TextFileReader.h"

1556027547 source:/home/csuser/GroupHWordScramble/io/SettingsFileReader.cpp
"SettingsFileReader.h"
Expand Down Expand Up @@ -313,7 +311,7 @@
"GameWindow.h"
<iostream>

1556027547 source:/home/csuser/GroupHWordScramble/view/HighScoreWindow.cpp
1556034177 source:/home/csuser/GroupHWordScramble/view/HighScoreWindow.cpp
"HighScoreWindow.h"

1556027547 source:/home/csuser/GroupHWordScramble/view/MainWindow.cpp
Expand Down Expand Up @@ -349,7 +347,7 @@
1556027547 source:/home/csuser/GroupHWordScramble/io/DictionaryFileReader.cpp
"DictionaryFileReader.h"

1556027547 /home/csuser/GroupHWordScramble/io/DictionaryFileReader.h
1556033187 /home/csuser/GroupHWordScramble/io/DictionaryFileReader.h
<iostream>
<iterator>
<sstream>
Expand All @@ -376,17 +374,18 @@

1556027547 /home/csuser/GroupHWordScramble/io/HighScoreFileWriter.h

1556027547 /home/csuser/GroupHWordScramble/view/OutputFormatter.h
<map>
1556035227 /home/csuser/GroupHWordScramble/view/OutputFormatter.h
<iomanip>
<vector>
<string>
<map>
<sstream>
"PlayerScore.h"

1556027547 source:/home/csuser/GroupHWordScramble/io/HighScoreFileReader.cpp
"HighScoreFileReader.h"

1556027547 /home/csuser/GroupHWordScramble/io/HighScoreFileReader.h
1556033192 /home/csuser/GroupHWordScramble/io/HighScoreFileReader.h
<iostream>
<iterator>
<sstream>
Expand All @@ -396,7 +395,7 @@
<vector>
<map>

1556027547 source:/home/csuser/GroupHWordScramble/view/OutputFormatter.cpp
1556036131 source:/home/csuser/GroupHWordScramble/view/OutputFormatter.cpp
"OutputFormatter.h"
<iostream>

Expand Down Expand Up @@ -443,27 +442,34 @@
1555964346 source:/home/csuser/Desktop/GroupHWordScramble/model/GameLogic.cpp
"GameLogic.h"

1556027547 /home/csuser/GroupHWordScramble/model/GameLogic.h
1556035674 /home/csuser/GroupHWordScramble/model/GameLogic.h
"LetterFrequency.h"
"DictionaryFileReader.h"

1556027547 source:/home/csuser/GroupHWordScramble/model/GameLogic.cpp
1556036058 source:/home/csuser/GroupHWordScramble/model/GameLogic.cpp
"GameLogic.h"

1556028441 source:/home/csuser/GroupHWordScramble/model/PlayerScore.cpp
1556034002 source:/home/csuser/GroupHWordScramble/model/PlayerScore.cpp
"PlayerScore.h"

1556028366 /home/csuser/GroupHWordScramble/model/PlayerScore.h
1556034030 /home/csuser/GroupHWordScramble/model/PlayerScore.h
<string>

1556032960 source:/home/csuser/GroupHWordScramble/io/TextFileReader.cpp
1556036168 source:/home/csuser/GroupHWordScramble/io/TextFileReader.cpp
"TextFileReader.h"

1556032896 /home/csuser/GroupHWordScramble/io/TextFileReader.h
1556034576 /home/csuser/GroupHWordScramble/io/TextFileReader.h
"PlayerScore.h"
<sstream>
<fstream>
<vector>
<string>
<unordered_set>

1556033053 source:/home/csuser/GroupHWordScramble/model/HighScoreBoard.cpp
"HighScoreBoard.h"

1556033034 /home/csuser/GroupHWordScramble/model/HighScoreBoard.h
"PlayerScore.h"
<vector>

Binary file modified bin/Debug/GroupHWordScramble
Binary file not shown.
19 changes: 12 additions & 7 deletions controller/WordScrambleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace controller

WordScrambleController::WordScrambleController()
{

unordered_set<string> words = this->fileReader.getDictionaryData();
this->logic = GameLogic(words);
}

WordScrambleController::~WordScrambleController()
Expand All @@ -16,13 +17,17 @@ WordScrambleController::~WordScrambleController()

int WordScrambleController::getNumberOfLetters()
{
this->settingsFileReader.getNumberOfLetters();
vector<string> settings = this->fileReader.getSettingsData();
int numberOfLetters = stoi(settings[INDEX_OF_NUMBER_OF_LETTERS]);
return numberOfLetters;

}

int WordScrambleController::getTimer()
{
this->settingsFileReader.getTimer();
vector<string> settings = this->fileReader.getSettingsData();
int timer = stoi(settings[INDEX_OF_TIMER]);
return timer;
}

void WordScrambleController::writeSettingsToFile(const int numberOfLetters, const int timer)
Expand Down Expand Up @@ -81,11 +86,11 @@ string WordScrambleController::getFormattedWordsAndTheirPoints()
return this->formatter.formatWords(this->logic.getGuessedWords());
}

string WordScrambleController::getFormattedHighScores()
string WordScrambleController::getInitialHighScores()
{
map<string, vector<int>> scores = this->scoreFileReader.readFile();
string output = this->formatter.formatScores(scores);
return this->formatter.formatScores(scores);
vector<PlayerScore> playerScores = this->fileReader.getHighScoreData();
string output = this->formatter.formatScores(playerScores);
return output;
}


Expand Down
13 changes: 4 additions & 9 deletions controller/WordScrambleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
#include <string>
#include <vector>
#include <unordered_set>
#include <map>
using namespace std;

#include "GameLogic.h"
#include "PlayerScore.h"
using namespace model;

#include "SettingsFileReader.h"
#include "SettingsFileWriter.h"
#include "DictionaryFileReader.h"
#include "HighScoreFileReader.h"
#include "TextFileReader.h"
using namespace io;

#include "OutputFormatter.h"
Expand All @@ -36,16 +34,13 @@ class WordScrambleController
{

private:
HighScoreFileReader scoreFileReader;

SettingsFileReader settingsFileReader;
TextFileReader fileReader;

OutputFormatter formatter;

GameLogic logic;

DictionaryFileReader dictionaryFileReader;

LetterFrequency letterFrequency;


Expand Down Expand Up @@ -154,7 +149,7 @@ class WordScrambleController
* @postcondition none
* @return Formatted highscores
*/
string getFormattedHighScores();
string getInitialHighScores();

/**
* Sets the possible words to guess from
Expand Down
1 change: 0 additions & 1 deletion io/DictionaryFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ using namespace std;

namespace io
{
const string DICTIONARY_FILE_NAME = "dictionary";

//The dictionary file reader that handles reading data from the dictionary file
//@author Lucas Carlson
Expand Down
7 changes: 0 additions & 7 deletions io/HighScoreFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ using namespace std;
namespace io
{

const string HIGH_SCORE_FILE_NAME = "highscores";
const int INDEX_OF_VALUES = 0;
const int INDEX_OF_NAME = 0;
const int INDEX_OF_SCORE = 1;
const int INDEX_OF_TIME = 2;
const char COMMA = ',';

class HighScoreFileReader
{
private:
Expand Down
5 changes: 1 addition & 4 deletions io/SettingsFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ using namespace std;
namespace io
{

const string SETTINGS_FILE_NAME = "settings";
const int INDEX_OF_SETTINGS = 0;
const int INDEX_OF_NUMBER_OF_LETTERS = 0;
const int INDEX_OF_TIMER = 1;


/**
* The settings file reader that controls reader the settings from the file
Expand Down
2 changes: 1 addition & 1 deletion io/SettingsFileWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
using namespace std;

#include "SettingsFileReader.h"
#include "TextFileReader.h"


namespace io
Expand Down
11 changes: 6 additions & 5 deletions io/TextFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ TextFileReader::~TextFileReader()

}

unordered_set<string> TextFileReader::readDictionaryFile()
unordered_set<string> TextFileReader::getDictionaryData()
{
vector<string> data = this->getDataFromFile(DICTIONARY_FILE_NAME);
unordered_set<string> words;
for (size_t index = 0; index < data.size(); index++)
{
words.insert(data[index]);
string word = data[index].erase(data[index].length()-1);
words.insert(word);
}
return words;
}


vector<string> TextFileReader::readSettingsFile()
vector<string> TextFileReader::getSettingsData()
{
vector<string> data = this->getDataFromFile(SETTINGS_FILE_NAME);
vector<string> settings = this->split(data[INDEX_OF_VALUES], COMMA);
Expand All @@ -36,13 +37,13 @@ vector<string> TextFileReader::readSettingsFile()
}


vector<PlayerScore> TextFileReader::readHighScoreFile()
vector<PlayerScore> TextFileReader::getHighScoreData()
{
vector<string> data = this->getDataFromFile(HIGH_SCORE_FILE_NAME);
vector<PlayerScore> playerScores;
for(size_t index = 0; index < data.size(); index++)
{
vector<string> values = this->split(data[INDEX_OF_VALUES], COMMA);
vector<string> values = this->split(data[index], COMMA);
string name = values[INDEX_OF_NAME];
int score = stoi(values[INDEX_OF_SCORE]);
int timeInSeconds = stoi(values[INDEX_OF_TIME]);
Expand Down
6 changes: 3 additions & 3 deletions io/TextFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class TextFileReader
*/
virtual ~TextFileReader();

unordered_set<string> readDictionaryFile();
unordered_set<string> getDictionaryData();

vector<string> readSettingsFile();
vector<string> getSettingsData();

vector<PlayerScore> readHighScoreFile();
vector<PlayerScore> getHighScoreData();


};
Expand Down
18 changes: 11 additions & 7 deletions model/GameLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

namespace model
{

GameLogic::GameLogic()
{
DictionaryFileReader reader;
this->validWords = reader.getValidWords();

}

GameLogic::GameLogic(unordered_set<string> words)
{
this->validWords = words;
}

GameLogic::~GameLogic()
Expand Down Expand Up @@ -103,7 +108,7 @@ int GameLogic::getTotalNumberOfWords()

void GameLogic::setPossibleWords(const string& characters)
{
this->possibleWords = this->findAllValidWords(characters);
this->possibleWords = this->findAllPossibleWords(characters);
}

bool GameLogic::isPossible(string word, string letters)
Expand All @@ -127,17 +132,16 @@ bool GameLogic::isPossible(string word, string letters)

}

unordered_set<string> GameLogic::findAllValidWords(string letters)
unordered_set<string> GameLogic::findAllPossibleWords(string letters)
{
DictionaryFileReader reader;
unordered_set<string> dictionary = reader.getValidWords();
unordered_set<string> result;
for (auto& word : dictionary)
for (auto& word : this->validWords)
{
if (word.length() >= 3)
{
if (this->isPossible(word, letters))
{

result.insert(word);
}
}
Expand Down
Loading

0 comments on commit 8876172

Please sign in to comment.