Commit 06460642 authored by Konrad McClure's avatar Konrad McClure

Minor additions and fixes

parent 85ee009a
#include <iostream>
#include "BaseMenuState.h"
#include <string>
#include <fstream>
#include <streambuf>
using namespace std;
CBaseMenuState CBaseMenuState::m_BaseMenuState;
void CBaseMenuState::Init()
{
// Load in main menu title
// ifstream fs();
// fs.seekg(0, ios::end);
// menuTitle.reserve(fs.tellg());
// fs.seekg(0, ios::beg);
// menuTitle.assign((istreambuf_iterator<char>(fs)),
// istreambuf_iterator<char>());
// Add menu options
menuOptions.push_back("Play Game");
menuOptions.push_back("High Scores");
menuOptions.push_back("Return to Main Menu");
// Set name for debugging
stateName = "basemenu";
// Set first input and draw the menu
input = ' ';
Draw(nullptr);
}
void CBaseMenuState::Pause()
{
}
void CBaseMenuState::Resume()
{
input = 0;
menuPos = 0;
}
void CBaseMenuState::Cleanup()
{
}
void CBaseMenuState::HandleEvents(CGameEngine* game)
{
while (game->newInput == false)
{
input = ' ';
}
input = game->input;
game->newInput = false;
}
void CBaseMenuState::Update(CGameEngine* game)
{
switch(input)
{
case 'w':
menuPos--;
break;
case 's':
menuPos++;
break;
case 'd':
{
switch (menuPos)
{
case 0: //Play Game
//game->PushState(CGameState::Instance());
break;
case 1: //Snake
//game->PushState(CHighScore::Instance());
break;
case 2: //Quit
game->PopState();
break;
}
break;
}
default:
break;
}
if (menuPos < 0)
{
menuPos = 0;
}
if (menuPos >= menuOptions.size())
{
menuPos = menuOptions.size() - 1;
}
}
void CBaseMenuState::Draw(CGameEngine* game)
{
system("stty cooked");
cout << menuTitle << endl;
for (int i = 0; i < menuOptions.size(); i++)
{
if (i == menuPos)
{
cout << " * " << menuOptions.at(i) << endl;
}
else
{
cout << " " << menuOptions.at(i) << endl;
}
}
cout << "\n\n\n" << "Press w and s to move up and down, d to select" << endl;
system("stty raw");
}
#ifndef BASEMENUSTATE_H
#define BASEMENUSTATE_H
#include "GameState.h"
#include <iostream>
#include <string>
class CBaseMenuState : public CGameState
{
public:
void Init();
void Cleanup();
void Pause();
void Resume();
void HandleEvents(CGameEngine* game);
void Update(CGameEngine* game);
void Draw(CGameEngine* game);
static CBaseMenuState* Instance() { return &m_BaseMenuState; }
protected:
CBaseMenuState() {}
private:
static CBaseMenuState m_BaseMenuState;
char input;
int menuPos;
string menuTitle;
vector<string> menuOptions;
};
#endif
\ No newline at end of file
......@@ -107,9 +107,12 @@ void CSnakeGameOverState::Draw(CGameEngine* game)
if (scoreSet)
{
cout << endl << "Your score:" << endl;
highscores.useRankFindScore(userRank);
}
cout << "Press x to return to main menu" << endl;
highscores.updateFile("../SaveLoad/snakedata.txt");
system("stty raw");
......
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