Commit 25d70808 authored by Brandon Toledo's avatar Brandon Toledo
Browse files

seperate display and movement

parent e552481e
......@@ -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;
}
......
#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;
};
#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
......@@ -86,3 +81,6 @@ void Movement::transition(vector<vector<int>>& game){ //this is to prevent val
}
}
}
//void Movement::randomNumber()
\ No newline at end of file
#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;
......
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