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
5f63363a
Commit
5f63363a
authored
Feb 25, 2019
by
Brandon Toledo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2048 mostly finish
parent
5d9fc366
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
30 deletions
+57
-30
2048/Game2048.cpp
2048/Game2048.cpp
+43
-14
2048/Game2048.h
2048/Game2048.h
+2
-1
2048/Movement.cpp
2048/Movement.cpp
+1
-7
2048/Movement.h
2048/Movement.h
+0
-1
2048/mainTest.cpp
2048/mainTest.cpp
+8
-7
GameEngine/2048GameState.cpp
GameEngine/2048GameState.cpp
+3
-0
No files found.
2048/Game2048.cpp
View file @
5f63363a
#include <iostream>
#include <vector>
#include <cstdlib>
#include "Display.h"
#include "Movement.h"
#include "Game2048.h"
...
...
@@ -13,23 +14,20 @@ Game2048::Game2048(int gameSize,int& highScore) { // this initialize a board
score
=
0
;
board
=
new
vector
<
vector
<
int
>>
(
gameSize
,
vector
<
int
>
(
gameSize
,
0
));
}
/*
void Game2048::playGame(){
*
board
=
{
{
4
,
0
,
0
,
2
},
{
4
,
2
,
0
,
0
},
{
4
,
4
,
0
,
0
},
{
4
,
4
,
0
,
0
}};
movement
.
right
(
*
board
,
score
);
display
.
showGame
(
*
board
,
score
,
highScore
);
movement
.
left
(
*
board
,
score
);
display
.
showGame
(
*
board
,
score
,
highScore
);
movement
.
up
(
*
board
,
score
);
display
.
showGame
(
*
board
,
score
,
highScore
);
movement
.
right
(
*
board
,
score
);
display
.
showGame
(
*
board
,
score
,
highScore
);
movement
.
down
(
*
board
,
score
);
display
.
showGame
(
*
board
,
score
,
highScore
);
char choise;
while(true){
randomNumber();
Draw();
cin << choise;
Shift(choise);
}
delete board;
}
*/
void
Game2048
::
Shift
(
char
input
){
switch
(
input
){
...
...
@@ -46,6 +44,37 @@ void Game2048::Shift(char input){
movement
.
right
(
*
board
,
score
);
break
;
}
}
bool
Game2048
::
addNumber
(){
int
num
=
rand
()
%
5
;
int
numX
;
int
numY
;
bool
pass
=
true
;
bool
success
=
false
;
if
(
num
!=
4
)
{
num
=
2
;
}
for
(
vector
<
int
>
line
:
*
board
){
for
(
int
value
:
line
){
if
(
value
==
0
)
{
success
=
true
;
}
}
}
if
(
!
success
){
return
success
;
}
while
(
pass
){
numX
=
rand
()
%
board
->
size
();
numY
=
rand
()
%
board
->
size
();
if
(
board
->
at
(
numX
).
at
(
numY
)
==
0
){
board
->
at
(
numX
).
at
(
numY
)
=
num
;
pass
=
false
;
}
}
return
success
;
}
\ No newline at end of file
2048/Game2048.h
View file @
5f63363a
...
...
@@ -7,11 +7,12 @@ using namespace std;
class
Game2048
{
public:
Game2048
(
int
gameSize
,
int
&
highScore
);
Game2048
(
int
gameSize
,
int
&
highScore
);
// remove the pass by reference in high score
void
playGame
();
void
Draw
()
{
display
.
showGame
(
*
board
,
score
,
highScore
);}
void
Shift
(
char
input
);
void
testInit
(){
*
board
=
{
{
4
,
0
,
0
,
2
},
{
4
,
2
,
0
,
0
},
{
4
,
4
,
0
,
0
},
{
4
,
4
,
0
,
0
}};}
bool
addNumber
();
...
...
2048/Movement.cpp
View file @
5f63363a
...
...
@@ -80,10 +80,4 @@ void Movement::transition(vector<vector<int>>& board){ //this is to prevent va
}
}
}
}
/*void Movement::randomNumber(vector<vector<int>>& board){
}
*/
\ No newline at end of file
}
\ No newline at end of file
2048/Movement.h
View file @
5f63363a
...
...
@@ -11,7 +11,6 @@ class Movement {
void
down
(
vector
<
vector
<
int
>>&
board
,
int
&
score
);
void
right
(
vector
<
vector
<
int
>>&
board
,
int
&
score
);
void
left
(
vector
<
vector
<
int
>>&
board
,
int
&
score
);
void
randomNumber
(
vector
<
vector
<
int
>>&
board
);
private:
void
transition
(
vector
<
vector
<
int
>>&
board
);
//no values are added twice
void
transfer
(
int
&
num1
,
int
&
num2
){
// to move the number if the next slot is empty
...
...
2048/mainTest.cpp
View file @
5f63363a
...
...
@@ -3,13 +3,14 @@
#include "Game2048.h"
using
namespace
std
;
//
int main() {
/*
int main() {
//
int highScore = 2048;
//
Game2048 game(4,highScore);
//
game.playGame();
int highScore = 2048;
Game2048 game(4,highScore);
game.playGame();
//
return 0;
//
}
return 0;
}
*/
\ No newline at end of file
GameEngine/2048GameState.cpp
View file @
5f63363a
...
...
@@ -76,6 +76,9 @@ void C2048GameState::Update(CGameEngine* game)
cout
<<
" 2048GameState Update"
<<
endl
;
game2048
->
Shift
(
input
);
if
(
!
game2048
->
addNumber
())
{
game
->
Quit
();
}
}
void
C2048GameState
::
Draw
(
CGameEngine
*
game
)
...
...
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