51 lines
881 B
C++
51 lines
881 B
C++
#include "level.h"
|
|
#include <stdlib.h>
|
|
|
|
|
|
static LEVEL *level = NULL;
|
|
|
|
|
|
LEVEL *getLevel() {
|
|
return level;
|
|
}
|
|
|
|
void setLevel(LEVEL *l) {
|
|
level = l;
|
|
}
|
|
|
|
void addRoom(LEVEL *lvl, const ROOM *room) {
|
|
lvl->nRooms++;
|
|
if(lvl->nRooms > 1)
|
|
lvl->rooms = (ROOM*)realloc(lvl->rooms, lvl->nRooms*sizeof(ROOM));
|
|
else
|
|
lvl->rooms = (ROOM*)calloc(1, sizeof(ROOM));
|
|
lvl->rooms[lvl->nRooms-1] = *room;
|
|
}
|
|
|
|
void deleteRoom(LEVEL *lvl, unsigned int n) {
|
|
int i;
|
|
|
|
lvl->nRooms--;
|
|
|
|
for(i = n; i < lvl->nRooms; i++)
|
|
lvl->rooms[i] = lvl->rooms[i+1];
|
|
|
|
lvl->rooms = (ROOM*)realloc(lvl->rooms, lvl->nRooms*sizeof(ROOM));
|
|
}
|
|
|
|
void freeLevel(LEVEL *lvl) {
|
|
int i;
|
|
|
|
if(lvl) {
|
|
if(lvl->rooms) {
|
|
for(i = 0; i < lvl->nRooms; i++) {
|
|
if(lvl->rooms[i].name)
|
|
free(lvl->rooms[i].name);
|
|
}
|
|
|
|
free(lvl->rooms);
|
|
}
|
|
|
|
free(lvl);
|
|
}
|
|
}
|