COSC1076 - Advanced Programming Techniques in Game of Card Board

Download Solution Order New Solution

Assignment Task

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

This assignment is on 4 milestones and marked according to three criteria, as given on the Marking Rubric on Canvas:

  • Milestone 1: Demonstration in
  • Milestone 2-4: Implementation of the Car
  • Style & Code Description: Producing well formatted, and well documented

To complete this assignment, you will require skills and knowledge from workshop and lab material for Weeks 2 to

Relevant Workshop/Lab Material

You may find that you will be unable to complete some of the activities until you have completed the relevant lab work. However, you will be able to commence work on some sections. Thus, do the work you can initially, and continue to build in new features as you learn the relevant skills. You will need to learn how to use C++ Standard Library class template vector much sooner so that you can build your game board. You are encouraged to learn new C++ features through C++ reference documentation such as 

Description of the Program

The development of Car Board program can be broken down into following smaller requirements (REQs).

1: Main Menu

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.

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.

2: 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.

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

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.

4: 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 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).

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

5: 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.

A further example of moving the car is shown below.

The car shown in the previous example has turned right again, which changed its direction from east () to south (↓). It then moved forward twice.

NOTE: The command turn_left should be interchangeable with the command l , and the command turn_right should be interchangeable with the command r . That is, the command l should behave exactly similar to turn_left , and the command r should behave exactly similar to turn_right .

6: Stopping at the Edges of the Board and Before the Road Blocks

The car must not move beyond the edges of the board. For example, a car in a position with x = 9 should not be able to move towards the east any more. Similarly, a car in a position with y = 0 should not be able to move towards the north any more.

If the user attempts to move the car beyond the edges of the board, you should display the error message “The car is at the edge of the board and cannot move further in that direction".

7: Quit Main Menu

This option should terminate your program without any crash for any reasons (i.e. exit from function main() of your C++ code).

8: Return to Main Menu

When the quit command is entered in the middle of the game, the game should terminate and the control should be returned to the main menu.

Additionally, the total number of successful forward moves in the game should be displayed before exiting the game. For example, if the player attempts to move the car forward four times and only three of these attempts were successful (e.g. one move hit a road block), the following message should be displayed when exiting the current game: "Total player moves: 3".

9: Input Validation

For functionality that we ask you to implement that relies upon the user entering input, you will need to check the length, range and type of all inputs where applicable.

For example, you will be expected to check the length of strings (e.g. acceptable number of characters?), the ranges of numeric inputs (e.g. acceptable value in an integer?) and the type of data (e.g. is this input numeric?). For any detected invalid inputs, you are asked to re-prompt for this input. You should not truncate extra data or abort the function.

This COSC1076 - IT Computer Science has been solved by our PhD Experts at My Uni Paper.

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.