From 6b5e4d8743c04f8682318f036390a298482d72ea Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 27 Dec 2015 15:52:42 +0100 Subject: [PATCH] Aggiunta creazione di corridoi tra due punti. --- main.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/main.cpp b/main.cpp index 02a8755..f48ddb8 100644 --- a/main.cpp +++ b/main.cpp @@ -41,11 +41,79 @@ void room(char map[X_MAX][Y_MAX], int start_x, int start_y, int end_x, int end_y } } +//Crea un corridoio che connetta due punti +void corridor(char map[X_MAX][Y_MAX], int start_x, int start_y, int end_x, int end_y, bool verticale) +{ + if(verticale) + { + if(start_y > end_y) + { + for(int y=end_y; y<=start_y; y++) + { + map[start_x][y] = '.'; + } + } + else + { + for(int y=start_y; y<=end_y; y++) + { + map[start_x][y] = '.'; + } + } + if(start_x > end_x) + { + for(int x=end_x; x<=start_x; x++) + { + map[x][end_y] = '.'; + } + } + else + { + for(int x=start_x; x<=end_x; x++) + { + map[x][end_y] = '.'; + } + } + } + else + { + if(start_x > end_x) + { + for(int x=end_x; x<=start_x; x++) + { + map[x][start_y] = '.'; + } + } + else + { + for(int x=start_x; x<=end_x; x++) + { + map[x][start_y] = '.'; + } + } + if(start_y > end_y) + { + for(int y=end_y; y<=start_y; y++) + { + map[end_x][y] = '.'; + } + } + else + { + for(int y=start_y; y<=end_y; y++) + { + map[end_x][y] = '.'; + } + } + } +} int main() { char map[X_MAX][Y_MAX]; //Mappa del gioco init(map); + corridor(map, 1, 1, 3, 3, true); + corridor(map, 5, 5, 7, 7, false); draw(map); return 0; }