From: Christian Heller Date: Tue, 2 Jul 2013 01:40:06 +0000 (+0200) Subject: Refactored / made more flexible: item/monster initialization. X-Git-Tag: tce~1178 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/%27%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28escapeHTML%28span%5B2%5D%29%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28%27?a=commitdiff_plain;h=867fe8e2358c8d71919b144f97e4ab272b8f4ebe;p=plomrogue Refactored / made more flexible: item/monster initialization. --- diff --git a/src/roguelike.c b/src/roguelike.c index c5365a1..04da8a6 100644 --- a/src/roguelike.c +++ b/src/roguelike.c @@ -204,31 +204,26 @@ int main (int argc, char *argv[]) { update_log (&world, " "); struct Player player; world.player = &player; - struct Monster monster1; - struct Monster monster2; - struct Monster monster3; - world.monster = &monster1; - monster1.next = &monster2; - monster2.next = &monster3; - monster3.next = 0; - monster1.name = 'A'; - monster2.name = 'B'; - monster3.name = 'C'; - struct Item item1; - struct Item item2; - struct Item item3; - world.item = &item1; - item1.next = &item2; - item2.next = &item3; - item3.next = 0; - item1.name = '&'; - item2.name = '%'; - item3.name = '#'; + char i; + struct Monster * monster = malloc(sizeof(struct Monster)); + world.monster = monster; + for (i = 0; i < 2; i++) { + monster->name = 'M'; + monster->next = malloc(sizeof(struct Monster)); + monster = monster->next; } + monster->name = 'M'; + monster->next = 0; + struct Item * item = malloc(sizeof(struct Item)); + world.item = item; + for (i = 0; i < 2; i++) { + item->name = '#'; + item->next = malloc(sizeof(struct Item)); + item = item->next; } + item->name = '#'; + item->next = 0; // For interactive mode, try to load world state from savefile. FILE * file; - struct Item * item; - struct Monster * monster; if (1 == world.interactive && 0 == access("savefile", F_OK)) { file = fopen("savefile", "r"); world.seed = read_uint32_bigendian(file);