From 93221b5eafbc9e51eb7024a6a38e4356ba548c03 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 27 Dec 2015 16:34:17 +0100 Subject: [PATCH] Aggiunto algoritmo di generazione livelli. --- main.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index f48ddb8..4c8b295 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,11 @@ #include +#include +#include + #define X_MAX 80 #define Y_MAX 23 +#define ROOMS 8 +#define ROOM_SIZE 7 using namespace std; @@ -108,12 +113,34 @@ void corridor(char map[X_MAX][Y_MAX], int start_x, int start_y, int end_x, int e } } +void generate(char map[X_MAX][Y_MAX]) +{ + int corridor_x; + int corridor_y; + for(int r=0; r 0) + { + int link_x = rand() % size_x + 1 + start_x; + int link_y = rand() % size_y + 1 + start_y; + corridor(map, link_x, link_y, corridor_x, corridor_y, rand() % 2); + } + corridor_x = rand() % size_x + start_x; + corridor_y = rand() % size_y + start_y; + } +} + int main() { char map[X_MAX][Y_MAX]; //Mappa del gioco + srand(time(NULL)); //TODO: Rendere il seed modificabile init(map); - corridor(map, 1, 1, 3, 3, true); - corridor(map, 5, 5, 7, 7, false); + generate(map); draw(map); return 0; }