Thomas Gill / Mbed 2 deprecated LabyrinthOfTheMinotaur

Dependencies:   N5110 PowerControl mbed

Revision:
4:6482ceb08dc8
Parent:
3:1a25939df22a
Child:
5:9bd276652111
--- a/main.cpp	Fri Apr 17 00:18:50 2015 +0000
+++ b/main.cpp	Fri Apr 17 00:56:02 2015 +0000
@@ -351,9 +351,48 @@
     }
 }
 
+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 DeadEnds()
+{
+    for (int del = rand()%5 + 1; del > 0; del--) {
+        for(int i = 0; i < 84; i++) {
+            for(int j = 0; j < 48; j++) {
+
+                sx = i;
+                sy = j;
+
+                Neighbours();
+
+                if(n == 1) {
+                    map[i][j] = WALL;
+                }
+            }
+        }
+    }
+}
+
+
 void Maze()
 {
-
     for(int i = 0; i < 84; i+=2) {
         for(int j = 0; j < 48; j+=2) {
 
@@ -361,6 +400,7 @@
 
             dir = rand()%2; //South or east
 
+
             if(dir == SOUTH && j < 47) {
                 map[i][j+1] = FLOOR;
             }
@@ -370,7 +410,7 @@
         }
     }
 
-    for(int del = rand()%250 + 151; del > 0; del--) {
+    for(int space = rand()%50 + 51; space > 0; space--) {
 
         int i = rand()% 84;
         int j = rand()% 48;
@@ -379,9 +419,8 @@
             map[i][j] = FLOOR;
         }
     }
-    
-    
-    
+
+    DeadEnds();
 
 }
 
@@ -408,14 +447,18 @@
 void DungeonBuilder()
 {
 
+    FirstRoom();
+
     int rn = rand()%20 + 20;
 
     for(int i = rn; i>0; i--) {
         DungeonRoomBuilder();
     }
 
+    SetExit();
+
     DrawMap();
-    wait(1.0);
+    wait(2.0);
 
     Maze();
 
@@ -445,6 +488,6 @@
     //Game loop
     while(1) {
         World();
-        wait(10.0);
+        wait(4.0);
     }
 }
\ No newline at end of file