COSC1076 Advanced Programming Techniques :Car Board Assessment
In this assignment you will build an interesting game called Car Board. The rules for the game are simple: a car can move around inside a board; the player can move the car by entering a set of specific commands; and the car must stay within the board boundaries and must not hit the roadblocks.
In this assignment you will:
- Practice the programming skills such as:
- Pointers
- Dynamic Memory Management
- Arrays/Vectors
- Implement a medium size C++ program using predefined classes
- Use a prescribed set of C++11/14 language features
When the program starts, the following menu should be displayed.
Your program should reject any invalid data. If invalid input is entered (for example: 10, c . . . ), you should simply ignore the input and show the prompt again.
If user enters number 2, your program should print your name, your student number as below. Note that you should replace
If user selects menu number 3, your program should exit without crashing. This is also specified in REQ7 below.
If user selects menu number 1, the following list of commands will be displayed.
The load
The init
The forward turn_left (or l) turn_right (or r)
The quit main menu
It is important to note that the board (containing the blocks, the position and the direction of the car) must be displayed on the screen after it is loaded initialised forward left right currently acceptable commands
REQ2: Displaying the Board
This game has a 10x10 board. When the game starts (right after the Play Game command and before loading any board), the following board should be displayed on the screen.
Note that the board is completely empty. This is exactly how it should look like before any particular board is loaded in the next section.
At this stage of the program, only two commands are acceptable:
-
load
quit
If user enters any other command, or an incorrect command, an error message (e.g. “Invalid Input.”) must be displayed and the menu should be displayed again.
REQ3: Loading Game Boards and Data Structure Initialisation
The application comes with two different predefined boards. The data structure associated with each board is available in the start-up code. The user can load either of these boards as follows. When user starts a game using board number 1:
This is another example where the user starts a game using board number 2:
At this stage you are required to initialise the board with the predefined data values which are available in the start-up code.
The cells in the board which contain a star sign (*) are blocked. The car cannot move to those cells. If the user attempts to move the car to one of those cells by the forward
At this stage of the program, only three commands are acceptable:
-
load
init
, , quit
If user enters any other command, or an incorrect command, an error message (e.g. Invalid Input.) must be displayed and the menu should be displayed again.
REQ4:Initialise Game
When the user loads a game board, then he/she should specify the initial position and direction of the car in the game board. This can be done through the init
-
: an integer between 0-9 that specifies the horizontal location of the car
: an integer between 0-9 that specifies the vertical location of the car
: any one of the values
north, east, south
or
west
. These specify the direction of the car’s moving forward. For example, if
north
is specified and then
forward
command is issued, the car’s current position will change to one cell towards the north (up).
Below is an example of initialising the game after loading game board 1:
You can see that the user specified arguments 5,3,north x
=
5
and y
=
3
. The car should be shown in the grid with an arrow sign ( , ,
|
At this stage of the program, only four commands are acceptable:
-
forward
turn_left (or l)
turn_right (or r)
quit
If user enters any other command, or an incorrect command, an error message (e.g. “Invalid Input.”) must be displayed and the menu should be displayed again.
REQ5: Play Game
When the game is initialised, as explained in the previous section on REQ4, the user can move the car in the grid by using the
forward
command. This command will move the car one cell towards up, right, down or left. The direction of the move is decided according to the current direction of the car. For example, if the current direction of the car is
north
, moving forward will increase the vertical location of the car by one
cell. If the current direction is left
Below is an example of how forward x
=
5, y = 3
and direction
=
north forward x
=
5
and y
=
2
, and the direction is not affected (remains north
The turn_right
-
North
?
East
East
?
South
South
?
West
West
?
North
The turn_left (or l)
-
North
?
West
West
?
South
South
?
East
East
?
North
Assuming that the car is currently located in [ x
= 4, y = 5
] and pointing towards north ( ), below is an example of how it will be affected by a turn_right (or r) forward
Note that in the example above the user first issued a turn_right (or r) north
?
) to east
?
).
Given the new direction, when the user used the
forward
command, the program attempted to move the car towards the east. However, there is a roadblock on the right side of the current position (* on
x
= 5, y = 5
)
and the car cannot be moved forward. The error message indicates this problem. This is the way you are expected to handle hitting the roadblocks.