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
2342fbb1
Commit
2342fbb1
authored
Feb 24, 2019
by
Brandon Toledo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
all the movements functions are working
parent
40b1e610
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
43 deletions
+29
-43
2048/Game2048.cpp
2048/Game2048.cpp
+4
-3
2048/Movement.cpp
2048/Movement.cpp
+25
-23
2048/mainTest.cpp
2048/mainTest.cpp
+0
-17
No files found.
2048/Game2048.cpp
View file @
2342fbb1
...
...
@@ -16,10 +16,11 @@ Game2048::Game2048(int gameSize,int& highScore) { // this initialize a game
void
Game2048
::
playGame
(){
*
game
=
{
{
4
,
0
,
0
,
2
},
{
4
,
2
,
0
,
0
},
{
4
,
4
,
0
,
0
},
{
4
,
4
,
0
,
0
}};
//shift.right(*game, score, highScore);
//shift.left(*game, score, highScore);
shift
.
down
(
*
game
,
score
,
highScore
);
shift
.
right
(
*
game
,
score
,
highScore
);
shift
.
left
(
*
game
,
score
,
highScore
);
shift
.
up
(
*
game
,
score
,
highScore
);
shift
.
right
(
*
game
,
score
,
highScore
);
shift
.
down
(
*
game
,
score
,
highScore
);
delete
game
;
}
...
...
2048/Movement.cpp
View file @
2342fbb1
...
...
@@ -4,23 +4,8 @@
#include "Display.h"
using
namespace
std
;
void
Movement
::
up
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
){
for
(
vector
<
int
>
line
:
game
){
for
(
int
value
:
line
){
cout
<<
value
<<
" "
;
}
cout
<<
endl
;
}
cout
<<
endl
;
for
(
int
i
=
game
.
size
()
-
1
;
i
>=
0
;
i
--
){
for
(
int
u
=
0
;
u
<
game
.
size
();
u
++
){
cout
<<
game
.
at
(
u
).
at
(
i
)
<<
" "
;
}
cout
<<
endl
;
}
}
void
Movement
::
down
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
){
for
(
int
i
=
game
.
size
()
-
1
;
i
>=
0
;
i
--
){
for
(
int
u
=
0
;
u
<
game
.
size
()
-
1
;
u
++
){
if
((
game
.
at
(
u
).
at
(
i
)
==
game
.
at
(
u
+
1
).
at
(
i
))
&&
(
game
.
at
(
u
).
at
(
i
)
!=
0
))
{
// check if they are the same to add them
...
...
@@ -38,7 +23,23 @@ void Movement::down(vector<vector<int>>& game, int& score, const int& highScore)
gameDisplay
.
showGame
(
game
,
score
,
highScore
);
}
void
Movement
::
down
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
){
for
(
int
i
=
game
.
size
()
-
1
;
i
>=
0
;
i
--
){
for
(
int
u
=
game
.
size
()
-
1
;
u
>
0
;
u
--
){
if
((
game
.
at
(
u
).
at
(
i
)
==
game
.
at
(
u
-
1
).
at
(
i
))
&&
(
game
.
at
(
u
).
at
(
i
)
!=
0
))
{
score
+=
add
(
game
.
at
(
u
).
at
(
i
),
game
.
at
(
u
-
1
).
at
(
i
));
}
else
if
((
game
.
at
(
u
).
at
(
i
)
==
0
)
&&
(
game
.
at
(
u
-
1
).
at
(
i
)
!=
0
)){
transfer
(
game
.
at
(
u
).
at
(
i
),
game
.
at
(
u
-
1
).
at
(
i
));
if
(
u
<
3
){
u
+=
2
;
}
}
}
}
transition
(
game
);
gameDisplay
.
showGame
(
game
,
score
,
highScore
);
}
void
Movement
::
right
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
){
for
(
int
i
=
0
;
i
<
game
.
size
();
i
++
){
...
...
@@ -57,15 +58,16 @@ void Movement::right(vector<vector<int>>& game, int& score, const int& highScore
transition
(
game
);
gameDisplay
.
showGame
(
game
,
score
,
highScore
);
}
void
Movement
::
left
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
){
for
(
int
i
=
0
;
i
<
game
.
size
();
i
++
){
//seperates every row of the vector
for
(
int
u
=
0
;
u
<
game
.
size
()
-
1
;
u
++
){
// individual value
if
((
game
.
at
(
i
).
at
(
u
)
==
game
.
at
(
i
).
at
(
u
+
1
))
&&
(
game
.
at
(
i
).
at
(
u
)
!=
0
))
{
// check if they are the same to add them
score
+=
add
(
game
.
at
(
i
).
at
(
u
),
game
.
at
(
i
).
at
(
u
+
1
));
// this is add to the score
for
(
int
i
=
0
;
i
<
game
.
size
();
i
++
){
for
(
int
u
=
0
;
u
<
game
.
size
()
-
1
;
u
++
){
if
((
game
.
at
(
i
).
at
(
u
)
==
game
.
at
(
i
).
at
(
u
+
1
))
&&
(
game
.
at
(
i
).
at
(
u
)
!=
0
))
{
score
+=
add
(
game
.
at
(
i
).
at
(
u
),
game
.
at
(
i
).
at
(
u
+
1
));
}
else
if
((
game
.
at
(
i
).
at
(
u
)
==
0
)
&&
(
game
.
at
(
i
).
at
(
u
+
1
)
!=
0
)){
//check to move the value if slot is empty
else
if
((
game
.
at
(
i
).
at
(
u
)
==
0
)
&&
(
game
.
at
(
i
).
at
(
u
+
1
)
!=
0
)){
transfer
(
game
.
at
(
i
).
at
(
u
),
game
.
at
(
i
).
at
(
u
+
1
));
if
(
u
>
0
){
// this would stop it when it is at the end
if
(
u
>
0
){
u
-=
2
;
}
}
...
...
2048/mainTest.cpp
View file @
2342fbb1
...
...
@@ -10,23 +10,6 @@ int main() {
Game2048
game
(
4
,
highScore
);
game
.
playGame
();
/*
int y = 0;
vector<vector<int>> game(4, vector<int>(4,0));
for (int i = 0; i < game.size(); i++){
for(int u = 0;u < game.size()-1; u++) {
y++;
game.at(u).at(i) = y;
}
}
for (vector<int> line: game){
for (int value: line){
cout << value << " ";
}
cout << endl;
}
*/
return
0
;
}
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