Commit e57ab6cc authored by Kyle Malaguit's avatar Kyle Malaguit

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

parents 26772a20 fcbdfbab
#include <iostream>
#include "2048MenuState.h"
#include "2048GameState.h"
#include <string>
#include <fstream>
#include <streambuf>
using namespace std;
C2048MenuState C2048MenuState::m_2048MenuState;
void C2048MenuState::Init()
{
if (!isInit)
{
// Load in main menu title
ifstream fs("2048menu.txt");
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 = "2048menu";
// Set that is has been initialized
isInit = true;
}
// Set first input and draw the menu
input = ' ';
Draw(nullptr);
}
void C2048MenuState::Pause()
{
}
void C2048MenuState::Resume()
{
input = 0;
menuPos = 0;
}
void C2048MenuState::Cleanup()
{
}
void C2048MenuState::HandleEvents(CGameEngine* game)
{
while (game->newInput == false)
{
input = ' ';
}
input = game->input;
game->newInput = false;
}
void C2048MenuState::Update(CGameEngine* game)
{
switch(input)
{
case 'w':
menuPos--;
break;
case 's':
menuPos++;
break;
case 'd':
{
switch (menuPos)
{
case 0: //Play Game
game->PushState(C2048GameState::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 C2048MenuState::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 TESTSTATE2_H
#define TESTSTATE2_H
#ifndef C2048MENUSTATE_H
#define C2048MENUSTATE_H
#include "GameState.h"
#include <iostream>
#include <string>
class CTestState2 : public CGameState
class C2048MenuState : public CGameState
{
public:
void Init();
......@@ -17,14 +18,18 @@ class CTestState2 : public CGameState
void Update(CGameEngine* game);
void Draw(CGameEngine* game);
static CTestState2* Instance() { return &m_TestState2; }
static C2048MenuState* Instance() { return &m_2048MenuState; }
protected:
CTestState2() {}
C2048MenuState() {}
private:
static CTestState2 m_TestState2;
int runtimes = 0;
static C2048MenuState m_2048MenuState;
char input;
int menuPos;
string menuTitle;
vector<string> menuOptions;
bool isInit = false;
};
#endif
\ No newline at end of file
==========================
|| ___ ___ _ _ ___ ||
|| |__ \ / _ \| || | / _ \ ||
|| ) | | | | || || (_) | ||
|| / /| | | |__ _> _ < ||
|| / /_| |_| | | || (_) | ||
|| |____|\___/ |_| \___/ ||
|| ||
==========================
\ No newline at end of file
#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 SNAKESTATE_H
#define SNAKESTATE_H
#ifndef BASEMENUSTATE_H
#define BASEMENUSTATE_H
#include "GameState.h"
#include <iostream>
#include <string>
class CSnakeState : public CGameState
class CBaseMenuState : public CGameState
{
public:
void Init();
......@@ -17,13 +18,17 @@ class CSnakeState : public CGameState
void Update(CGameEngine* game);
void Draw(CGameEngine* game);
static CSnakeState* Instance() { return &m_SnakeState; }
static CBaseMenuState* Instance() { return &m_BaseMenuState; }
protected:
CSnakeState() {}
CBaseMenuState() {}
private:
static CSnakeState m_SnakeState;
static CBaseMenuState m_BaseMenuState;
char input;
int menuPos;
string menuTitle;
vector<string> menuOptions;
};
#endif
\ No newline at end of file
#include <iostream>
#include "MainMenuState.h"
#include "2048GameState.h"
#include "SnakeState.h"
#include "2048MenuState.h"
#include "SnakeMenuState.h"
#include <string>
#include <fstream>
......@@ -76,11 +76,11 @@ void CMainMenuState::Update(CGameEngine* game)
switch (menuPos)
{
case 0: //2048
game->PushState(C2048GameState::Instance());
game->PushState(C2048MenuState::Instance());
break;
case 1: //Snake
game->PushState(CSnakeState::Instance());
game->PushState(CSnakeMenuState::Instance());
break;
case 2: //Quit
......
g++ -std=c++11 -pthread *.cpp ../2048/*.cpp ../Testings/Snake/ReadInput.cpp
./a.out
\ No newline at end of file
g++ -std=c++11 -pthread *.cpp ../2048/*.cpp ../Testings/Snake/ReadInput.cpp && ./a.out
\ No newline at end of file
#include <iostream>
#include "SnakeState.h"
// #include "TestState2.h"
// #include "TestState3.h"
#include "SnakeGameState.h"
#include "2048GameState.h"
CSnakeState CSnakeState::m_SnakeState;
CSnakeGameState CSnakeGameState::m_SnakeGameState;
void CSnakeState::Init()
void CSnakeGameState::Init()
{
// cout << " SnakeState Init" << endl;
// stateName = "SnakeState";
}
void CSnakeState::Pause()
void CSnakeGameState::Pause()
{
// cout << " SnakeState Pause" << endl;
}
void CSnakeState::Resume()
void CSnakeGameState::Resume()
{
// cout << " SnakeState Resume" << endl;
}
void CSnakeState::Cleanup()
void CSnakeGameState::Cleanup()
{
// cout << " SnakeState Cleanup" << endl;
}
void CSnakeState::HandleEvents(CGameEngine* game)
void CSnakeGameState::HandleEvents(CGameEngine* game)
{
// cout << " SnakeState Handle Events" << endl;
}
void CSnakeState::Update(CGameEngine* game)
void CSnakeGameState::Update(CGameEngine* game)
{
// cout << " SnakeState Update" << endl;
while (game->input != 'd') {}
game->PopState();
}
void CSnakeState::Draw(CGameEngine* game)
void CSnakeGameState::Draw(CGameEngine* game)
{
// cout << " SnakeState Draw" << endl;
}
......
#ifndef TESTSTATE3_H
#define TESTSTATE3_H
#ifndef SNAKEGAMESTATE_H
#define SNAKEGAMESTATE_H
#include "GameState.h"
#include <iostream>
class CTestState3 : public CGameState
class CSnakeGameState : public CGameState
{
public:
void Init();
......@@ -17,14 +17,13 @@ class CTestState3 : public CGameState
void Update(CGameEngine* game);
void Draw(CGameEngine* game);
static CTestState3* Instance() { return &m_TestState3; }
static CSnakeGameState* Instance() { return &m_SnakeGameState; }
protected:
CTestState3() {}
CSnakeGameState() {}
private:
static CTestState3 m_TestState3;
int runtimes = 0;
static CSnakeGameState m_SnakeGameState;
};
#endif
\ No newline at end of file
#include <iostream>
#include "SnakeMenuState.h"
#include "SnakeGameState.h"
#include <string>
#include <fstream>
#include <streambuf>
using namespace std;
CSnakeMenuState CSnakeMenuState::m_SnakeMenuState;
void CSnakeMenuState::Init()
{
if (!isInit)
{
// Load in main menu title
ifstream fs("snakemenu.txt");
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 = "snakemenu";
// Set that it has been initialized
isInit = true;
}
// Set first input and draw the menu
input = ' ';
Draw(nullptr);
}
void CSnakeMenuState::Pause()
{
}
void CSnakeMenuState::Resume()
{
input = 0;
menuPos = 0;
}
void CSnakeMenuState::Cleanup()
{
}
void CSnakeMenuState::HandleEvents(CGameEngine* game)
{
while (game->newInput == false)
{
input = ' ';
}
input = game->input;
game->newInput = false;
}
void CSnakeMenuState::Update(CGameEngine* game)
{
switch(input)
{
case 'w':
menuPos--;
break;
case 's':
menuPos++;
break;
case 'd':
{
switch (menuPos)
{
case 0: //Play Game
//game->PushState(CSnakeGameState::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 CSnakeMenuState::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 TESTSTATE1_H
#define TESTSTATE1_H
#ifndef SNAKEMENUSTATE_H
#define SNAKEMENUSTATE_H
#include "GameState.h"
#include <iostream>
#include <string>
class CTestState1 : public CGameState
class CSnakeMenuState : public CGameState
{
public:
void Init();
......@@ -17,14 +18,18 @@ class CTestState1 : public CGameState
void Update(CGameEngine* game);
void Draw(CGameEngine* game);
static CTestState1* Instance() { return &m_TestState1; }
static CSnakeMenuState* Instance() { return &m_SnakeMenuState; }
protected:
CTestState1() {}
CSnakeMenuState() {}
private:
static CTestState1 m_TestState1;
int runtimes = 0;
static CSnakeMenuState m_SnakeMenuState;
char input;