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
caa566d6
Commit
caa566d6
authored
Mar 14, 2019
by
Konrad McClure
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
THE GAME IS LIKE, KINDA DONE
parent
8f98ca19
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
349 additions
and
63 deletions
+349
-63
GameEngine/RunGame.sh
GameEngine/RunGame.sh
+1
-1
GameEngine/SnakeGameOverState.cpp
GameEngine/SnakeGameOverState.cpp
+108
-0
GameEngine/SnakeGameOverState.h
GameEngine/SnakeGameOverState.h
+37
-0
GameEngine/SnakeGameOverTitle.txt
GameEngine/SnakeGameOverTitle.txt
+11
-0
GameEngine/SnakeGameState.cpp
GameEngine/SnakeGameState.cpp
+17
-10
GameEngine/SnakeGameState.h
GameEngine/SnakeGameState.h
+2
-2
GameEngine/SnakeMenuState.cpp
GameEngine/SnakeMenuState.cpp
+3
-1
GameEngine/SnakeScoreState.cpp
GameEngine/SnakeScoreState.cpp
+86
-0
GameEngine/SnakeScoreState.h
GameEngine/SnakeScoreState.h
+36
-0
SaveLoad/2048Data.txt
SaveLoad/2048Data.txt
+3
-0
SaveLoad/snakedata.txt
SaveLoad/snakedata.txt
+14
-18
Snake/Snake.cpp
Snake/Snake.cpp
+6
-7
Snake/Snake.h
Snake/Snake.h
+25
-24
No files found.
GameEngine/RunGame.sh
View file @
caa566d6
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
g++
-std
=
c++11
-pthread
*
.cpp ../2048/
*
.cpp ../Snake/Threads.cpp ../Snake/Snake.cpp ../Snake/ReadInput.cpp ../SaveLoad/SaveLoad.cpp ../SaveLoad/SL2048.cpp ../SaveLoad/SLSnake.cpp
&&
./a.out
\ No newline at end of file
\ No newline at end of file
GameEngine/SnakeGameOverState.cpp
0 → 100644
View file @
caa566d6
#include <iostream>
#include "SnakeGameOverState.h"
#include <string>
#include <fstream>
#include <streambuf>
using
namespace
std
;
CSnakeGameOverState
CSnakeGameOverState
::
m_SnakeGameOverState
;
void
CSnakeGameOverState
::
Init
()
{
if
(
!
isInit
)
{
// Load in main menu title
ifstream
fs
(
"SnakeGameOverTitle.txt"
);
fs
.
seekg
(
0
,
ios
::
end
);
menuTitle
.
reserve
(
fs
.
tellg
());
fs
.
seekg
(
0
,
ios
::
beg
);
menuTitle
.
assign
((
istreambuf_iterator
<
char
>
(
fs
)),
istreambuf_iterator
<
char
>
());
// Set name for debugging
stateName
=
"Snakegameover"
;
// Read in score data
highscores
.
LoadContainers
(
"../SaveLoad/snakedata.txt"
);
isInit
=
true
;
}
// Set first input and draw the menu
input
=
0
;
scoreSet
=
false
;
Draw
(
nullptr
);
}
void
CSnakeGameOverState
::
Pause
()
{
}
void
CSnakeGameOverState
::
Resume
()
{
input
=
0
;
}
void
CSnakeGameOverState
::
Cleanup
()
{
}
void
CSnakeGameOverState
::
HandleEvents
(
CGameEngine
*
game
)
{
if
(
!
scoreSet
)
{
system
(
"stty cooked"
);
cout
<<
"Press enter to continue"
<<
endl
;
game
->
newInput
=
false
;
game
->
inputPause
=
true
;
while
(
game
->
newInput
==
false
)
{}
highscores
.
userInputNameMakeScore
(
game
->
GetScore
());
scoreSet
=
true
;
system
(
"stty raw"
);
game
->
inputPause
=
false
;
}
else
{
while
(
game
->
newInput
==
false
)
{}
input
=
game
->
input
;
game
->
newInput
=
false
;
}
}
void
CSnakeGameOverState
::
Update
(
CGameEngine
*
game
)
{
if
(
scoreSet
)
{
switch
(
input
)
{
case
'x'
:
game
->
HoldScore
(
0
);
// Reset the engine's score value
game
->
PopState
();
break
;
default:
break
;
}
}
}
void
CSnakeGameOverState
::
Draw
(
CGameEngine
*
game
)
{
system
(
"stty cooked"
);
cout
<<
menuTitle
<<
endl
;
cout
<<
"
\n\n
"
;
highscores
.
displayScores
();
highscores
.
updateFile
(
"../SaveLoad/snakedata.txt"
);
system
(
"stty raw"
);
}
GameEngine/SnakeGameOverState.h
0 → 100644
View file @
caa566d6
#ifndef CSNAKEGAMEOVERSTATE_H
#define CSNAKEGAMEOVERSTATE_H
#include "GameState.h"
#include "../SaveLoad/SLSnake.h"
#include <iostream>
#include <string>
class
CSnakeGameOverState
:
public
CGameState
{
public:
void
Init
();
void
Cleanup
();
void
Pause
();
void
Resume
();
void
HandleEvents
(
CGameEngine
*
game
);
void
Update
(
CGameEngine
*
game
);
void
Draw
(
CGameEngine
*
game
);
static
CSnakeGameOverState
*
Instance
()
{
return
&
m_SnakeGameOverState
;
}
protected:
CSnakeGameOverState
()
{}
private:
static
CSnakeGameOverState
m_SnakeGameOverState
;
char
input
;
string
menuTitle
;
SLSnake
highscores
;
bool
isInit
=
false
;
bool
scoreSet
=
false
;
};
#endif
GameEngine/SnakeGameOverTitle.txt
0 → 100644
View file @
caa566d6
=======================================================
|| _____ ____ ||
|| / ____| / __ \ ||
|| | | __ __ _ _ __ ___ ___ | | | |_ _____ _ __ ||
|| | | |_ |/ _` | '_ ` _ \ / _ \ | | | \ \ / / _ \ '__| ||
|| | |__| | (_| | | | | | | __/ | |__| |\ V / __/ | ||
|| \_____|\__,_|_| |_| |_|\___| \____/ \_/ \___|_| ||
|| ||
=======================================================
GameEngine/SnakeGameState.cpp
View file @
caa566d6
#include <iostream>
#include <iostream>
#include "SnakeGameState.h"
#include "SnakeGameState.h"
#include "SnakeGameOverState.h"
CSnakeGameState
CSnakeGameState
::
m_SnakeGameState
;
CSnakeGameState
CSnakeGameState
::
m_SnakeGameState
;
void
CSnakeGameState
::
Init
()
void
CSnakeGameState
::
Init
()
{
{
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
BrdSet
=
new
Snake
;
waitTime
=
new
Thread
;
BrdSet
->
newBody
();
snake
=
new
Snake
;
snake
->
newBody
();
input
=
0
;
input
=
0
;
}
}
...
@@ -24,29 +26,34 @@ void CSnakeGameState::Resume()
...
@@ -24,29 +26,34 @@ void CSnakeGameState::Resume()
void
CSnakeGameState
::
Cleanup
()
void
CSnakeGameState
::
Cleanup
()
{
{
// cout << " SnakeState Cleanup" << endl;
// cout << " SnakeState Cleanup" << endl;
delete
waitTime
;
waitTime
=
nullptr
;
delete
snake
;
snake
=
nullptr
;
}
}
void
CSnakeGameState
::
HandleEvents
(
CGameEngine
*
game
)
void
CSnakeGameState
::
HandleEvents
(
CGameEngine
*
game
)
{
waitTime
.
Sleep
(
1
);
}
void
CSnakeGameState
::
Update
(
CGameEngine
*
game
)
{
{
if
(
game
->
newInput
)
if
(
game
->
newInput
)
{
{
input
=
game
->
input
;
input
=
game
->
input
;
}
}
BrdSet
->
movement
(
input
);
}
void
CSnakeGameState
::
Update
(
CGameEngine
*
game
)
{
waitTime
->
Sleep
(
1
);
snake
->
movement
(
input
);
}
}
void
CSnakeGameState
::
Draw
(
CGameEngine
*
game
)
void
CSnakeGameState
::
Draw
(
CGameEngine
*
game
)
{
{
system
(
"stty cooked"
);
system
(
"stty cooked"
);
if
(
!
(
BrdSet
->
draw
()))
if
(
!
(
snake
->
draw
()))
{
{
game
->
PopState
();
game
->
HoldScore
(
snake
->
snekoScore
());
game
->
ChangeState
(
CSnakeGameOverState
::
Instance
());
}
}
system
(
"stty raw"
);
system
(
"stty raw"
);
...
...
GameEngine/SnakeGameState.h
View file @
caa566d6
...
@@ -26,8 +26,8 @@ class CSnakeGameState : public CGameState
...
@@ -26,8 +26,8 @@ class CSnakeGameState : public CGameState
private:
private:
static
CSnakeGameState
m_SnakeGameState
;
static
CSnakeGameState
m_SnakeGameState
;
Snake
*
BrdSet
;
Snake
*
snake
=
nullptr
;
Thread
waitTime
;
Thread
*
waitTime
=
nullptr
;
char
input
;
char
input
;
};
};
...
...
GameEngine/SnakeMenuState.cpp
View file @
caa566d6
#include <iostream>
#include <iostream>
#include "SnakeMenuState.h"
#include "SnakeMenuState.h"
#include "SnakeGameState.h"
#include "SnakeGameState.h"
#include "SnakeScoreState.h"
#include <string>
#include <string>
#include <fstream>
#include <fstream>
...
@@ -36,6 +37,7 @@ void CSnakeMenuState::Init()
...
@@ -36,6 +37,7 @@ void CSnakeMenuState::Init()
// Set first input and draw the menu
// Set first input and draw the menu
input
=
' '
;
input
=
' '
;
menuPos
=
0
;
Draw
(
nullptr
);
Draw
(
nullptr
);
}
}
...
@@ -85,7 +87,7 @@ void CSnakeMenuState::Update(CGameEngine* game)
...
@@ -85,7 +87,7 @@ void CSnakeMenuState::Update(CGameEngine* game)
break
;
break
;
case
1
:
//Snake
case
1
:
//Snake
//game->PushState(CHighScor
e::Instance());
game
->
PushState
(
CSnakeScoreStat
e
::
Instance
());
break
;
break
;
case
2
:
//Quit
case
2
:
//Quit
...
...
GameEngine/SnakeScoreState.cpp
0 → 100644
View file @
caa566d6
#include <iostream>
#include "SnakeScoreState.h"
#include <string>
#include <fstream>
#include <streambuf>
using
namespace
std
;
CSnakeScoreState
CSnakeScoreState
::
m_SnakeScoreState
;
void
CSnakeScoreState
::
Init
()
{
if
(
!
isInit
)
{
// Load in main menu title
ifstream
fs
(
"SnakeScoreTitle.txt"
);
fs
.
seekg
(
0
,
ios
::
end
);
menuTitle
.
reserve
(
fs
.
tellg
());
fs
.
seekg
(
0
,
ios
::
beg
);
menuTitle
.
assign
((
istreambuf_iterator
<
char
>
(
fs
)),
istreambuf_iterator
<
char
>
());
// Set name for debugging
stateName
=
"Snakescore"
;
// Read in score data
highscores
.
LoadContainers
(
"../SaveLoad/snakedata.txt"
);
isInit
=
true
;
}
// Set first input and draw the menu
input
=
0
;
Draw
(
nullptr
);
}
void
CSnakeScoreState
::
Pause
()
{
}
void
CSnakeScoreState
::
Resume
()
{
input
=
0
;
}
void
CSnakeScoreState
::
Cleanup
()
{
}
void
CSnakeScoreState
::
HandleEvents
(
CGameEngine
*
game
)
{
while
(
game
->
newInput
==
false
)
{
input
=
' '
;
}
input
=
game
->
input
;
game
->
newInput
=
false
;
}
void
CSnakeScoreState
::
Update
(
CGameEngine
*
game
)
{
switch
(
input
)
{
case
'x'
:
// Erase Scores
break
;
default:
game
->
PopState
();
break
;
}
}
void
CSnakeScoreState
::
Draw
(
CGameEngine
*
game
)
{
system
(
"stty cooked"
);
cout
<<
menuTitle
<<
endl
;
highscores
.
displayScores
();
system
(
"stty raw"
);
}
GameEngine/SnakeScoreState.h
0 → 100644
View file @
caa566d6
#ifndef CSNAKESCORESTATE_H
#define CSNAKESCORESTATE_H
#include "GameState.h"
#include "../SaveLoad/SLSnake.h"
#include <iostream>
#include <string>
class
CSnakeScoreState
:
public
CGameState
{
public:
void
Init
();
void
Cleanup
();
void
Pause
();
void
Resume
();
void
HandleEvents
(
CGameEngine
*
game
);
void
Update
(
CGameEngine
*
game
);
void
Draw
(
CGameEngine
*
game
);
static
CSnakeScoreState
*
Instance
()
{
return
&
m_SnakeScoreState
;
}
protected:
CSnakeScoreState
()
{}
private:
static
CSnakeScoreState
m_SnakeScoreState
;
char
input
;
string
menuTitle
;
SLSnake
highscores
;
bool
isInit
=
false
;
};
#endif
\ No newline at end of file
SaveLoad/2048Data.txt
View file @
caa566d6
...
@@ -13,3 +13,6 @@ NKV 5453
...
@@ -13,3 +13,6 @@ NKV 5453
KAL 2434
KAL 2434
KOM 1404
KOM 1404
POP 636
POP 636
kom 428
asd 68
dad 36
SaveLoad/snakedata.txt
View file @
caa566d6
NAME SCORE
NAME SCORE
nge 654346
aaa 50
vfd 45365
aaa 40
cdn 21474
aaa 30
ooo 10000
aaa 25
LOP 10000
aaa 20
vfr 9999
aaa 15
ddd 9999
aaa 10
Kyl 9999
aaa 5
PPP 9999
kom 5
bbb 9999
aaa 1
vfd 4636
kom 1
vev 4536
qwe 1
DVS 3423
kom 0
goo 1000
kom 0
vfd 1000
efd 1000
dew 343
bth 34
Snake/Snake.cpp
View file @
caa566d6
...
@@ -7,7 +7,6 @@
...
@@ -7,7 +7,6 @@
using
namespace
std
;
using
namespace
std
;
bool
hi
=
true
;
bool
hi
=
true
;
Snake
bdy
;
Snake
bdy
;
vector
<
Body
>
parts
;
void
Snake
::
movement
(
char
input
){
void
Snake
::
movement
(
char
input
){
...
@@ -52,7 +51,7 @@ void Snake::movement(char input){
...
@@ -52,7 +51,7 @@ void Snake::movement(char input){
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
if
(
count
!=
0
)
if
(
count
!=
0
)
parts
[
count
].
follow
(
count
);
parts
[
count
].
follow
(
count
,
this
);
}
}
}
}
...
@@ -118,11 +117,11 @@ if (grid [x][y] == grid[h][o] ){ // randomizes the apples
...
@@ -118,11 +117,11 @@ if (grid [x][y] == grid[h][o] ){ // randomizes the apples
h
=
(
rand
()
%
26
)
+
1
;
h
=
(
rand
()
%
26
)
+
1
;
o
=
(
rand
()
%
57
)
+
1
;
o
=
(
rand
()
%
57
)
+
1
;
score
++
;
score
++
;
bdy
.
newBody
();
newBody
();
bonusBody
=
bonusBody
+
5
;
bonusBody
=
bonusBody
+
5
;
}
else
if
(
bonusBody
>
0
){
// adds body parts every loop after picking up apples
}
else
if
(
bonusBody
>
0
){
// adds body parts every loop after picking up apples
bdy
.
newBody
();
newBody
();
bonusBody
--
;
bonusBody
--
;
}
}
...
@@ -207,9 +206,9 @@ if (grid [x][y] == grid[h][o] ){ // randomizes the apples
...
@@ -207,9 +206,9 @@ if (grid [x][y] == grid[h][o] ){ // randomizes the apples
return
lastY
;
return
lastY
;
}
}
void
Body
::
follow
(
int
count
){
void
Body
::
follow
(
int
count
,
Snake
*
snake
){
lastX
=
x
;
lastX
=
x
;
lastY
=
y
;
lastY
=
y
;
x
=
parts
[
count
-
1
]
.
getlastX
();
x
=
snake
->
getPart
(
count
-
1
)
.
getlastX
();
y
=
parts
[
count
-
1
]
.
getlastY
();
y
=
snake
->
getPart
(
count
-
1
)
.
getlastY
();
}
}
\ No newline at end of file
Snake/Snake.h
View file @
caa566d6
...
@@ -2,7 +2,30 @@
...
@@ -2,7 +2,30 @@
#define SNAKE_H
#define SNAKE_H
#include <iostream>
#include <iostream>
#include <vector>
class
Snake
;
class
Body
{
public:
Body
(
int
xCord
,
int
yCord
);
int
getX
();
int
getY
();
void
changeX
(
bool
updown
);
void
changeY
(
bool
updown
);
void
follow
(
int
count
,
Snake
*
snake
);
int
getlastX
();
int
getlastY
();
void
setLast
(
int
count
);
private:
int
x
,
y
;
int
lastX
,
lastY
;
char
piece
;
};
class
Snake
{
class
Snake
{
...
@@ -18,6 +41,7 @@ class Snake {
...
@@ -18,6 +41,7 @@ class Snake {
void
newBody
();
void
newBody
();
void
GameOver
();
void
GameOver
();
bool
fillspace
();
bool
fillspace
();
Body
getPart
(
int
index
)
{
return
parts
.
at
(
index
);
}
private:
private:
...
@@ -27,29 +51,6 @@ class Snake {
...
@@ -27,29 +51,6 @@ class Snake {
char
whtSpace
=
' '
;
char
whtSpace
=
' '
;
int
direction
=
5
;
int
direction
=
5
;
int
bonusBody
=
0
;
int
bonusBody
=
0
;
};
std
::
vector
<
Body
>
parts
;
class
Body
{
public:
Body
(
int
xCord
,
int
yCord
);
int
getX
();
int
getY
();
void
changeX
(
bool
updown
);
void
changeY
(
bool
updown
);
void
follow
(
int
count
);
int
getlastX
();
int
getlastY
();
void
setLast
(
int
count
);
private:
int
x
,
y
;
int
lastX
,
lastY
;
char
piece
;
};
};
#endif
#endif
\ No newline at end of file
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