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
962b4c8a
Commit
962b4c8a
authored
Mar 12, 2019
by
Konrad McClure
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added score entering to game over screen
parent
7c6f862c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
67 additions
and
36 deletions
+67
-36
2048/Game2048.h
2048/Game2048.h
+1
-0
GameEngine/2048Data.txt
GameEngine/2048Data.txt
+7
-6
GameEngine/2048GameOverState.cpp
GameEngine/2048GameOverState.cpp
+31
-11
GameEngine/2048GameOverState.h
GameEngine/2048GameOverState.h
+2
-1
GameEngine/2048GameOverTitle.txt
GameEngine/2048GameOverTitle.txt
+11
-0
GameEngine/2048GameState.cpp
GameEngine/2048GameState.cpp
+6
-2
GameEngine/GameEngine.cpp
GameEngine/GameEngine.cpp
+0
-12
GameEngine/GameEngine.h
GameEngine/GameEngine.h
+4
-1
GameEngine/enginetest.cpp
GameEngine/enginetest.cpp
+5
-3
No files found.
2048/Game2048.h
View file @
962b4c8a
...
@@ -13,6 +13,7 @@ class Game2048 {
...
@@ -13,6 +13,7 @@ class Game2048 {
void
Shift
(
char
input
);
void
Shift
(
char
input
);
void
testInit
(){
*
board
=
{
{
4
,
0
,
0
,
2
},
{
4
,
2
,
0
,
0
},
{
4
,
4
,
0
,
0
},
{
4
,
4
,
0
,
0
}};}
void
testInit
(){
*
board
=
{
{
4
,
0
,
0
,
2
},
{
4
,
2
,
0
,
0
},
{
4
,
4
,
0
,
0
},
{
4
,
4
,
0
,
0
}};}
bool
addNumber
();
bool
addNumber
();
int
getScore
()
{
return
score
;}
...
...
GameEngine/2048Data.txt
View file @
962b4c8a
NAME SCORE
NAME SCORE
Mal 54234
Mal 54234
BVB 9240
BVB 9240
BND 6564
ass 532
CDS 6544
WEB 128
NKV 5453
qwe 128
KAL 2434
mop 128
ddd 76
GameEngine/2048GameOverState.cpp
View file @
962b4c8a
...
@@ -13,7 +13,7 @@ void C2048GameOverState::Init()
...
@@ -13,7 +13,7 @@ void C2048GameOverState::Init()
if
(
!
isInit
)
if
(
!
isInit
)
{
{
// Load in main menu title
// Load in main menu title
ifstream
fs
(
"2048
Score
Title.txt"
);
ifstream
fs
(
"2048
GameOver
Title.txt"
);
fs
.
seekg
(
0
,
ios
::
end
);
fs
.
seekg
(
0
,
ios
::
end
);
menuTitle
.
reserve
(
fs
.
tellg
());
menuTitle
.
reserve
(
fs
.
tellg
());
fs
.
seekg
(
0
,
ios
::
beg
);
fs
.
seekg
(
0
,
ios
::
beg
);
...
@@ -22,7 +22,7 @@ void C2048GameOverState::Init()
...
@@ -22,7 +22,7 @@ void C2048GameOverState::Init()
istreambuf_iterator
<
char
>
());
istreambuf_iterator
<
char
>
());
// Set name for debugging
// Set name for debugging
stateName
=
"2048
score
"
;
stateName
=
"2048
gameover
"
;
// Read in score data
// Read in score data
highscores
.
LoadContainers
();
highscores
.
LoadContainers
();
...
@@ -32,6 +32,7 @@ void C2048GameOverState::Init()
...
@@ -32,6 +32,7 @@ void C2048GameOverState::Init()
// Set first input and draw the menu
// Set first input and draw the menu
input
=
' '
;
input
=
' '
;
scoreSet
=
false
;
Draw
(
nullptr
);
Draw
(
nullptr
);
}
}
...
@@ -52,25 +53,39 @@ void C2048GameOverState::Cleanup()
...
@@ -52,25 +53,39 @@ void C2048GameOverState::Cleanup()
void
C2048GameOverState
::
HandleEvents
(
CGameEngine
*
game
)
void
C2048GameOverState
::
HandleEvents
(
CGameEngine
*
game
)
{
{
while
(
game
->
newInput
==
false
)
if
(
!
scoreSet
)
{
{
input
=
' '
;
system
(
"stty cooked"
);
cout
<<
"Press enter to continue"
<<
endl
;
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
;
input
=
game
->
input
;
game
->
newInput
=
false
;
game
->
newInput
=
false
;
}
}
}
void
C2048GameOverState
::
Update
(
CGameEngine
*
game
)
void
C2048GameOverState
::
Update
(
CGameEngine
*
game
)
{
{
switch
(
inpu
t
)
if
(
scoreSe
t
)
{
{
case
'x'
:
switch
(
input
)
// Erase Scores
{
break
;
case
'x'
:
default:
game
->
PopState
();
game
->
PopState
();
break
;
break
;
default:
break
;
}
}
}
}
}
...
@@ -79,8 +94,13 @@ void C2048GameOverState::Draw(CGameEngine* game)
...
@@ -79,8 +94,13 @@ void C2048GameOverState::Draw(CGameEngine* game)
system
(
"stty cooked"
);
system
(
"stty cooked"
);
cout
<<
menuTitle
<<
endl
;
cout
<<
menuTitle
<<
endl
;
cout
<<
"
\n\n
"
;
highscores
.
displayScores
();
highscores
.
displayScores
();
highscores
.
updateFile
();
system
(
"stty raw"
);
system
(
"stty raw"
);
}
}
GameEngine/2048GameOverState.h
View file @
962b4c8a
...
@@ -19,7 +19,7 @@ class C2048GameOverState : public CGameState
...
@@ -19,7 +19,7 @@ class C2048GameOverState : public CGameState
void
Update
(
CGameEngine
*
game
);
void
Update
(
CGameEngine
*
game
);
void
Draw
(
CGameEngine
*
game
);
void
Draw
(
CGameEngine
*
game
);
static
C2048GameOverState
*
Instance
()
{
return
&
m_2048
Score
State
;
}
static
C2048GameOverState
*
Instance
()
{
return
&
m_2048
GameOver
State
;
}
protected:
protected:
C2048GameOverState
()
{}
C2048GameOverState
()
{}
...
@@ -30,6 +30,7 @@ class C2048GameOverState : public CGameState
...
@@ -30,6 +30,7 @@ class C2048GameOverState : public CGameState
string
menuTitle
;
string
menuTitle
;
SL2048
highscores
;
SL2048
highscores
;
bool
isInit
=
false
;
bool
isInit
=
false
;
bool
scoreSet
=
false
;
};
};
...
...
GameEngine/2048GameOverTitle.txt
0 → 100644
View file @
962b4c8a
=======================================================
|| _____ ____ ||
|| / ____| / __ \ ||
|| | | __ __ _ _ __ ___ ___ | | | |_ _____ _ __ ||
|| | | |_ |/ _` | '_ ` _ \ / _ \ | | | \ \ / / _ \ '__| ||
|| | |__| | (_| | | | | | | __/ | |__| |\ V / __/ | ||
|| \_____|\__,_|_| |_| |_|\___| \____/ \_/ \___|_| ||
|| ||
=======================================================
GameEngine/2048GameState.cpp
View file @
962b4c8a
#include <iostream>
#include <iostream>
#include "2048GameState.h"
#include "2048GameState.h"
#include "2048GameOverState.h"
C2048GameState
C2048GameState
::
m_2048GameState
;
C2048GameState
C2048GameState
::
m_2048GameState
;
...
@@ -84,8 +85,11 @@ void C2048GameState::Update(CGameEngine* game)
...
@@ -84,8 +85,11 @@ void C2048GameState::Update(CGameEngine* game)
// cout << " 2048GameState Update" << endl;
// cout << " 2048GameState Update" << endl;
game2048
->
Shift
(
input
);
game2048
->
Shift
(
input
);
if
(
!
game2048
->
addNumber
())
{
if
(
!
game2048
->
addNumber
())
game
->
PopState
();
{
// Push the score to the engine for temporary keeping
game
->
HoldScore
(
game2048
->
getScore
());
game
->
ChangeState
(
C2048GameOverState
::
Instance
());
}
}
}
}
...
...
GameEngine/GameEngine.cpp
View file @
962b4c8a
...
@@ -95,16 +95,4 @@ void CGameEngine::Draw()
...
@@ -95,16 +95,4 @@ void CGameEngine::Draw()
cout
<<
"\e[2J\e[0;0H"
;
cout
<<
"\e[2J\e[0;0H"
;
states
.
back
()
->
Draw
(
this
);
states
.
back
()
->
Draw
(
this
);
// system("stty raw");
// system("stty raw");
}
void
CGameEngine
::
PushInput
(
char
input
)
{
inputQueue
.
push
(
input
);
}
char
CGameEngine
::
PopInput
()
{
char
input
=
inputQueue
.
front
();
inputQueue
.
pop
();
return
input
;
}
}
\ No newline at end of file
GameEngine/GameEngine.h
View file @
962b4c8a
...
@@ -31,12 +31,15 @@ class CGameEngine
...
@@ -31,12 +31,15 @@ class CGameEngine
void
PushInput
(
char
input
);
void
PushInput
(
char
input
);
char
PopInput
();
char
PopInput
();
void
HoldScore
(
int
score
)
{
this
->
score
=
score
;
}
int
GetScore
()
{
return
score
;
}
bool
newInput
=
false
;
bool
newInput
=
false
;
char
input
;
char
input
;
bool
inputPause
=
false
;
private:
private:
// Gamestate Stack
// Gamestate Stack
vector
<
CGameState
*>
states
;
vector
<
CGameState
*>
states
;
queue
<
char
>
inputQueu
e
;
int
scor
e
;
// Currently running bool (false will initiate cleanup)
// Currently running bool (false will initiate cleanup)
bool
m_running
;
bool
m_running
;
...
...
GameEngine/enginetest.cpp
View file @
962b4c8a
...
@@ -50,8 +50,10 @@ void MainInput(CGameEngine* game)
...
@@ -50,8 +50,10 @@ void MainInput(CGameEngine* game)
while
(
game
->
isRunning
())
while
(
game
->
isRunning
())
{
{
// game.PushInput(reader.collectInput());
if
(
!
game
->
inputPause
)
game
->
input
=
reader
.
collectInput
();
{
game
->
newInput
=
true
;
game
->
input
=
reader
.
collectInput
();
game
->
newInput
=
true
;
}
}
}
}
}
\ 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