diff_months: 17

COSC1076 Advanced Programming Techniques :Car Board Assessment

Download Solution Now
Added on: 2023-03-16 09:17:38
Order Code: 487363
Question Task Id: 0

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 , and sections with your real name, student number and student email address.

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

command is responsible to initialise the game board. More details about this command is available in REQ3 below.

The

init

command is responsible to set the initialised values of the car’s position and movement. More detail about this command is available in REQ4 below.

The

forward

command is responsible to move the car one position forward according to the current direction of the car. The

turn_left (or l)

and

turn_right (or r)

commands are responsible to change the direction of the car’s movement. See the details in REQ5 below.

The

quit

command will exit the current game and return to the

main menu

. This requirement is defined in REQ8 below.

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

, moved

forward

and turned

left

or

right

. See the requirement for printing the board in REQ2 below. Note that you should print a statement that at each stage of the program you must also display the list of

currently acceptable commands

in the output. The acceptable commands are mentioned in each section below.

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

command, an error will be shown as discussed in REQ5 below.

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 ,,

command. The meaning of the arguments of this command are as follows.

    • : 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

and accordingly the car is positioned in the cell

x

=

5

and

y

=

3

. The car should be shown in the grid with an arrow sign (

,   ,

, or    according to the current direction of the car).

 

? ? ?       ?

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

, moving forward will decrease the current vertical position of the car by one cell.

Below is an example of how

forward

command would work on the board shown in REQ4. Remember that in REQ4 the board was initialised with

x

=

5, y = 3

and

direction

=

north

. Here a

forward

command is taking the car one cell towards the north (up). The new position of the car is

x

=

5

and

y

=

2

, and the direction is not affected (remains

north

).

The

turn_right

command will change the direction of the car in the following sequence.

    • North

      ?

      East

    • East

      ?

      South

    • South

      ?

      West

    • West

      ?

      North

The

turn_left (or l)

command will affect the direction of the car in the opposite sequence:

    • 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)

command followed by a

forward

command.

Note that in the example above the user first issued a

turn_right (or r)

command, which changed the direction of the car from

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.

  • Uploaded By : Katthy Wills
  • Posted on : March 16th, 2023
  • Downloads : 0
  • Views : 276

Download Solution Now

Can't find what you're looking for?

Whatsapp Tap to ChatGet instant assistance

Choose a Plan

Premium

80 USD
  • All in Gold, plus:
  • 30-minute live one-to-one session with an expert
    • Understanding Marking Rubric
    • Understanding task requirements
    • Structuring & Formatting
    • Referencing & Citing
Most
Popular

Gold

30 50 USD
  • Get the Full Used Solution
    (Solution is already submitted and 100% plagiarised.
    Can only be used for reference purposes)
Save 33%

Silver

20 USD
  • Journals
  • Peer-Reviewed Articles
  • Books
  • Various other Data Sources – ProQuest, Informit, Scopus, Academic Search Complete, EBSCO, Exerpta Medica Database, and more