thrive/01_text_adventure/transition.c

33 lines
1007 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "transition.h"
#include "game.h"
#define TRANSITIONS_PATH "./transitions.txt"
char transition_buffer[2001];
void game_load_transitions(Game *g) {
FILE *transitions_file = fopen(TRANSITIONS_PATH, "r");
while ((fgets(transition_buffer, 2000, transitions_file)) != NULL) {
char *token = strtok(transition_buffer, "|");
g->transitions->transitions[g->transitions->count].from = find_room(g->rooms, token);
token = strtok(NULL, "|");
g->transitions->transitions[g->transitions->count].via = command_from_string(token);
token = strtok(NULL, "|");
g->transitions->transitions[g->transitions->count].to = find_room(g->rooms, token);
token = strtok(NULL, "|");
g->transitions->transitions[g->transitions->count].description = malloc(strlen(token) + 1);
strcpy(g->transitions->transitions[g->transitions->count].description, token);
g->transitions->count++;
}
fclose(transitions_file);
}