write_uint16_bigendian(world->player->x, file);
write_uint16_bigendian(world->monster->y, file);
write_uint16_bigendian(world->monster->x, file);
+ write_uint16_bigendian(world->monster->next->y, file);
+ write_uint16_bigendian(world->monster->next->x, file);
+ write_uint16_bigendian(world->monster->next->next->y, file);
+ write_uint16_bigendian(world->monster->next->next->x, file);
fclose(file); }
void record_action (char action) {
// 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;
- if (1 == d)
- ty++;
- else if (2 == d)
- ty--;
- else if (3 == d)
- tx++;
- else if (4 == d)
- tx--;
- if (tx == world->player->x && ty == world->player->y)
- update_log(world, "\nThe monster hits you.");
- else if (is_passable(world->map, ty, tx)) {
- world->monster->y = ty;
- world->monster->x = tx; } }
+ char d;
+ struct Monster * monster;
+ uint16_t ty, tx;
+ for (monster = world->monster; monster != 0; monster = monster->next) {
+ d = rrand(0, 0) % 5;
+ ty = monster->y;
+ tx = monster->x;
+ if (1 == d)
+ ty++;
+ else if (2 == d)
+ ty--;
+ else if (3 == d)
+ tx++;
+ else if (4 == d)
+ tx--;
+ if (tx == world->player->x && ty == world->player->y)
+ update_log(world, "\nThe monster hits you.");
+ else if (is_passable(world->map, ty, tx)) {
+ monster->y = ty;
+ monster->x = tx; } } }
void update_log (struct World * world, char * text) {
// Update log with new text to be appended.
if ('e' == d) {
dir = "east";
tx++; }
- if (ty == world->monster->y && tx == world->monster->x)
- success = 2;
- else if (is_passable(world->map, ty, tx)) {
+ struct Monster * monster;
+ for (monster = world->monster; monster != 0; monster = monster->next)
+ if (ty == monster->y && tx == monster->x) {
+ success = 2;
+ break; }
+ if (2 != success && is_passable(world->map, ty, tx)) {
success = 1;
world->player->y = ty;
world->player->x = tx; }
update_log (&world, " ");
struct Player player;
world.player = &player;
- struct Monster monster;
- world.monster = &monster;
+ 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';
FILE * file;
if (1 == world.interactive && 0 == access("savefile", F_OK)) {
file = fopen("savefile", "r");
world.turn = read_uint32_bigendian(file);
player.y = read_uint16_bigendian(file);
player.x = read_uint16_bigendian(file);
- monster.y = read_uint16_bigendian(file);
- monster.x = read_uint16_bigendian(file);
+ monster1.y = read_uint16_bigendian(file);
+ monster1.x = read_uint16_bigendian(file);
+ monster2.y = read_uint16_bigendian(file);
+ monster2.x = read_uint16_bigendian(file);
+ monster3.y = read_uint16_bigendian(file);
+ monster3.x = read_uint16_bigendian(file);
fclose(file); }
else {
world.turn = 1;
for (player.y = player.x = 0; 0 == is_passable(&map, player.y, player.x);) {
player.y = rrand(0, 0) % map.height;
player.x = rrand(0, 0) % map.width; }
- for (monster.y = monster.x = 0; 0 == is_passable(&map, monster.y, monster.x);) {
- monster.y = rrand(0, 0) % map.height;
- monster.x = rrand(0, 0) % map.width; } }
+ struct Monster * monster;
+ for (monster = world.monster; monster != 0; monster = monster->next)
+ for (monster->y = monster->x = 0; 0 == is_passable(&map, monster->y, monster->x);) {
+ monster->y = rrand(0, 0) % map.height;
+ monster->x = rrand(0, 0) % map.width; } }
WINDOW * screen = initscr();
noecho();