Commit 9b0c6d91 authored by Konrad McClure's avatar Konrad McClure

Added Snake into the main engine

parent 48429465
......@@ -25,7 +25,7 @@ void C2048GameOverState::Init()
stateName = "2048gameover";
// Read in score data
highscores.LoadContainers();
highscores.LoadContainers("../SaveLoad/2048Data.txt");
isInit = true;
}
......@@ -99,7 +99,7 @@ void C2048GameOverState::Draw(CGameEngine* game)
highscores.displayScores();
highscores.updateFile();
highscores.updateFile("../SaveLoad/2048Data.txt");
system("stty raw");
}
......
......@@ -2,7 +2,7 @@
#define C2048GAMEOVERSTATE_H
#include "GameState.h"
#include "../Testings/SaveLoad/SL2048.h"
#include "../SaveLoad/SL2048.h"
#include <iostream>
#include <string>
......
......@@ -25,7 +25,7 @@ void C2048ScoreState::Init()
stateName = "2048score";
// Read in score data
highscores.LoadContainers();
highscores.LoadContainers("../SaveLoad/2048Data.txt");
isInit = true;
}
......
......@@ -5,13 +5,13 @@
void CGameEngine::Init()
{
cout << "Game Engine: Initializing" << endl;
// cout << "Game Engine: Initializing" << endl;
m_running = true;
}
void CGameEngine::Cleanup()
{
cout << "Game Engine: Cleanup" << endl;
// cout << "Game Engine: Cleanup" << endl;
// Cleanup the states
while (!states.empty())
......@@ -25,7 +25,7 @@ void CGameEngine::Cleanup()
// Operations with the gamestate stack
void CGameEngine::ChangeState(CGameState* state)
{
cout << "Game Engine: Changing to state " << state->GetName() << endl;
// cout << "Game Engine: Changing to state " << state->GetName() << endl;
// Pop and cleanup the current state
if (!states.empty())
......@@ -41,7 +41,7 @@ void CGameEngine::ChangeState(CGameState* state)
void CGameEngine::PushState(CGameState* state)
{
cout << "Game Engine: Pausing " << states.back()->GetName() << endl;
// cout << "Game Engine: Pausing " << states.back()->GetName() << endl;
// Pause the current state
if (!states.empty())
......@@ -49,7 +49,7 @@ void CGameEngine::PushState(CGameState* state)
states.back()->Pause();
}
cout << "Game Engine: Pushing " << state->GetName() << endl;
// cout << "Game Engine: Pushing " << state->GetName() << endl;
// Push new state to stack and initialize it
states.push_back(state);
......@@ -58,7 +58,7 @@ void CGameEngine::PushState(CGameState* state)
void CGameEngine::PopState()
{
cout << "Game Engine: Popping " << states.back()->GetName() << endl;
// cout << "Game Engine: Popping " << states.back()->GetName() << endl;
// Pause the current state
if (!states.empty())
......@@ -70,7 +70,7 @@ void CGameEngine::PopState()
// Check if there was a paused state and if so, resume
if (!states.empty())
{
cout << "Game Engine: Resuming " << states.back()->GetName() << endl;
// cout << "Game Engine: Resuming " << states.back()->GetName() << endl;
states.back()->Resume();
}
}
......
g++ -std=c++11 -pthread *.cpp ../2048/*.cpp ../Testings/Snake/ReadInput.cpp ../Testings/SaveLoad/SaveLoad.cpp ../Testings/SaveLoad/SL2048.cpp && ./a.out
\ No newline at end of file
g++ -std=c++11 -pthread *.cpp ../2048/*.cpp ../Snake/Threads.cpp ../Snake/Snake.cpp ../Snake/ReadInput.cpp ../SaveLoad/SaveLoad.cpp ../SaveLoad/SL2048.cpp && ./a.out
\ No newline at end of file
#include <iostream>
#include "SnakeGameState.h"
#include "2048GameState.h"
CSnakeGameState CSnakeGameState::m_SnakeGameState;
void CSnakeGameState::Init()
{
// cout << " SnakeState Init" << endl;
// stateName = "SnakeState";
srand(time(NULL));
BrdSet = new Snake;
BrdSet->newBody();
input = 0;
}
void CSnakeGameState::Pause()
......@@ -27,18 +28,27 @@ void CSnakeGameState::Cleanup()
void CSnakeGameState::HandleEvents(CGameEngine* game)
{
// cout << " SnakeState Handle Events" << endl;
waitTime.Sleep(1);
}
void CSnakeGameState::Update(CGameEngine* game)
{
// cout << " SnakeState Update" << endl;
while (game->input != 'd') {}
game->PopState();
if (game->newInput)
{
input = game->input;
}
BrdSet->movement(input);
}
void CSnakeGameState::Draw(CGameEngine* game)
{
// cout << " SnakeState Draw" << endl;
system("stty cooked");
if (!(BrdSet->draw()))
{
game->PopState();
}
system("stty raw");
}
......@@ -2,6 +2,8 @@
#define SNAKEGAMESTATE_H
#include "GameState.h"
#include "../Snake/Threads.h"
#include "../Snake/Snake.h"
#include <iostream>
class CSnakeGameState : public CGameState
......@@ -24,6 +26,9 @@ class CSnakeGameState : public CGameState
private:
static CSnakeGameState m_SnakeGameState;
Snake* BrdSet;
Thread waitTime;
char input;
};
#endif
\ No newline at end of file
......@@ -81,7 +81,7 @@ void CSnakeMenuState::Update(CGameEngine* game)
switch (menuPos)
{
case 0: //Play Game
//game->PushState(CSnakeGameState::Instance());
game->PushState(CSnakeGameState::Instance());
break;
case 1: //Snake
......
#include "GameEngine.h"
#include "MainMenuState.h"
#include "../Testings/Snake/ReadInput.h"
#include "../Snake/ReadInput.h"
#include <thread>
#include <iostream>
......
......@@ -11,3 +11,5 @@ BND 6564
CDS 6544
NKV 5453
KAL 2434
KOM 1404
POP 636
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