Commit 1baffa59 authored by Konrad McClure's avatar Konrad McClure
Browse files

Added the 2048GameState and tested it

parent e2b9a33f
......@@ -4,12 +4,12 @@
using namespace std;
int main() {
// int main() {
int highScore = 2048;
Game2048 game(4,highScore);
game.playGame();
// int highScore = 2048;
// Game2048 game(4,highScore);
// game.playGame();
return 0;
}
// return 0;
// }
#include <iostream>
#include "2048GameState.h"
C2048GameState C2048GameState::m_2048GameState;
void C2048GameState::Init()
{
cout << " 2048GameState Init" << endl;
int highScore = 1000;
game2048 = new Game2048(4, highScore);
game2048->testInit();
stateName = "2048GameState";
}
void C2048GameState::Pause()
{
cout << " 2048GameState Pause" << endl;
}
void C2048GameState::Resume()
{
cout << " 2048GameState Resume" << endl;
}
void C2048GameState::Cleanup()
{
cout << " 2048GameState Cleanup" << endl;
delete game2048;
game2048 = nullptr;
}
void C2048GameState::HandleEvents(CGameEngine* game)
{
cout << " 2048GameState Handle Events" << endl;
// switch (runtimes)
// {
// case 0:
// input = 'd';
// break;
// case 1:
// input = 'a';
// break;
// case 2:
// input = 'w';
// break;
// case 3:
// input = 'd';
// break;
// case 4:
// input = 's';
// break;
// case 5:
// game->Quit();
// break;
// }
cin >> input;
if (input == 'q')
{
game->Quit();
}
runtimes++;
}
void C2048GameState::Update(CGameEngine* game)
{
cout << " 2048GameState Update" << endl;
game2048->Shift(input);
}
void C2048GameState::Draw(CGameEngine* game)
{
cout << " 2048GameState Draw" << endl;
game2048->Draw();
}
#ifndef C2048GAMESTATE_H
#define C2048GAMESTATE_H
#include "GameState.h"
#include "../2048/Game2048.h"
#include <iostream>
class C2048GameState : public CGameState
{
public:
void Init();
void Cleanup();
void Pause();
void Resume();
void HandleEvents(CGameEngine* game);
void Update(CGameEngine* game);
void Draw(CGameEngine* game);
static C2048GameState* Instance() { return &m_2048GameState; }
protected:
C2048GameState() {}
private:
static C2048GameState m_2048GameState;
Game2048* game2048 = nullptr;
char input;
int runtimes = 0;
};
#endif
\ No newline at end of file
#include <iostream>
#include "TestState1.h"
#include "TestState2.h"
#include "TestState3.h"
// #include "TestState2.h"
// #include "TestState3.h"
#include "2048GameState.h"
CTestState1 CTestState1::m_TestState1;
......@@ -36,15 +37,7 @@ void CTestState1::Update(CGameEngine* game)
{
cout << " TestState1 Update" << endl;
if (runtimes == 2)
{
game->PushState(CTestState3::Instance());
}
if (runtimes >= 3)
{
game->ChangeState(CTestState2::Instance());
}
game->ChangeState(C2048GameState::Instance());
}
void CTestState1::Draw(CGameEngine* game)
......
Supports Markdown
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