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:
- 6:ca5db4353c95
- Parent:
- 5:9bd276652111
- Child:
- 7:cd799c701997
--- a/main.cpp Fri Apr 17 01:20:18 2015 +0000 +++ b/main.cpp Fri Apr 17 01:26:50 2015 +0000 @@ -144,7 +144,7 @@ void ExitRoom() { - //Create initial room + //Create exit room int si = rand()%50 + 30; int sj = rand()%25 + 20; @@ -156,191 +156,12 @@ map[i][j] = FLOOR; } } - //Create enterance in room + //Create exit in room enx = rand()%sw + si; eny = rand()%sh + sj; map[enx][eny] = EXIT; } -void SetExit() -{ - do { - exx = enx + rand()%30 +15; - exy = eny + rand()%20 +15; - } while(map[exx][exy] == WALL && exx > 84 && exy > 48); - - map[exx][exy] = EXIT; - -} - -void MinePoint() -{ - //Find start location - for(int i=0; i<84; i++) { - for (int j=0; j<48; j++) { - - int r = rand()%6; - - if(map[i][j] == FLOOR && map[i+1][j] == WALL && r == 0) { - dir = RIGHT; - sx = i; - sy = j; - break; - } else if(map[i][j] == FLOOR && map[i-1][j] == WALL && r == 0) { - dir = LEFT; - sx = i; - sy = j; - break; - } else if(map[i][j] == FLOOR && map[i][j+1] == WALL && r == 0) { - dir = UP; - sx = i; - sy = j; - break; - } else if(map[i][j] == FLOOR && map[i][j-1] == WALL && r == 0) { - dir = DOWN; - sx = i; - sy = j; - break; - } - } - } -} - -void MineCorridorBuilder() -{ - MinePoint(); - - //Get length - int l = rand()%5 + 5; - - //Check direction of corridor - if(dir == RIGHT) { - for(int i = l; i>0; i--) { - if(map[sx+1][sy] == WALL && map[sx+1][sy+1] == WALL && map[sx+1][sy-1] == WALL && sx < 83) { - sx++; - map[sx][sy] = FLOOR; - } else - break; - } - } else if(dir == LEFT) { - for(int i = l; i>0; i--) { - if(map[sx-1][sy] == WALL && map[sx-1][sy+1] == WALL && map[sx-1][sy-1] == WALL && sx > 1) { - sx--; - map[sx][sy] = FLOOR; - } else - break; - } - } else if(dir == UP) { - for(int i = l; i>0; i--) { - if(map[sx][sy+1] == WALL && map[sx-1][sy+1] == WALL && map[sx+1][sy+1] == WALL && sy < 47) { - sy++; - map[sx][sy] = FLOOR; - } else - break; - } - } else if(dir == DOWN) { - for(int i = l; i>0; i--) { - if(map[sx][sy-1] == WALL && map[sx-1][sy-1] == WALL && map[sx+1][sy-1] == WALL && sy > 1) { - sy--; - map[sx][sy] = FLOOR; - } else - break; - } - } -} - -void MineRoomBuilder() -{ - MinePoint(); - - //Get length - int sw = rand()%5 + 5; - int sh = rand()%5 + 5; - - int b = 0; - - if(dir == RIGHT) { - sx++; - //Check each space. +1 to variable if wall. If total = w*h then build room - for(int i = sx; i < sx + sw; i++) { - for(int j = sy; j < sy + sh; j++) { - if(map[i][j] == WALL) { - b++; - } - } - } - if(b == sw*sh) { - for(int i = sx; i < sx + sw; i++) { - for(int j = sy; j < sy + sh; j++) { - if(i < 84 && j < 48) { - map[i][j] = FLOOR; - } - } - } - } - } - if(dir == LEFT) { - sx--; - //Check each space. +1 to variable if wall. If total = w*h then build room - for(int i = sx; i > sx - sw; i--) { - for(int j = sy; j < sy + sh; j++) { - if(map[i][j] == WALL) { - b++; - } - } - } - if(b == sw*sh) { - for(int i = sx; i > sx - sw; i--) { - for(int j = sy; j < sy + sh; j++) { - if(i < 84 && j < 48) { - map[i][j] = FLOOR; - } - } - } - } - } - if(dir == UP) { - sy++; - //Check each space. +1 to variable if wall. If total = w*h then build room - for(int i = sx; i < sx + sw; i++) { - for(int j = sy; j < sy + sh; j++) { - if(map[i][j] == WALL) { - b++; - } - } - } - if(b == sw*sh) { - for(int i = sx; i < sx + sw; i++) { - for(int j = sy; j < sy + sh; j++) { - if(i < 84 && j < 48) { - map[i][j] = FLOOR; - } - } - } - } - } - if(dir == DOWN) { - sy--; - //Check each space. +1 to variable if wall. If total = w*h then build room - for(int i = sx; i < sx + sw; i++) { - for(int j = sy; j > sy - sh; j--) { - if(map[i][j] == WALL) { - b++; - } - } - } - if(b == sw*sh) { - for(int i = sx; i < sx + sw; i++) { - for(int j = sy; j > sy - sh; j--) { - if(i < 84 && j < 48) { - map[i][j] = FLOOR; - } - } - } - } - } -} - void DungeonRoomBuilder() { sx = rand()%84; @@ -462,26 +283,6 @@ } -void MineBuilder() -{ - Walls(); - - FirstRoom(); - - int fn = rand()%20 + 20; - - for(int i = fn; i>0; i--) { - int f = rand()% 5; - if(f == 0) { - MineRoomBuilder(); - } else { - MineCorridorBuilder(); - } - } - - SetExit(); -} - void DungeonBuilder() { @@ -506,8 +307,9 @@ void World() { Walls(); - //MineBuilder(); + DungeonBuilder(); + DrawMap(); }