Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: N5110 PowerControl mbed
Diff: main.cpp
- Revision:
- 5:9bd276652111
- Parent:
- 4:6482ceb08dc8
- Child:
- 6:ca5db4353c95
--- a/main.cpp Fri Apr 17 00:56:02 2015 +0000 +++ b/main.cpp Fri Apr 17 01:20:18 2015 +0000 @@ -142,6 +142,26 @@ map[enx][eny] = ENTER; } +void ExitRoom() +{ + //Create initial room + int si = rand()%50 + 30; + int sj = rand()%25 + 20; + + int sw = rand()%5+5; + int sh = rand()%5+5; + + for(int i = si, w = si + sw; i <w; i++) { + for (int j = sj, h = sj + sh; j <h; j++) { + map[i][j] = FLOOR; + } + } + //Create enterance in room + enx = rand()%sw + si; + eny = rand()%sh + sj; + map[enx][eny] = EXIT; +} + void SetExit() { do { @@ -373,7 +393,7 @@ void DeadEnds() { - for (int del = rand()%5 + 1; del > 0; del--) { + for (int del = 20; del > 0; del--) { for(int i = 0; i < 84; i++) { for(int j = 0; j < 48; j++) { @@ -390,21 +410,37 @@ } } +void Border() +{ + + for(int i = 0; i < 84; i++) { + for(int j = 0; j < 48; j++) { + + if(i == 0 || i == 83 || j == 0 || j == 47) { + + map[i][j] = WALL; + + } + } + } +} void Maze() { for(int i = 0; i < 84; i+=2) { for(int j = 0; j < 48; j+=2) { - map[i][j] = FLOOR; + if(map[i][j] == WALL) { + map[i][j] = FLOOR; + } dir = rand()%2; //South or east - if(dir == SOUTH && j < 47) { + if(dir == SOUTH && j < 47 && map[i][j+1] == WALL) { map[i][j+1] = FLOOR; } - if(dir == EAST && i < 84) { + if(dir == EAST && i < 84 && map[i+1][j] == WALL) { map[i+1][j] = FLOOR; } } @@ -415,11 +451,13 @@ int i = rand()% 84; int j = rand()% 48; - if(rand()%2 == 0) { + if(rand()%2 == 0 && map[i][j] == WALL) { map[i][j] = FLOOR; } } + Border(); + DeadEnds(); } @@ -448,6 +486,7 @@ { FirstRoom(); + ExitRoom(); int rn = rand()%20 + 20; @@ -455,7 +494,7 @@ DungeonRoomBuilder(); } - SetExit(); + DrawMap(); wait(2.0);