Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
1
142GameCenter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nelson Phillips
142GameCenter
Commits
9b0c6d91
Commit
9b0c6d91
authored
Mar 14, 2019
by
Konrad McClure
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Snake into the main engine
parent
48429465
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
39 additions
and
22 deletions
+39
-22
GameEngine/2048GameOverState.cpp
GameEngine/2048GameOverState.cpp
+2
-2
GameEngine/2048GameOverState.h
GameEngine/2048GameOverState.h
+1
-1
GameEngine/2048ScoreState.cpp
GameEngine/2048ScoreState.cpp
+1
-1
GameEngine/GameEngine.cpp
GameEngine/GameEngine.cpp
+7
-7
GameEngine/RunGame.sh
GameEngine/RunGame.sh
+1
-1
GameEngine/SnakeGameState.cpp
GameEngine/SnakeGameState.cpp
+18
-8
GameEngine/SnakeGameState.h
GameEngine/SnakeGameState.h
+5
-0
GameEngine/SnakeMenuState.cpp
GameEngine/SnakeMenuState.cpp
+1
-1
GameEngine/enginetest.cpp
GameEngine/enginetest.cpp
+1
-1
SaveLoad/2048Data.txt
SaveLoad/2048Data.txt
+2
-0
No files found.
GameEngine/2048GameOverState.cpp
View file @
9b0c6d91
...
@@ -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"
);
}
}
...
...
GameEngine/2048GameOverState.h
View file @
9b0c6d91
...
@@ -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>
...
...
GameEngine/2048ScoreState.cpp
View file @
9b0c6d91
...
@@ -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
;
}
}
...
...
GameEngine/GameEngine.cpp
View file @
9b0c6d91
...
@@ -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
();
}
}
}
}
...
...
GameEngine/RunGame.sh
View file @
9b0c6d91
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
GameEngine/SnakeGameState.cpp
View file @
9b0c6d91
#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"
);
}
}
GameEngine/SnakeGameState.h
View file @
9b0c6d91
...
@@ -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
GameEngine/SnakeMenuState.cpp
View file @
9b0c6d91
...
@@ -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
...
...
GameEngine/enginetest.cpp
View file @
9b0c6d91
#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>
...
...
SaveLoad/2048Data.txt
View file @
9b0c6d91
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment