Commit 2342fbb1 authored by Brandon Toledo's avatar Brandon Toledo
Browse files

all the movements functions are working

parent 40b1e610
...@@ -16,10 +16,11 @@ Game2048::Game2048(int gameSize,int& highScore) { // this initialize a game ...@@ -16,10 +16,11 @@ Game2048::Game2048(int gameSize,int& highScore) { // this initialize a game
void Game2048::playGame(){ void Game2048::playGame(){
*game = { {4,0,0,2}, {4,2,0,0}, {4,4,0,0}, {4,4,0,0}}; *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.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; delete game;
} }
......
...@@ -4,23 +4,8 @@ ...@@ -4,23 +4,8 @@
#include "Display.h" #include "Display.h"
using namespace std; using namespace std;
void Movement::up(vector<vector<int>>& game, int& score, const int& highScore){ 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 i = game.size() - 1; i >= 0; i--){
for (int u = 0; u < game.size() - 1; u++){ 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 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) ...@@ -38,7 +23,23 @@ void Movement::down(vector<vector<int>>& game, int& score, const int& highScore)
gameDisplay.showGame(game, score, 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){ void Movement::right(vector<vector<int>>& game, int& score, const int& highScore){
for (int i = 0; i < game.size(); i++){ for (int i = 0; i < game.size(); i++){
...@@ -57,15 +58,16 @@ void Movement::right(vector<vector<int>>& game, int& score, const int& highScore ...@@ -57,15 +58,16 @@ void Movement::right(vector<vector<int>>& game, int& score, const int& highScore
transition(game); transition(game);
gameDisplay.showGame(game, score, highScore); 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, const int& highScore){
for (int i = 0; i < game.size(); i++){ //seperates every row of the vector for (int i = 0; i < game.size(); i++){
for (int u = 0; u < game.size() - 1; u++){ // individual value 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)) { // check if they are the same to add them 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)); // this is add to the score 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)); 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; u -= 2;
} }
} }
......
...@@ -10,23 +10,6 @@ int main() { ...@@ -10,23 +10,6 @@ int main() {
Game2048 game(4,highScore); Game2048 game(4,highScore);
game.playGame(); 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; return 0;
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment