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