Labyrinth of the Minotaur A simple roguelike/RPG using a nokia 5110 screen

Dependencies:   N5110 PowerControl mbed

Revision:
36:b64696135142
Parent:
35:2c290fa78f1d
--- a/WorldBuilder/WorldBuilder.cpp	Mon May 11 22:03:41 2015 +0000
+++ b/WorldBuilder/WorldBuilder.cpp	Mon May 11 22:25:57 2015 +0000
@@ -34,6 +34,8 @@
 void FirstRoom()
 {
     //Create initial room
+    
+    //Generate starting coordinates
     int si = rand()%25 + 1;
     int sj = rand()%15 + 1;
 
@@ -55,8 +57,9 @@
 
 void ExitRoom()
 {
-
     //Create exit room
+    
+    //Generate starting coordinates
     int si = rand()%50 + 30;
     int sj = rand()%25 + 20;
 
@@ -77,6 +80,7 @@
 
 void DungeonRoomBuilder()
 {
+    //Generate starting coordinates
     sx = rand() % (MAP_WIDTH - 1) + 1;
     sy = rand() % (MAP_HEIGHT - 1) + 1;
 
@@ -95,6 +99,7 @@
     }
 
     if (rand() % 3 == 0) {
+        //Build chest at random coordinate in room
         int i = rand() % sw + sx;
         int j = rand() % sh + sy;
         map[i][j] = CHEST;
@@ -124,11 +129,12 @@
 
 void DeadEnds(int d)
 {
-    for (int del = d; del > 0; del--) {
+    for (int del = d; del > 0; del--) { //Iterate the code d amount of times
+    
         for (int i = 0; i < 84; i++) {
             for (int j = 0; j < 48; j++) {
 
-                if (Neighbours(i, j) < 2) {
+                if (Neighbours(i, j) < 2) { //If an island or dead end then turn the floor into a wall
                     map[i][j] = WALL;
                 }
             }
@@ -138,7 +144,6 @@
 
 void Border()
 {
-
     for (int i = 0; i < 84; i++) {
         for (int j = 0; j < 48; j++) {
 
@@ -154,8 +159,9 @@
 void RandFloor(int r)
 {
 
-    for (int space = rand() % 50 + r; space > 0; space--) {
+    for (int space = rand() % 50 + r; space > 0; space--) { //Iterate code r amount of times
 
+        //Randomly generate coordinates
         int i = rand() % 84;
         int j = rand() % 48;
 
@@ -168,7 +174,7 @@
 
 void MazeKill()
 {
-
+    //Array which stores the order in which directions whill be checked
     int move[4] = { UP, DOWN, LEFT, RIGHT };
 
     bool moved = true;
@@ -188,9 +194,10 @@
             move[r] = temp;
         }
 
-
-
         for (int i = 0; i < 3; i++) {
+            //For (direction) check if there are walls 2 tiles in that directions 
+            //and check that they do not interfere with any part of the maze that has already been built
+            
             if (move[i] == UP) {
                 if (map[sx][sy - 1] == WALL && Neighbours(sx, sy - 1) == 1 && map[sx][sy - 2] == WALL && Neighbours(sx, sy - 2) == 0 && sy > 3) {
                     map[sx][sy - 1] = FLOOR;
@@ -231,6 +238,7 @@
 
 void Maze()
 {
+    //Start in top left corner
     sx = 1;
     sy = 1;
 
@@ -248,7 +256,7 @@
 
         end = true;
 
-        map[sx][sy] = FLOOR;
+        map[sx][sy] = FLOOR; //Set current tile to a floor
 
         MazeKill();
 
@@ -261,7 +269,7 @@
                     sx = i;
                     sy = j;
 
-                    end = false;
+                    end = false; //If a wall tile in the array has only one neighbouring space that is a floor then more of the maze can be built so the generation has not yet finished 
                 }
 
             }
@@ -284,13 +292,11 @@
         DungeonRoomBuilder();
     }
 
-
-
     RandFloor(31);
 
     Border();
 
-    DeadEnds(50);
+    DeadEnds(50); //Remove lots of dead ends to make the map less confusing
 
 }
 
@@ -302,11 +308,9 @@
     FirstRoom();
     ExitRoom();
 
-
-
     RandFloor(151);
 
-    DeadEnds(1);
+    DeadEnds(1); //Only remove some of the dead ends so that the map is still a challenge
 
     Border();