+char is_passable (struct World * world, int x, int y) {
+// Check if coordinate on (or beyond) map is accessible to movement.
+ char passable = 0;
+ if (0 <= x && x < world->map->width && 0 <= y && y < world->map->height)
+ if ( '.' == world->map->cells[y * world->map->width + x]
+ && (y != world->monster->y || x != world->monster->x))
+ passable = 1;
+ return passable; }
+
+void move_player (struct World * world, char d) {
+// Move player in direction d, increment turn counter and update log.
+ static char prev = 0;
+ char success = 0;
+ char * dir;
+ if ('s' == d) {
+ dir = "south";
+ if (is_passable(world, world->player->x, world->player->y + 1)) {
+ world->player->y++;
+ success = 1; } }
+ else if ('n' == d) {
+ dir = "north";
+ if (is_passable(world, world->player->x, world->player->y - 1)) {
+ world->player->y--;
+ success = 1; } }
+ else if ('w' == d) {
+ dir = "west";
+ if (is_passable(world, world->player->x - 1, world->player->y)) {
+ world->player->x--;
+ success = 1; } }
+ else if ('e' == d) {
+ dir = "east";
+ if (is_passable(world, world->player->x + 1, world->player->y)) {
+ world->player->x++;
+ success = 1; } }
+ if (success * d == prev)
+ update_log (world, ".");
+ else {
+ char * msg = calloc(25, sizeof(char));
+ char * msg_content = "You fail to move";
+ if (success)
+ msg_content = "You move";
+ sprintf(msg, "\n%s %s.", msg_content, dir);
+ update_log (world, msg);
+ free(msg); }
+ prev = success * d;
+ update_info (world); }
+