Commit 7156b14c authored by Kyle Malaguit's avatar Kyle Malaguit

autosave

parent 962b4c8a
...@@ -5,6 +5,7 @@ vds 10000 ...@@ -5,6 +5,7 @@ vds 10000
NEL 10000 NEL 10000
PHI 10000 PHI 10000
BAG 10000 BAG 10000
mmm 10000
BVB 9240 BVB 9240
BND 6564 BND 6564
CDS 6544 CDS 6544
......
...@@ -26,9 +26,10 @@ void SL2048::LoadContainers(){ ...@@ -26,9 +26,10 @@ void SL2048::LoadContainers(){
fin.close(); fin.close();
} }
void SL2048::updateFile(){ void SL2048::updateFile(string fileName){
ofstream fout; ofstream fout;
fout.open("2048Data.txt", ofstream::out | ofstream::trunc); fout.open(fileName, ofstream::out | ofstream::trunc);
//delete file contents //delete file contents
fout << "NAME" << "\t" << "SCORE" << endl; fout << "NAME" << "\t" << "SCORE" << endl;
for(auto scoresFull : scores){ for(auto scoresFull : scores){
......
...@@ -16,7 +16,7 @@ class Scores; ...@@ -16,7 +16,7 @@ class Scores;
class SL2048 : public SaveLoad{ class SL2048 : public SaveLoad{
public: public:
void LoadContainers(); void LoadContainers();
void updateFile(); void updateFile(string fileName);
}; };
#endif #endif
\ No newline at end of file
...@@ -25,10 +25,10 @@ void SLSnake::LoadContainers(){ ...@@ -25,10 +25,10 @@ void SLSnake::LoadContainers(){
fin.close(); fin.close();
} }
void SLSnake::updateFile(){ void SLSnake::updateFile(string fileName){
ofstream fout; ofstream fout;
//delete date in snake data file //delete date in snake data file
fout.open("snakedata.txt", ofstream::out | ofstream::trunc); fout.open(fileName, ofstream::out | ofstream::trunc);
//update //update
fout << "NAME" << "\t" << "SCORE" << endl; fout << "NAME" << "\t" << "SCORE" << endl;
......
...@@ -16,7 +16,7 @@ class Scores; ...@@ -16,7 +16,7 @@ class Scores;
class SLSnake : public SaveLoad{ class SLSnake : public SaveLoad{
public: public:
void LoadContainers(); void LoadContainers();
void updateFile(); void updateFile(string fileName);
}; };
#endif #endif
\ No newline at end of file
...@@ -40,7 +40,6 @@ void SaveLoad::userInputNameMakeScore(int intScore){ ...@@ -40,7 +40,6 @@ void SaveLoad::userInputNameMakeScore(int intScore){
} }
catch(runtime_error &ex){ catch(runtime_error &ex){
cout << ex.what() << endl; cout << ex.what() << endl;
cout << userNameInput << endl;
} }
}while(true); }while(true);
......
...@@ -16,22 +16,24 @@ using namespace std; ...@@ -16,22 +16,24 @@ using namespace std;
class Scores; class Scores;
class SaveLoad { class SaveLoad {
public: public:
//these functions change the files data
virtual void LoadContainers() = 0; virtual void LoadContainers() = 0;
virtual void updateFile() = 0; virtual void updateFile() = 0;
//add new data into file //add new data into file
void pushBackNewScoreAndSort(Scores Score);
void sortByScore(); void sortByScore();
static bool sortAscending(Scores, Scores);
void userInputNameMakeScore(int intScore); void userInputNameMakeScore(int intScore);
//display scores in the bash //display scores in the bash
void displayScores(); void displayScores();
//function for comparing
static bool sortAscending(Scores, Scores);
protected: protected:
vector<Scores> scores; vector<Scores> scores;
void pushBackNewScoreAndSort(Scores Score);
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment