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
25d70808
Commit
25d70808
authored
Feb 24, 2019
by
Brandon Toledo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
seperate display and movement
parent
e552481e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
21 deletions
+25
-21
2048/Game2048.cpp
2048/Game2048.cpp
+10
-5
2048/Game2048.h
2048/Game2048.h
+2
-0
2048/Movement.cpp
2048/Movement.cpp
+8
-10
2048/Movement.h
2048/Movement.h
+5
-6
No files found.
2048/Game2048.cpp
View file @
25d70808
...
...
@@ -16,11 +16,16 @@ 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
.
up
(
*
game
,
score
,
highScore
);
shift
.
right
(
*
game
,
score
,
highScore
);
shift
.
down
(
*
game
,
score
,
highScore
);
shift
.
right
(
*
game
,
score
);
board
.
showGame
(
*
game
,
score
,
highScore
);
shift
.
left
(
*
game
,
score
);
board
.
showGame
(
*
game
,
score
,
highScore
);
shift
.
up
(
*
game
,
score
);
board
.
showGame
(
*
game
,
score
,
highScore
);
shift
.
right
(
*
game
,
score
);
board
.
showGame
(
*
game
,
score
,
highScore
);
shift
.
down
(
*
game
,
score
);
board
.
showGame
(
*
game
,
score
,
highScore
);
delete
game
;
}
...
...
2048/Game2048.h
View file @
25d70808
#include <iostream>
#include <vector>
#include "Movement.h"
#include "Display.h"
using
namespace
std
;
...
...
@@ -15,5 +16,6 @@ class Game2048 {
int
gameSize
;
int
score
;
Movement
shift
;
Display
board
;
vector
<
vector
<
int
>>*
game
=
nullptr
;
};
2048/Movement.cpp
View file @
25d70808
#include <iostream>
#include <vector>
#include "Movement.h"
#include "Display.h"
using
namespace
std
;
void
Movement
::
up
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
){
void
Movement
::
up
(
vector
<
vector
<
int
>>&
game
,
int
&
score
){
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
...
...
@@ -20,10 +19,9 @@ void Movement::up(vector<vector<int>>& game, int& score, const int& highScore){
}
}
transition
(
game
);
gameDisplay
.
showGame
(
game
,
score
,
highScore
);
}
void
Movement
::
down
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
){
void
Movement
::
down
(
vector
<
vector
<
int
>>&
game
,
int
&
score
){
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
))
{
...
...
@@ -38,10 +36,9 @@ void Movement::down(vector<vector<int>>& game, int& score, const int& highScore)
}
}
transition
(
game
);
gameDisplay
.
showGame
(
game
,
score
,
highScore
);
}
void
Movement
::
right
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
){
void
Movement
::
right
(
vector
<
vector
<
int
>>&
game
,
int
&
score
){
for
(
int
i
=
0
;
i
<
game
.
size
();
i
++
){
for
(
int
u
=
game
.
size
()
-
1
;
u
>
0
;
u
--
){
if
((
game
.
at
(
i
).
at
(
u
)
==
game
.
at
(
i
).
at
(
u
-
1
))
&&
(
game
.
at
(
i
).
at
(
u
)
!=
0
))
{
...
...
@@ -56,10 +53,9 @@ 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
){
void
Movement
::
left
(
vector
<
vector
<
int
>>&
game
,
int
&
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
))
{
...
...
@@ -74,7 +70,6 @@ void Movement::left(vector<vector<int>>& game, int& score, const int& highScore)
}
}
transition
(
game
);
gameDisplay
.
showGame
(
game
,
score
,
highScore
);
}
void
Movement
::
transition
(
vector
<
vector
<
int
>>&
game
){
//this is to prevent values to add them twice
...
...
@@ -85,4 +80,7 @@ void Movement::transition(vector<vector<int>>& game){ //this is to prevent val
}
}
}
}
\ No newline at end of file
}
//void Movement::randomNumber()
\ No newline at end of file
2048/Movement.h
View file @
25d70808
#ifndef MOVEMENT_H
#define MOVEMENT_H
#include "Display.h"
#include <iostream>
#include <vector>
...
...
@@ -8,12 +7,12 @@ using namespace std;
class
Movement
{
public:
void
up
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
);
void
down
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
);
void
right
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
);
void
left
(
vector
<
vector
<
int
>>&
game
,
int
&
score
,
const
int
&
highScore
);
void
up
(
vector
<
vector
<
int
>>&
game
,
int
&
score
);
void
down
(
vector
<
vector
<
int
>>&
game
,
int
&
score
);
void
right
(
vector
<
vector
<
int
>>&
game
,
int
&
score
);
void
left
(
vector
<
vector
<
int
>>&
game
,
int
&
score
);
void
randomNumber
(
vector
<
vector
<
int
>>&
game
);
private:
Display
gameDisplay
;
void
transition
(
vector
<
vector
<
int
>>&
game
);
//no values are added twice
void
transfer
(
int
&
num1
,
int
&
num2
){
// to move the number if the next slot is empty
num1
=
num2
;
...
...
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