Print room description when first entering a room
This commit is contained in:
parent
42e90b8531
commit
bfc20bdfce
@ -13,7 +13,7 @@ void cause_effect(Game *g, Effect *e) {
|
||||
case EFFECT_NOOP:
|
||||
break;
|
||||
case EFFECT_GOTO:
|
||||
g->current_room = find_room(g->rooms, e->argument);
|
||||
change_current_room(g, find_room(g->rooms, e->argument));
|
||||
break;
|
||||
case EFFECT_INCREMENT:
|
||||
find_flag(g->flags, e->argument)->value++;
|
||||
@ -31,7 +31,6 @@ void cause_effect(Game *g, Effect *e) {
|
||||
g->should_close = true;
|
||||
break;
|
||||
case EFFECT_LOOK_ROOM:
|
||||
// TODO
|
||||
push_line_to_log(g->input->log, find_room_in(g)->description);
|
||||
break;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ Game *game_create(void) {
|
||||
|
||||
g->input = input;
|
||||
|
||||
change_current_room(g, &g->rooms->rooms[0]);
|
||||
return g;
|
||||
}
|
||||
|
||||
@ -85,3 +86,11 @@ void game_run_until_close(Game *g) {
|
||||
game_draw(g);
|
||||
}
|
||||
}
|
||||
|
||||
void change_current_room(Game *g, Room *r) {
|
||||
g->current_room = r;
|
||||
if (!r->visited) {
|
||||
push_line_to_log(g->input->log, find_room_in(g)->description);
|
||||
}
|
||||
r->visited = true;
|
||||
}
|
||||
|
@ -43,5 +43,6 @@ void game_run_until_close(Game *g);
|
||||
void game_handle_input(Game *g);
|
||||
void game_draw(Game *g);
|
||||
void free_game(Game *g);
|
||||
void change_current_room(Game *g, Room *r);
|
||||
|
||||
#endif
|
||||
|
@ -11,6 +11,8 @@ void load_room(Game *g, char *line) {
|
||||
g->rooms->rooms[g->rooms->count].name = malloc(strlen(token) + 1);
|
||||
strcpy(g->rooms->rooms[g->rooms->count].name, token);
|
||||
|
||||
g->rooms->rooms[g->rooms->count].visited = false;
|
||||
|
||||
g->rooms->count++;
|
||||
}
|
||||
|
||||
@ -20,7 +22,6 @@ void game_load_rooms(Game *g) {
|
||||
g->rooms->count = 0;
|
||||
parse_multiline_string(g, data_rooms_txt, &load_room);
|
||||
printf("loaded rooms\n");
|
||||
g->current_room = &g->rooms->rooms[0];
|
||||
}
|
||||
|
||||
void free_room(Room r) {
|
||||
|
@ -4,8 +4,11 @@
|
||||
typedef struct Room Room;
|
||||
typedef struct Rooms Rooms;
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct Room {
|
||||
char *name;
|
||||
bool visited;
|
||||
};
|
||||
|
||||
struct Rooms {
|
||||
|
Loading…
Reference in New Issue
Block a user