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
d6e09fa0969faccbf7bf7cd100e38e6d6c710fe7 to 1992310f93510a98bd03dc75957caa3489c4d911
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
1992310f93510a98bd03dc75957caa3489c4d911
Select Git revision
Branches
master
1 result
Swap
Target
h45-taylor/assignment-2048
Select target project
h45-taylor/assignment-2048
1 result
d6e09fa0969faccbf7bf7cd100e38e6d6c710fe7
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 more indexes to the top of the page
· 8affa26b
h45-taylor
authored
1 year ago
8affa26b
finished all of the movement functions
· 1992310f
h45-taylor
authored
1 year ago
1992310f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
2048
+0
-0
0 additions, 0 deletions
2048
2048.cpp
+64
-21
64 additions, 21 deletions
2048.cpp
README.md
+6
-2
6 additions, 2 deletions
README.md
game.hpp
+1
-1
1 addition, 1 deletion
game.hpp
with
71 additions
and
24 deletions
2048
0 → 100755
View file @
1992310f
File added
This diff is collapsed.
Click to expand it.
2048.cpp
View file @
1992310f
...
...
@@ -105,9 +105,8 @@ void Board::userInput() {
}
void
Board
::
moveLeft
()
{
for
(
int
i
=
0
;
i
<
SIZE
;
++
i
)
{
// Slide tiles to the left
for
(
int
j
=
0
;
j
<
SIZE
-
1
;
++
j
)
{
for
(
int
i
=
0
;
i
<
SIZE
;
++
i
)
{
// loops through all the rows
for
(
int
j
=
0
;
j
<
SIZE
-
1
;
++
j
)
{
// loops through the columns except the column on the right
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
...
...
@@ -118,8 +117,7 @@ void Board::moveLeft() {
}
}
}
else
{
// If the current tile is not empty, try to merge with the next tile
}
else
{
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
...
...
@@ -134,28 +132,26 @@ void Board::moveLeft() {
}
}
}
void
Board
::
moveRight
()
{
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
)
{
for
(
int
j
=
SIZE
-
1
;
j
>
0
;
--
j
)
{
if
(
board
[
i
][
j
]
==
0
)
{
for
(
int
k
=
j
-
1
;
k
>=
0
;
--
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
moved
=
true
;
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
for
(
int
k
=
j
-
1
;
k
>=
0
;
--
k
)
{
if
(
board
[
i
][
k
]
!=
0
)
{
if
(
board
[
i
][
j
]
==
board
[
i
][
k
])
{
board
[
i
][
j
]
*=
2
;
board
[
i
][
k
]
=
0
;
moved
=
true
;
}
break
;
}
...
...
@@ -166,14 +162,61 @@ void Board::moveRight() {
}
void
Board
::
moveUp
()
{
// create
for
(
int
j
=
0
;
j
<
SIZE
;
++
j
)
{
for
(
int
i
=
0
;
i
<
SIZE
-
1
;
++
i
)
{
if
(
board
[
i
][
j
]
==
0
)
{
for
(
int
k
=
i
+
1
;
k
<
SIZE
;
++
k
)
{
if
(
board
[
k
][
j
]
!=
0
)
{
board
[
i
][
j
]
=
board
[
k
][
j
];
board
[
k
][
j
]
=
0
;
moved
=
true
;
break
;
}
}
}
else
{
for
(
int
k
=
i
+
1
;
k
<
SIZE
;
++
k
)
{
if
(
board
[
k
][
j
]
!=
0
)
{
if
(
board
[
i
][
j
]
==
board
[
k
][
j
])
{
board
[
i
][
j
]
*=
2
;
board
[
k
][
j
]
=
0
;
moved
=
true
;
}
break
;
}
}
}
}
}
}
void
Board
::
moveDown
()
{
// create
for
(
int
j
=
0
;
j
<
SIZE
;
++
j
)
{
for
(
int
i
=
SIZE
-
1
;
i
>
0
;
--
i
)
{
if
(
board
[
i
][
j
]
==
0
)
{
for
(
int
k
=
i
-
1
;
k
>=
0
;
--
k
)
{
if
(
board
[
k
][
j
]
!=
0
)
{
board
[
i
][
j
]
=
board
[
k
][
j
];
board
[
k
][
j
]
=
0
;
moved
=
true
;
break
;
}
}
}
else
{
for
(
int
k
=
i
-
1
;
k
>=
0
;
--
k
)
{
if
(
board
[
k
][
j
]
!=
0
)
{
if
(
board
[
i
][
j
]
==
board
[
k
][
j
])
{
board
[
i
][
j
]
*=
2
;
board
[
k
][
j
]
=
0
;
moved
=
true
;
}
break
;
}
}
}
}
}
}
bool
Board
::
isGameOver
()
{
// create
return
true
;
}
This diff is collapsed.
Click to expand it.
README.md
View file @
1992310f
# 2048 Game
-
[
The Rules
](
#the-rules
)
-
[
The Aim
](
#the-aim
)
-
[
The Functions
](
#the-functions-in-depth
)
-
[
Images
](
#images
)
-
[
How To Play
](
#how-to-play
)
-
[
Show randomness
](
#randomness-proof
)
...
...
@@ -60,7 +61,10 @@ I then use a switch statement to match what key was pressed and to run a functio
Compile using "g++ main.cpp 2048.cpp -o 2048"
Then run using ./2048
#### How To Play
Use Keys W,A,S,D to select your move and press enter to submit your move.
then follow
[
The Rules
](
#the-rules
)
# Images
...
...
This diff is collapsed.
Click to expand it.
game.hpp
View file @
1992310f
#pragma once
#include
<vector>
//
#include <vector>
class
Board
{
private:
...
...
This diff is collapsed.
Click to expand it.