Commit 962b4c8a authored by Konrad McClure's avatar Konrad McClure

Added score entering to game over screen

parent 7c6f862c
......@@ -13,6 +13,7 @@ class Game2048 {
void Shift(char input);
void testInit(){*board = { {4,0,0,2}, {4,2,0,0}, {4,4,0,0}, {4,4,0,0}};}
bool addNumber();
int getScore() {return score;}
......
NAME SCORE
Mal 54234
BVB 9240
BND 6564
CDS 6544
NKV 5453
KAL 2434
Mal 54234
BVB 9240
ass 532
WEB 128
qwe 128
mop 128
ddd 76
......@@ -13,7 +13,7 @@ void C2048GameOverState::Init()
if (!isInit)
{
// Load in main menu title
ifstream fs("2048ScoreTitle.txt");
ifstream fs("2048GameOverTitle.txt");
fs.seekg(0, ios::end);
menuTitle.reserve(fs.tellg());
fs.seekg(0, ios::beg);
......@@ -22,7 +22,7 @@ void C2048GameOverState::Init()
istreambuf_iterator<char>());
// Set name for debugging
stateName = "2048score";
stateName = "2048gameover";
// Read in score data
highscores.LoadContainers();
......@@ -32,6 +32,7 @@ void C2048GameOverState::Init()
// Set first input and draw the menu
input = ' ';
scoreSet = false;
Draw(nullptr);
}
......@@ -52,25 +53,39 @@ void C2048GameOverState::Cleanup()
void C2048GameOverState::HandleEvents(CGameEngine* game)
{
while (game->newInput == false)
if (!scoreSet)
{
input = ' ';
system("stty cooked");
cout << "Press enter to continue" << endl;
game->inputPause = true;
while (game->newInput == false) {}
highscores.userInputNameMakeScore(game->GetScore());
scoreSet = true;
system("stty raw");
game->inputPause = false;
}
else
{
while (game->newInput == false) {}
input = game->input;
game->newInput = false;
}
}
void C2048GameOverState::Update(CGameEngine* game)
{
switch(input)
if (scoreSet)
{
case 'x':
// Erase Scores
break;
default:
game->PopState();
break;
switch(input)
{
case 'x':
game->PopState();
break;
default:
break;
}
}
}
......@@ -79,8 +94,13 @@ void C2048GameOverState::Draw(CGameEngine* game)
system("stty cooked");
cout << menuTitle << endl;
cout << "\n\n";
highscores.displayScores();
highscores.updateFile();
system("stty raw");
}
......@@ -19,7 +19,7 @@ class C2048GameOverState : public CGameState
void Update(CGameEngine* game);
void Draw(CGameEngine* game);
static C2048GameOverState* Instance() { return &m_2048ScoreState; }
static C2048GameOverState* Instance() { return &m_2048GameOverState; }
protected:
C2048GameOverState() {}
......@@ -30,6 +30,7 @@ class C2048GameOverState : public CGameState
string menuTitle;
SL2048 highscores;
bool isInit = false;
bool scoreSet = false;
};
......
=======================================================
|| _____ ____ ||
|| / ____| / __ \ ||
|| | | __ __ _ _ __ ___ ___ | | | |_ _____ _ __ ||
|| | | |_ |/ _` | '_ ` _ \ / _ \ | | | \ \ / / _ \ '__| ||
|| | |__| | (_| | | | | | | __/ | |__| |\ V / __/ | ||
|| \_____|\__,_|_| |_| |_|\___| \____/ \_/ \___|_| ||
|| ||
=======================================================
#include <iostream>
#include "2048GameState.h"
#include "2048GameOverState.h"
C2048GameState C2048GameState::m_2048GameState;
......@@ -84,8 +85,11 @@ void C2048GameState::Update(CGameEngine* game)
// cout << " 2048GameState Update" << endl;
game2048->Shift(input);
if (!game2048->addNumber()) {
game->PopState();
if (!game2048->addNumber())
{
// Push the score to the engine for temporary keeping
game->HoldScore(game2048->getScore());
game->ChangeState(C2048GameOverState::Instance());
}
}
......
......@@ -95,16 +95,4 @@ void CGameEngine::Draw()
cout << "\e[2J\e[0;0H";
states.back()->Draw(this);
// system("stty raw");
}
void CGameEngine::PushInput(char input)
{
inputQueue.push(input);
}
char CGameEngine::PopInput()
{
char input = inputQueue.front();
inputQueue.pop();
return input;
}
\ No newline at end of file
......@@ -31,12 +31,15 @@ class CGameEngine
void PushInput(char input);
char PopInput();
void HoldScore(int score) { this->score = score; }
int GetScore() { return score; }
bool newInput = false;
char input;
bool inputPause = false;
private:
// Gamestate Stack
vector<CGameState*> states;
queue<char> inputQueue;
int score;
// Currently running bool (false will initiate cleanup)
bool m_running;
......
......@@ -50,8 +50,10 @@ void MainInput(CGameEngine* game)
while (game->isRunning())
{
// game.PushInput(reader.collectInput());
game->input = reader.collectInput();
game->newInput = true;
if (!game->inputPause)
{
game->input = reader.collectInput();
game->newInput = true;
}
}
}
\ No newline at end of file
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