Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How Can I Write a Program About the Maze Game in C++?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 35
    Comment on it

    Below are the rules involved in the Programming of a Maze Game :

     

    The maze is made out of walls and a path. The starting point of the maze is marked by the coordinates of the player. Similarly, the exit is marked as a dedicated coordinate. The goal of this program is to report the player's moves in the maze.

     

    Write a program that reads an input file with a description of the maze, the start coordinates of the player, the coordinates of the exit, and a list of player moves. The file name shall be taken from the command line parameters of your program. (See Assignment 5.2 for how to do that.) The information from the file is supposed to be stored in suitable data structures (read: classes). Once the input file has been read, the maze shall be printed to the screen. Next, the list of player moves shall be executed. Finally, the maze shall be printed again, followed by a message whether or not the player has reached the exit.

     

    Format of the input files:

    • Height and width of the maze
    • Layout of the maze ('l' denotes a wall, '.' denotes a path)
    • Row and column of the exit
    • Row and column of the player's start position
    • List of player moves ('u' denotes up, 'd' denotes down, 'l' denotes left, and 'r' denotes right)

     

    The coordinates within the maze range from (0,0) to (height-1,width-1). The coordinate (0,0) is at the top left.

     

    Example input file:

    4 6
    lll.ll
    ll..ll
    l..lll
    ..llll
    0 3
    3 0
    rururu

     

    The corresponding output for processing this file is:

    lllxll
    ll..ll
    l..lll
    P.llll
    
    lllPll
    ll..ll
    l..lll
    ..llll
    
    
    The player reached the exit!

     

    In case of errors, your program shall print an error message and stop. All error messages begin with the string, "an error occurred: ", followed by one of the following messages:

    • "no input file name given"
    • "could not open input file "+ fileName
    • "could not read height and width of the maze"
      • read error from file
    • "could not read maze layout"
      • read error from file, or character is neither 'l' nor '.'
    • "could not read coordinates"
      • read error from file
    • item + " outside maze or off the path"
      • Here, item is either "player" or "exit"
      • This may happen in two cases:
        • with incorrect coordinates in the input file
        • with a move that makes the player run into a wall
    • "invalid move"
      • move is none of 'l', 'r', 'u', 'd'

     

    Your program must implement at least two classes. (But having more classes is appreciated!) For example, since the maze is a two dimensional structure, it might be useful to create a class to represent a coordinate. Another class could be used to handle the layout of the maze. Another one could handle all information regarding the current state of the game.

     

    Here are some files to test with:

    4 6
    lll.ll
    ll..ll
    l..lll
    ..llll
    0 3
    3 0
    rururu

    or:

    10 eight
    lll.llll
    lll...ll
    lllll.ll
    lllll.ll
    lllll.ll
    l...l.ll
    l.l...ll
    l..lllll
    ll.lllll
    ll.lllll
    0 3
    9 2
    uuluurrdrruuuuullu

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: