Commit 830acdd0 authored by Konrad McClure's avatar Konrad McClure

Added TestState2 and got the game engine to sucessfully swtich to another...

Added TestState2 and got the game engine to sucessfully swtich to another state. Next is to add a TestState3 that opens on top of TestState1, pausing it, and then popping TestState3 and resuming TestState1 before going to TestState2
parent e4410d1b
#include <iostream>
#include "TestState.h"
CTestState CTestState::m_TestState;
void CTestState::Init()
{
cout << " TestState Init" << endl;
}
void CTestState::Pause()
{
cout << " TestState Pause" << endl;
}
void CTestState::Resume()
{
cout << " TestState Resume" << endl;
}
void CTestState::Cleanup()
{
cout << " TestState Cleanup" << endl;
}
void CTestState::HandleEvents(CGameEngine* game)
{
cout << " TestState Handle Events" << endl;
runtimes++;
}
void CTestState::Update(CGameEngine* game)
{
cout << " TestState Update" << endl;
if (runtimes >= 3)
{
game->Quit();
}
}
void CTestState::Draw(CGameEngine* game)
{
cout << " TestState Draw" << endl;
}
#include <iostream>
#include "TestState1.h"
#include "TestState2.h"
CTestState1 CTestState1::m_TestState1;
void CTestState1::Init()
{
cout << " TestState1 Init" << endl;
}
void CTestState1::Pause()
{
cout << " TestState1 Pause" << endl;
}
void CTestState1::Resume()
{
cout << " TestState1 Resume" << endl;
}
void CTestState1::Cleanup()
{
cout << " TestState1 Cleanup" << endl;
}
void CTestState1::HandleEvents(CGameEngine* game)
{
cout << " TestState1 Handle Events" << endl;
runtimes++;
}
void CTestState1::Update(CGameEngine* game)
{
cout << " TestState1 Update" << endl;
if (runtimes >= 3)
{
game->ChangeState(CTestState2::Instance());
}
}
void CTestState1::Draw(CGameEngine* game)
{
cout << " TestState1 Draw" << endl;
}
#ifndef TESTSTATE_H
#define TESTSTATE_H
#ifndef TESTSTATE1_H
#define TESTSTATE1_H
#include "GameState.h"
#include <iostream>
class CTestState : public CGameState
class CTestState1 : public CGameState
{
public:
void Init();
......@@ -17,14 +17,14 @@ class CTestState : public CGameState
void Update(CGameEngine* game);
void Draw(CGameEngine* game);
static CTestState* Instance() { return &m_TestState; }
static CTestState1* Instance() { return &m_TestState1; }
protected:
CTestState() {}
CTestState1() {}
private:
static CTestState m_TestState;
string stateName = "TestState";
static CTestState1 m_TestState1;
string stateName = "TestState1";
int runtimes = 0;
};
......
#include <iostream>
#include "TestState2.h"
CTestState2 CTestState2::m_TestState2;
void CTestState2::Init()
{
cout << " TestState2 Init" << endl;
}
void CTestState2::Pause()
{
cout << " TestState2 Pause" << endl;
}
void CTestState2::Resume()
{
cout << " TestState2 Resume" << endl;
}
void CTestState2::Cleanup()
{
cout << " TestState2 Cleanup" << endl;
}
void CTestState2::HandleEvents(CGameEngine* game)
{
cout << " TestState2 Handle Events" << endl;
runtimes++;
}
void CTestState2::Update(CGameEngine* game)
{
cout << " TestState2 Update" << endl;
if (runtimes >= 3)
{
game->Quit();
}
}
void CTestState2::Draw(CGameEngine* game)
{
cout << " TestState2 Draw" << endl;
}
#ifndef TESTSTATE2_H
#define TESTSTATE2_H
#include "GameState.h"
#include <iostream>
class CTestState2 : public CGameState
{
public:
void Init();
void Cleanup();
void Pause();
void Resume();
void HandleEvents(CGameEngine* game);
void Update(CGameEngine* game);
void Draw(CGameEngine* game);
static CTestState2* Instance() { return &m_TestState2; }
protected:
CTestState2() {}
private:
static CTestState2 m_TestState2;
string stateName = "TestState2";
int runtimes = 0;
};
#endif
\ No newline at end of file
#include "GameEngine.h"
#include "TestState.h"
#include "TestState1.h"
int main()
{
......@@ -7,7 +7,7 @@ int main()
game.Init();
game.ChangeState(CTestState::Instance());
game.ChangeState(CTestState1::Instance());
while (game.isRunning())
{
......
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