fputc(c, file);
fputc(d, file); }
-void load_seed(struct World * world) {
+void load_game(struct World * world) {
// Load seed integer from seed file.
FILE * file = fopen("savefile", "r");
world->seed = read_uint32_bigendian(file);
world->monster->x = read_uint16_bigendian(file);
fclose(file); }
-void save_seed(struct World * world) {
+void save_game(struct World * world) {
// Save seed integer to seed file.
FILE * file = fopen("savefile", "w");
write_uint32_bigendian(world->seed, file);
void next_turn (struct World * world) {
// Increment turn and move enemy.
world->turn++;
+ rrand(1, world->seed * world->turn);
char d = rrand(0, 0) % 5;
uint16_t ty = world->monster->y;
uint16_t tx = world->monster->x;
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);
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"))
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"))