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

autosave

parent dde00b28
......@@ -22,3 +22,28 @@ void SaveLoad::displayScores(){
}
}
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 @@
#include <fstream>
#include <vector>
#include <cstring>
#include "Scores.h"
#include <map>
#include <string>
#include <algorithm>
#include <stdexcept>
#include <iostream>
using namespace std;
......@@ -23,6 +25,8 @@ class SaveLoad {
static bool sortAscending(Scores, Scores);
void userInputNameMakeScore(int intScore);
//display scores in the bash
void displayScores();
......
......@@ -16,6 +16,7 @@ class Scores{
string getName(){return name;}
int getScore(){return score;}
private:
string name;
int score;
......
......@@ -10,27 +10,33 @@ using namespace std;
int main(){
//check for valid username
char userName[3];
// char userName[3];
SLSnake second;
second.LoadContainers();
cout << "Enter a username with a length of 3 characters\n";
cin >> userName;
//here is a temporary score input system
//in the final project the score will be taken automatically from the system.
int score;
cout << "Enter a score: ";
cin >> score;
cout << endl;
Scores score1(userName, score);
second.pushBackNewScoreAndSort(score1);
second.updateFile();
// cout << "Enter a username with a length of 3 characters\n";
// cin >> userName;
// //here is a temporary score input system
// //in the final project the score will be taken automatically from the system.
// int score;
// cout << "Enter a score: ";
// cin >> score;
// cout << endl;
// Scores score1(userName, score);
// second.pushBackNewScoreAndSort(score1);
// second.updateFile();
// second.displayScores();
second.userInputNameMakeScore(1000);
second.updateFile();
second.displayScores();
return 0;
}
......
......@@ -5,4 +5,6 @@ cdn 21474
vfd 4636
vev 4536
DVS 3423
goo 1000
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