Commit 7f4049e9 authored by Konrad McClure's avatar Konrad McClure

High Score stuff updated

parent 0c950b47
......@@ -57,12 +57,16 @@ void CSnakeGameOverState::HandleEvents(CGameEngine* game)
if (!scoreSet)
{
system("stty cooked");
cout << "Press enter to continue" << endl;
game->newInput = false;
game->inputPause = true;
while (game->newInput == false) {}
highscores.userInputNameMakeScore(game->GetScore());
userRank = highscores.userInputNameMakeScore(game->GetScore());
scoreSet = true;
system("stty raw");
game->inputPause = false;
}
......@@ -101,6 +105,11 @@ void CSnakeGameOverState::Draw(CGameEngine* game)
highscores.displayScores();
if (scoreSet)
{
highscores.useRankFindScore(userRank);
}
highscores.updateFile("../SaveLoad/snakedata.txt");
system("stty raw");
......
......@@ -3,6 +3,7 @@
#include "GameState.h"
#include "../SaveLoad/SLSnake.h"
#include "../SaveLoad/Scores.h"
#include <iostream>
#include <string>
......@@ -29,6 +30,7 @@ class CSnakeGameOverState : public CGameState
char input;
string menuTitle;
SLSnake highscores;
int userRank = 0;
bool isInit = false;
bool scoreSet = false;
......
......@@ -26,7 +26,7 @@ void SaveLoad::displayScores(){
}
void SaveLoad::userInputNameMakeScore(int intScore){
int SaveLoad::userInputNameMakeScore(int intScore){
char userNameInput[3];
do{
cout << "Please enter a 3 character user name\n";
......@@ -45,22 +45,24 @@ void SaveLoad::userInputNameMakeScore(int intScore){
}while(true);
pushBackNewScoreAndSort(Scores(userNameInput, intScore));
return printScoreIfLessThan10(Scores(userNameInput, intScore));
}
void SaveLoad::printScoreIfLessThan10(Scores findScore){
int SaveLoad::printScoreIfLessThan10(Scores findScore){
vector<Scores>::iterator iter;
cout << "Finding Score..\n";
iter = find(scores.begin(), scores.end(), findScore);
if(iter != scores.end()){
//use iterator to return position in vector
cout << "Score found "<< (iter - scores.begin())+1 << endl;
return (iter - scores.begin())+1;
}else{
cout << "Score not found" << endl;
return 0;
}
}
void SaveLoad::useRankFindScore(int rank){
......@@ -69,5 +71,5 @@ void SaveLoad::useRankFindScore(int rank){
return;
}
Scores foundScore = scores.at(rank - 1);
cout << "At rank " << rank << " player " << foundScore.getName() << " has a score of " << foundScore.getScore() << endl;
cout << rank << "\t\t" << foundScore.getName() << "\t\t" << foundScore.getScore() << endl;
}
\ No newline at end of file
......@@ -23,13 +23,13 @@ class SaveLoad {
//add new data into file
void sortByScore();
void userInputNameMakeScore(int intScore);
int userInputNameMakeScore(int intScore);
//display scores in the bash
void displayScores();
//if score is less than top ten print score
void printScoreIfLessThan10(Scores);
int printScoreIfLessThan10(Scores);
//one that passes a position and returns the line in the vector
void useRankFindScore(int rank);
......
......@@ -6,10 +6,14 @@ aaa 25
aaa 20
aaa 15
aaa 10
aaa 5
kom 5
aaa 1
aaa 5
kom 1
MOP 1
kom 1
KMO 1
qwe 1
kom 1
aaa 1
kom 0
kom 0
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