Commit c9918a08 authored by Nelson Phillips's avatar Nelson Phillips

Merge branch 'master' of gitlab.cs.wallawalla.edu:philne/142GameCenter

parents 1e61c7ef bd4d4e41
#include <iostream>
#include "2048GameOverState.h"
#include <string>
#include <fstream>
#include <streambuf>
using namespace std;
C2048GameOverState C2048GameOverState::m_2048GameOverState;
void C2048GameOverState::Init()
{
if (!isInit)
{
// Load in main menu title
ifstream fs("2048ScoreTitle.txt");
fs.seekg(0, ios::end);
menuTitle.reserve(fs.tellg());
fs.seekg(0, ios::beg);
menuTitle.assign((istreambuf_iterator<char>(fs)),
istreambuf_iterator<char>());
// Set name for debugging
stateName = "2048score";
// Read in score data
highscores.LoadContainers();
isInit = true;
}
// Set first input and draw the menu
input = ' ';
Draw(nullptr);
}
void C2048GameOverState::Pause()
{
}
void C2048GameOverState::Resume()
{
input = 0;
}
void C2048GameOverState::Cleanup()
{
}
void C2048GameOverState::HandleEvents(CGameEngine* game)
{
while (game->newInput == false)
{
input = ' ';
}
input = game->input;
game->newInput = false;
}
void C2048GameOverState::Update(CGameEngine* game)
{
switch(input)
{
case 'x':
// Erase Scores
break;
default:
game->PopState();
break;
}
}
void C2048GameOverState::Draw(CGameEngine* game)
{
system("stty cooked");
cout << menuTitle << endl;
highscores.displayScores();
system("stty raw");
}
#ifndef C2048GAMEOVERSTATE_H
#define C2048GAMEOVERSTATE_H
#include "GameState.h"
#include "../Testings/SaveLoad/SL2048.h"
#include <iostream>
#include <string>
class C2048GameOverState : public CGameState
{
public:
void Init();
void Cleanup();
void Pause();
void Resume();
void HandleEvents(CGameEngine* game);
void Update(CGameEngine* game);
void Draw(CGameEngine* game);
static C2048GameOverState* Instance() { return &m_2048ScoreState; }
protected:
C2048GameOverState() {}
private:
static C2048GameOverState m_2048GameOverState;
char input;
string menuTitle;
SL2048 highscores;
bool isInit = false;
};
#endif
\ No newline at end of file
......@@ -25,8 +25,8 @@ void SaveLoad::displayScores(){
void SaveLoad::userInputNameMakeScore(int intScore){
char userNameInput[3];
cout << "Please enter a 3 character user name\n";
do{
cout << "Please enter a 3 character user name\n";
try{
cin >> userNameInput;
if(strlen(userNameInput) != 3){
......@@ -41,10 +41,7 @@ void SaveLoad::userInputNameMakeScore(int intScore){
}while(true);
Scores*scorePtr = nullptr;
scorePtr = new Scores(userNameInput, intScore);
pushBackNewScoreAndSort(*scorePtr);
delete scorePtr;
pushBackNewScoreAndSort(Scores(userNameInput, intScore));
}
\ No newline at end of file
......@@ -29,7 +29,7 @@ int main(){
// second.displayScores();
second.userInputNameMakeScore(1000);
second.userInputNameMakeScore(9999);
second.updateFile();
second.displayScores();
......
......@@ -2,10 +2,15 @@ NAME SCORE
nge 654346
vfd 45365
cdn 21474
bbb 9999
vfr 9999
ddd 9999
Kyl 9999
vfd 4636
vev 4536
DVS 3423
goo 1000
vfd 1000
efd 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