Commit 86caa1fc authored by Brandon Toledo's avatar Brandon Toledo
Browse files

I added new .h and .cpp file, it compiles but is not fully functional

parent 68aebec4
#ifndef DISPLAY_H
#define DISPLAY_H
#include <iostream> #include <iostream>
#include <vector> #include <vector>
...@@ -10,4 +12,6 @@ class Display { ...@@ -10,4 +12,6 @@ class Display {
void top() {cout << '+' << '-' << '-' << '-' << '-' << '-' << '-';} void top() {cout << '+' << '-' << '-' << '-' << '-' << '-' << '-';}
void middle() {cout << '|' << ' ' << ' ' << ' ' << ' ' << ' ' << ' ';} void middle() {cout << '|' << ' ' << ' ' << ' ' << ' ' << ' ' << ' ';}
void number(int value); void number(int value);
}; };
\ No newline at end of file
#endif
\ No newline at end of file
#include <iostream>
#include <vector>
#include "Display.h"
#include "Movement.h"
#include "Game2048.h"
using namespace std;
Game2048::Game2048(int gameSize) {
this->gameSize = gameSize;
score = 0;
game = new vector<vector<int>>(gameSize, vector<int>(gameSize,0));
}
void Game2048::playGame(){
*game = { {2,0,0,2}, {2,0,2,2}, {4,2,0,2}, {2,2,2,2}};
gameDisplay.showGame(*game);
shift.left(*game);
gameDisplay.showGame(*game);
delete game;
}
#include <iostream>
#include <vector>
#include "Display.h"
#include "Movement.h"
using namespace std;
class Game2048 {
public:
Game2048(int gameSize);
void playGame();
private:
int gameSize;
int score;
Movement shift;
Display gameDisplay;
vector<vector<int>>* game = nullptr;
};
#include <iostream>
#include <vector>
#include "Movement.h"
using namespace std;
void Movement::up(vector<vector<int>>& game){
int i;
}
void Movement::down(vector<vector<int>>& game){
int i;
}
void Movement::right(vector<vector<int>>& game){
int i;
}
void Movement::left(vector<vector<int>>& game){
for (vector<int>& row: game){
for (int i = 0; i < row.size() - 1; i++){
if ((row.at(i) == row.at(i + 1)) && (row.at(i) != 0)) {
add(row.at(i), row.at(i + 1));
i--;
}
else if ((row.at(i) == 0) && (row.at(i + 1) != 0)){
transfer(row.at(i), row.at(i+1));
i -= 2;
}
}
}
}
\ No newline at end of file
#ifndef MOVEMENT_H
#define MOVEMENT_H
#include <iostream>
#include <vector>
using namespace std;
class Movement {
public:
void up(vector<vector<int>>& game);
void down(vector<vector<int>>& game);
void right(vector<vector<int>>& game);
void left(vector<vector<int>>& game);
private:
void transfer(int& num1, int& num2){ // to move the number if
num1 = num2;
num2 = 0;
}
int add(int& num1, int& num2){ //this would return adition and would be use for the score
num1 += num2;
num2 = 0;
return num1;
}
};
#endif
\ No newline at end of file
#include <iostream>
#include <vector> // for 2D vector
#include "Game2048.h"
using namespace std;
int main() {
Game2048 game(4);
game.playGame();
return 0;
}
#include <iostream>
#include <vector> // for 2D vector
using namespace std;
int main()
{
// Initializing 2D vector "vect" with
// values
vector<vector<int>> vect(4, vector<int>(4,0));
//vector<vector<int>> vect{ { 1, 2, 3 },
// { 4, 5, 6 },
// { 7, 8, 9 } };
// Displaying the 2D vector
for (vector<int> value: vect) {
for (int value1: value)
cout << value1 << " ";
cout << endl;
}
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