aboutsummaryrefslogtreecommitdiffstats
path: root/2048 Game
diff options
context:
space:
mode:
authorzedarider <ymherklotz@gmail.com>2016-02-18 11:37:45 +0000
committerzedarider <ymherklotz@gmail.com>2016-02-18 11:37:45 +0000
commitaf98ee7ff28cff97f5f29a5d9e65f9153531b0ee (patch)
tree86bfc53a0bc04512ac2936ee067a2b43e901e688 /2048 Game
downloadimperial_2015-af98ee7ff28cff97f5f29a5d9e65f9153531b0ee.tar.gz
imperial_2015-af98ee7ff28cff97f5f29a5d9e65f9153531b0ee.zip
Imperial C++ Directory
These are all the projects I’ve been working on at university.
Diffstat (limited to '2048 Game')
-rw-r--r--2048 Game/Gamebin0 -> 12544 bytes
-rw-r--r--2048 Game/Game.cpp96
-rw-r--r--2048 Game/configFile.txt4
3 files changed, 100 insertions, 0 deletions
diff --git a/2048 Game/Game b/2048 Game/Game
new file mode 100644
index 0000000..9aef631
--- /dev/null
+++ b/2048 Game/Game
Binary files 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 <iostream>
+#include <fstream>
+#include <string>
+#include <sstream>
+
+#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