/*
 * A simple maze game.
 *
 * Author: Zach Tomaszewski
 */

#include <stdio.h>
#include "maze.h"


/*
 * Repeatedly prints a room map showing the player's current location
 * and an exit.  Each turn, asks the user to move.  When the player
 * reaches the exit, the game ends.
 */
int main() {
  
  //player starts in center of room.
  //(x increases left-to-right; y increases top-to-bottom)
  int playerX = WIDTH / 2;
  int playerY = HEIGHT / 2;
  
  //exit is in lower right corner
  int exitX = WIDTH - 1;
  int exitY = HEIGHT - 1;
  
  //Explain game to user
  printf("Try to escape the maze!  Move yourself (%c) to the exit (%c).\n", 
      PLAYER, EXIT);

  //play the game
  while (!(playerX == exitX && playerY == exitY)) {
    int move, success;
    
    //show room and get user's move
    printRoom(playerX, playerY, exitX, exitY);
    move = getUserMove();
    success = movePlayer(move, &playerX, &playerY);
    if (success == -1) {
      puts("Invalid move: You can only leave the room through the exit.");
    }
  }

  //loop only exits when player makes it to exit, so: congrats
  printf("\nCongratulations!  You made it out alive.\n");

  return 0;
}
