X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/form?a=blobdiff_plain;f=roguelike.c;h=0521ae953e818299c41bf6b461649cfbd347d527;hb=c9b91ea7cb25ac97e736935b1f5f26d7f0d58ef6;hp=6217fec2713128b4b4987c52f5f34e841da66078;hpb=98588def4ac3ab05cb815814de67a44f506ae569;p=plomrogue diff --git a/roguelike.c b/roguelike.c index 6217fec..0521ae9 100644 --- a/roguelike.c +++ b/roguelike.c @@ -54,8 +54,8 @@ void write_uint32_bigendian(uint32_t x, FILE * file) { fputc(c, file); fputc(d, file); } -void load_seed(struct World * world) { -// Load seed integer from seed file. +void load_game(struct World * world) { +// Load game data from game file. FILE * file = fopen("savefile", "r"); world->seed = read_uint32_bigendian(file); world->turn = read_uint32_bigendian(file); @@ -65,8 +65,8 @@ void load_seed(struct World * world) { world->monster->x = read_uint16_bigendian(file); fclose(file); } -void save_seed(struct World * world) { -// Save seed integer to seed file. +void save_game(struct World * world) { +// Save game data to game file. FILE * file = fopen("savefile", "w"); write_uint32_bigendian(world->seed, file); write_uint32_bigendian(world->turn, file); @@ -220,24 +220,24 @@ void player_wait (struct World * world) { int main (int argc, char *argv[]) { struct World world; + init_keybindings(&world); + + world.log = calloc(1, sizeof(char)); + update_log (&world, " "); struct Player player; world.player = &player; struct Monster monster; world.monster = &monster; if (0 == access("savefile", F_OK)) - load_seed(&world); + load_game(&world); else { player.y = 8; player.x = 8; monster.y = 55; monster.x = 55; world.seed = time(NULL); - world.turn = 0; } + world.turn = 1; } rrand(1, world.seed); - - init_keybindings(&world); - world.log = calloc(1, sizeof(char)); - update_log (&world, "Start!"); struct Map map = init_map(); world.map = ↦ @@ -253,7 +253,11 @@ int main (int argc, char *argv[]) { struct Win win_log = init_window(&win_meta, "Log", &world, draw_log_win); int key; + uint32_t last_turn = 0; while (1) { + if (last_turn != world.turn) { + save_game(&world); + last_turn = world.turn; } draw_all_windows (&win_meta); key = getch(); if (key == get_action_key(world.keybindings, "quit")) @@ -294,8 +298,6 @@ int main (int argc, char *argv[]) { keyswin_move_selection (&world, 'd'); else if (key == get_action_key(world.keybindings, "keys mod")) keyswin_mod_key (&world, &win_meta); - else if (key == get_action_key(world.keybindings, "save game")) - save_seed(&world); else if (key == get_action_key(world.keybindings, "map up")) map_scroll (&map, 'n'); else if (key == get_action_key(world.keybindings, "map down"))