Thomas Gill / Mbed 2 deprecated LabyrinthOfTheMinotaur

Dependencies:   N5110 PowerControl mbed

Revision:
3:1a25939df22a
Parent:
2:0b0311609edc
Child:
4:6482ceb08dc8
--- a/main.cpp	Wed Apr 15 12:14:27 2015 +0000
+++ b/main.cpp	Fri Apr 17 00:18:50 2015 +0000
@@ -25,6 +25,9 @@
 #define UP 2
 #define DOWN 3
 
+#define SOUTH 0
+#define EAST 1
+
 //Variables
 int buttonFlagA = 0;
 int buttonFlagS = 0;
@@ -88,11 +91,22 @@
     //Fill map with walls
     for(int i=0; i<84; i++) {
         for (int j=0; j<48; j++) {
+
             map[i][j] = WALL;
         }
     }
 }
 
+void Floors()
+{
+    //Fill map with floors
+    for(int i=0; i<84; i++) {
+        for (int j=0; j<48; j++) {
+            map[i][j] = FLOOR;
+        }
+    }
+}
+
 void DrawMap()
 {
     //Draw map on screen
@@ -337,149 +351,38 @@
     }
 }
 
-void Neighbours()
-{
-
-    //Check neighbours
-    n = 0;
-
-    if(map[sx+1][sy] == FLOOR) {
-        n++;
-    }
-    if(map[sx-1][sy] == FLOOR) {
-        n++;
-    }
-    if(map[sx][sy+1] == FLOOR) {
-        n++;
-    }
-    if(map[sx][sy-1] == FLOOR) {
-        n++;
-    }
-}
-
 void Maze()
 {
 
-    //Random start point
-    sx = rand()%84;
-    sy = rand()%48;
-
-    char unvisited = 0x0; //0000 (Up, Down, Left, Right)
-
-    int visited[84][48];
-
-    int totalVisited = 0; //Max 4032
-
-    map[sx][sy] = FLOOR;
-    visited[sx][sy] = 1;
-
-    while(totalVisited < 4032) {
-        DrawMap();
-        unvisited = 0x0;
+    for(int i = 0; i < 84; i+=2) {
+        for(int j = 0; j < 48; j+=2) {
 
-        //Check if cell neighbours are visited
-        if(visited[sx+1][sy] == 0 && sx < 83) {
-            unvisited |= (1<<0); //Set 1st bit to 1
-        }
-        if(visited[sx-1][sy] == 0 && sx > 1) {
-            unvisited |= (1<<1); //Set 2nd bit to 1
-        }
-        if(visited[sx][sy-1] == 0 && sy > 1) {
-            unvisited |= (1<<2); //Set 3rd bit to 1
-        }
-        if(visited[sx][sy+1] == 0 && sy < 47) {
-            unvisited |= (1<<3); //Set 4th bit to 1
-        }
-
-        dir = rand()%4;
+            map[i][j] = FLOOR;
 
-        if(dir == RIGHT && (0x1 & unvisited)) {
-            sx++;
-            visited[sx][sy] = 1;
-            totalVisited++;
-
-            //Check neighbours
-            Neighbours();
-
-            //If only has 1 neighbour create floor
-            if(n == 1) {
-                map[sx][sy] = FLOOR;
-            } else {
-                sx = rand()%84;
-                sy = rand()%48;
-
-                Neighbours();
-            }
-            while(visited[sx][sy] == 1 || n != 1 || map[sx][sy] != WALL);
-            
-        } else if(dir == LEFT && (0x2 & unvisited)) {
-            sx--;
-            visited[sx][sy] = 1;
-            totalVisited++;
+            dir = rand()%2; //South or east
 
-            //Check neighbours
-            Neighbours();
-
-            //If only has 1 neighbour create floor
-            if(n == 1) {
-                map[sx][sy] = FLOOR;
-            } else {
-                sx = rand()%84;
-                sy = rand()%48;
-
-                Neighbours();
-            }
-            while(visited[sx][sy] == 1 || n != 1 || map[sx][sy] != WALL);
-            
-        } else if(dir == DOWN && (0x4 & unvisited)) {
-            sy--;
-            visited[sx][sy] = 1;
-            totalVisited++;
-
-            //Check neighbours
-            Neighbours();
-
-            //If only has 1 neighbour create floor
-            if(n == 1) {
-                map[sx][sy] = FLOOR;
-            } else {
-                sx = rand()%84;
-                sy = rand()%48;
-
-                Neighbours();
+            if(dir == SOUTH && j < 47) {
+                map[i][j+1] = FLOOR;
             }
-            while(visited[sx][sy] == 1 || n != 1 || map[sx][sy] != WALL);
-            
-        } else if(dir == UP && (0x8 & unvisited)) {
-            sy++;
-            visited[sx][sy] = 1;
-            totalVisited++;
-
-            //Check neighbours
-            Neighbours();
-
-            //If only has 1 neighbour create floor
-            if(n == 1) {
-                map[sx][sy] = FLOOR;
-            } else {
-                sx = rand()%84;
-                sy = rand()%48;
-
-                Neighbours();
+            if(dir == EAST && i < 84) {
+                map[i+1][j] = FLOOR;
             }
-            while(visited[sx][sy] == 1 || n != 1 || map[sx][sy] != WALL);
-        } else if((0x1 & unvisited) || (0x2 & unvisited) || (0x4 & unvisited) || (0x8 & unvisited)) {
-            continue;
-        } else {
-            //Find new starting co-ordinate
-            do {
-                sx = rand()%84;
-                sy = rand()%48;
-
-                Neighbours();
-            } while(visited[sx][sy] == 1 || n != 1 || map[sx][sy] != WALL);
         }
     }
+
+    for(int del = rand()%250 + 151; del > 0; del--) {
+
+        int i = rand()% 84;
+        int j = rand()% 48;
+
+        if(rand()%2 == 0) {
+            map[i][j] = FLOOR;
+        }
+    }
+    
+    
+    
+
 }
 
 void MineBuilder()
@@ -504,7 +407,6 @@
 
 void DungeonBuilder()
 {
-    Walls();
 
     int rn = rand()%20 + 20;
 
@@ -512,18 +414,18 @@
         DungeonRoomBuilder();
     }
 
-    int cn = rand()%20 + 20;
+    DrawMap();
+    wait(1.0);
 
-    for(int i = cn; i>0; i--) {
-        MineCorridorBuilder();
-    }
+    Maze();
+
 }
 
 void World()
 {
     Walls();
-    MineBuilder();
-    //DungeonBuilder();
+    //MineBuilder();
+    DungeonBuilder();
     DrawMap();
 
 }
@@ -542,9 +444,7 @@
 
     //Game loop
     while(1) {
-        Maze();
-
-        //World();
-        wait(2.0);
+        World();
+        wait(10.0);
     }
 }
\ No newline at end of file