Commit 7ef3e3b1 authored by Kyle Malaguit's avatar Kyle Malaguit

autosave

parent dde00b28
...@@ -21,4 +21,29 @@ void SaveLoad::displayScores(){ ...@@ -21,4 +21,29 @@ void SaveLoad::displayScores(){
cout << i++ << "\t" << score.getName() << "\t" << score.getScore() << endl; cout << i++ << "\t" << score.getName() << "\t" << score.getScore() << endl;
} }
}
void SaveLoad::userInputNameMakeScore(int intScore){
char userNameInput[3];
cout << "Please enter a 3 character user name\n";
do{
try{
cin >> userNameInput;
if(strlen(userNameInput) != 3){
throw runtime_error("Invalid User Name input ! \n");
}
break;
}
catch(runtime_error &ex){
cout << ex.what() << endl;
}
}while(true);
Scores*scorePtr = nullptr;
scorePtr = new Scores(userNameInput, intScore);
pushBackNewScoreAndSort(*scorePtr);
} }
\ No newline at end of file
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include <cstring>
#include "Scores.h" #include "Scores.h"
#include <map> #include <map>
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <stdexcept>
#include <iostream> #include <iostream>
using namespace std; using namespace std;
...@@ -23,6 +25,8 @@ class SaveLoad { ...@@ -23,6 +25,8 @@ class SaveLoad {
static bool sortAscending(Scores, Scores); static bool sortAscending(Scores, Scores);
void userInputNameMakeScore(int intScore);
//display scores in the bash //display scores in the bash
void displayScores(); void displayScores();
......
...@@ -16,6 +16,7 @@ class Scores{ ...@@ -16,6 +16,7 @@ class Scores{
string getName(){return name;} string getName(){return name;}
int getScore(){return score;} int getScore(){return score;}
private: private:
string name; string name;
int score; int score;
......
...@@ -10,24 +10,30 @@ using namespace std; ...@@ -10,24 +10,30 @@ using namespace std;
int main(){ int main(){
//check for valid username //check for valid username
char userName[3]; // char userName[3];
SLSnake second; SLSnake second;
second.LoadContainers(); second.LoadContainers();
cout << "Enter a username with a length of 3 characters\n"; // cout << "Enter a username with a length of 3 characters\n";
cin >> userName; // cin >> userName;
//here is a temporary score input system // //here is a temporary score input system
//in the final project the score will be taken automatically from the system. // //in the final project the score will be taken automatically from the system.
int score; // int score;
cout << "Enter a score: "; // cout << "Enter a score: ";
cin >> score; // cin >> score;
cout << endl; // cout << endl;
Scores score1(userName, score); // Scores score1(userName, score);
second.pushBackNewScoreAndSort(score1); // second.pushBackNewScoreAndSort(score1);
second.updateFile(); // second.updateFile();
// second.displayScores();
second.userInputNameMakeScore(1000);
second.updateFile();
second.displayScores(); second.displayScores();
......
...@@ -5,4 +5,6 @@ cdn 21474 ...@@ -5,4 +5,6 @@ cdn 21474
vfd 4636 vfd 4636
vev 4536 vev 4536
DVS 3423 DVS 3423
goo 1000
dew 343 dew 343
bth 34
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