From af98ee7ff28cff97f5f29a5d9e65f9153531b0ee Mon Sep 17 00:00:00 2001 From: zedarider Date: Thu, 18 Feb 2016 11:37:45 +0000 Subject: Imperial C++ Directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are all the projects I’ve been working on at university. --- 2048 Game/Game | Bin 0 -> 12544 bytes 2048 Game/Game.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 2048 Game/configFile.txt | 4 ++ 3 files changed, 100 insertions(+) create mode 100644 2048 Game/Game create mode 100644 2048 Game/Game.cpp create mode 100644 2048 Game/configFile.txt (limited to '2048 Game') diff --git a/2048 Game/Game b/2048 Game/Game new file mode 100644 index 0000000..9aef631 Binary files /dev/null and b/2048 Game/Game differ diff --git a/2048 Game/Game.cpp b/2048 Game/Game.cpp new file mode 100644 index 0000000..553593e --- /dev/null +++ b/2048 Game/Game.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include + +#define GRIDSIZE 4 +#define UP 'w' +#define DOWN 's' +#define RIGHT 'd' +#define LEFT 'a' + +using namespace std; + +// defines the functions +void printGrid(int (&)[GRIDSIZE][GRIDSIZE]); +bool checkGameOver(int (&)[GRIDSIZE][GRIDSIZE]); + +int main(int argc, char* argv[]) { + // defines the 2D and tmp array + int grid[GRIDSIZE][GRIDSIZE]; + string fileName; + ifstream configFile; + + cout << "enter initial configuration file name:" << endl; + cin >> fileName; + + // opens the user defined file + configFile.open(fileName.c_str()); + + if(configFile.is_open()) { + for(int i = 0; i < GRIDSIZE; ++i) { + for(int j = 0; j < GRIDSIZE; ++j) { + configFile >> grid[i][j]; + } + } + configFile.close(); + } else { + cout << "the file doesn't exist, using default start" << endl; + // creates default grid + for(int i = 0; i < GRIDSIZE; ++i) { + for(int j = 0; j < GRIDSIZE; ++j) { + grid[i][j] = 0; + } + } + grid[GRIDSIZE-1][GRIDSIZE-1] = 2; + } + + printGrid(grid); + + while(!checkGameOver(grid)) { + + } + + return 0; +} + +void printGrid(int (&gridArray)[GRIDSIZE][GRIDSIZE]) { + for(int i = 0; i < GRIDSIZE; ++i) { + for(int j = 0; j < GRIDSIZE; ++j) { + cout << gridArray[i][j] << '\t'; + } + cout << endl; + } + cout << endl; +} + +void moveVertical() { + +} + +void moveHorizontal() { + +} + +void merge() { + +} + +bool checkGameOver(int (&gridArray)[GRIDSIZE][GRIDSIZE]) { + for(int i = 0; i < GRIDSIZE; ++i) { + for(int j = 0; j < GRIDSIZE; ++j) { + if(gridArray[i][j] == 0) { + return false; + } else if(i > 0 && gridArray[i][j] == gridArray[i-1][j]) { + return false; + } else if(i < GRIDSIZE-1 && gridArray[i][j] == gridArray[i+1][j]) { + return false; + } else if(j > 0 && gridArray[i][j] == gridArray[i][j-1]) { + return false; + } else if(j < GRIDSIZE-1 && gridArray[i][j] == gridArray[i][j+1]) { + return false; + } + } + } + return true; +} \ No newline at end of file diff --git a/2048 Game/configFile.txt b/2048 Game/configFile.txt new file mode 100644 index 0000000..b4f6ca6 --- /dev/null +++ b/2048 Game/configFile.txt @@ -0,0 +1,4 @@ +128 64 2 0 +0 0 32 0 +0 0 0 16 +0 8 4 0 \ No newline at end of file -- cgit