Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Assignment 2048
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
h45-taylor
Assignment 2048
Compare revisions
33943929a868f4033e8d1dede6aa13c203cead4b to d6e09fa0969faccbf7bf7cd100e38e6d6c710fe7
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
h45-taylor/assignment-2048
Select target project
No results found
d6e09fa0969faccbf7bf7cd100e38e6d6c710fe7
Select Git revision
Swap
Target
h45-taylor/assignment-2048
Select target project
h45-taylor/assignment-2048
1 result
33943929a868f4033e8d1dede6aa13c203cead4b
Select Git revision
Branches
master
1 result
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
added game.run to solve issues
· c0432f28
h45-taylor
authored
1 year ago
c0432f28
added move left and right functions
· d6e09fa0
h45-taylor
authored
1 year ago
d6e09fa0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
2048.cpp
+56
-3
56 additions, 3 deletions
2048.cpp
game.hpp
+1
-2
1 addition, 2 deletions
game.hpp
main.cpp
+2
-0
2 additions, 0 deletions
main.cpp
with
59 additions
and
5 deletions
2048.cpp
View file @
d6e09fa0
...
...
@@ -105,11 +105,64 @@ void Board::userInput() {
}
void
Board
::
moveLeft
()
{
// create
for
(
int
i
=
0
;
i
<
SIZE
;
++
i
)
{
// Slide tiles to the left
for
(
int
j
=
0
;
j
<
SIZE
-
1
;
++
j
)
{
if
(
board
[
i
][
j
]
==
0
)
{
// If the current tile is empty move the numbers left
for
(
int
k
=
j
+
1
;
k
<
SIZE
;
++
k
)
{
if
(
board
[
i
][
k
]
!=
0
)
{
//checks if the position to the left is empty
board
[
i
][
j
]
=
board
[
i
][
k
];
// moves the current tile as far left as it can without merging
board
[
i
][
k
]
=
0
;
// sets the original tile to 0
moved
=
true
;
// set movement bool to true to not allow 2 moves at once
break
;
}
}
}
else
{
// If the current tile is not empty, try to merge with the next tile
for
(
int
k
=
j
+
1
;
k
<
SIZE
;
++
k
)
{
if
(
board
[
i
][
k
]
!=
0
)
{
//check if there is a number to the left
if
(
board
[
i
][
j
]
==
board
[
i
][
k
])
{
// If Number in Grid position i j match i k
board
[
i
][
j
]
*=
2
;
// then double the value of the left tile
board
[
i
][
k
]
=
0
;
// set the tile to the right of the merged one to 0
moved
=
true
;
// set movement bool to true
}
break
;
}
}
}
}
}
}
void
Board
::
moveRight
()
{
// create
for
(
int
i
=
0
;
i
<
SIZE
;
++
i
)
{
// Slide tiles to the left
for
(
int
j
=
0
;
j
<
SIZE
-
1
;
++
j
)
{
if
(
board
[
i
][
j
]
==
0
)
{
// If the current tile is empty move the numbers left
for
(
int
k
=
j
+
1
;
k
<
SIZE
;
++
k
)
{
if
(
board
[
i
][
k
]
!=
0
)
{
board
[
i
][
j
]
=
board
[
i
][
k
];
board
[
i
][
k
]
=
0
;
moved
=
true
;
// set movement bool to true to not allow 2 moves at once
break
;
}
}
}
else
{
// If the current tile is not empty, try to merge with the next tile
for
(
int
k
=
j
+
1
;
k
<
SIZE
;
++
k
)
{
if
(
board
[
i
][
k
]
!=
0
)
{
//check if there is a number to the left
if
(
board
[
i
][
k
]
==
board
[
i
][
j
])
{
// If Number in Grid position i j match i k
board
[
i
][
k
]
*=
2
;
// then double the value of the left tile
board
[
i
][
j
]
=
0
;
// set the tile to the right of the merged one to 0
moved
=
true
;
// set movement bool to true
}
break
;
}
}
}
}
}
}
void
Board
::
moveUp
()
{
...
...
This diff is collapsed.
Click to expand it.
game.hpp
View file @
d6e09fa0
...
...
@@ -23,5 +23,4 @@ public:
Board
();
void
run
();
};
#endif
\ No newline at end of file
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.cpp
View file @
d6e09fa0
...
...
@@ -2,5 +2,7 @@
int
main
(){
Board
game
;
game
.
run
();
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.