COMP07027 Introduction to Programming

Programming Project

This project is worth 80% of the overall module assessment.

The development work for this coursework may be completed in pairs (recommended, but you may NOT work in groups larger than two) or individually.

If you work as a pair this means working on all parts of the program together (the report is an individual report, but the development and testing of the code should be done jointly) – it is not intended that you delegate different parts of the implementation work to partners individually, though it is acceptable for you to identify who will do the lead work for each function/part (as in, who types the code in to the computer once the algorithm/logic has been agreed and who sits and watches over their shoulder!), and you may wish to decide that where one person takes the lead on implementing some function that the other person takes the lead responsibility for testing it.

Project Specification

You are required to write a simple program that simulates a game of darts. In this, two (or more) players take turns to “throw” three darts to reduce their score from 501 down to zero. Each dart thrown will be simulated by a pair of numbers – the first is the number scored (1-20, 25, 50; or 0 if the throw is a complete miss), the second indicates a single double or treble if one is possible (note that 25 or 50 are always singles, and obviously 0 is just 0, so the first number will dictate whether the second value is necessary). After three throws, the full score will be deducted from 501. The first player to zero wins. However, as with real darts, the final dart must land on a double or bullseye (50), and must exactly clear the remaining score. If too much is scored, the player is out for that turn (and they score zero for it), and must try again after the other players have had a turn.

On-screen, each turn should generate:

  1. Each of the three throws’ scores, with doubles and trebles included
  2. The total score achieved in a turn, by summing all three
  3. The remaining score, having deducted from the total at each turn
  4. An indication of ‘bust’ if the player’s darts total more than the remaining score, or ‘win’ if the player has got out with a double or bullseye (note that if the player gets out on the first or second dart, this is a win – the remaining dart(s) do not need to be thrown).

A quick guide to the minimum requirements of a Darts program:

Point No.

Description (the facilities you need to implement)

Worth (marks)

1

Create a data structure suitable for recording the score of throwing a single dart. E.g. a Throw should be capable of storing this data:

Number scored = 15 Modifier = DOUBLE Total score = 30.

Extend this to record the score of a complete Turn (with up to three darts).

10 (pair)

2

Write a function to simulate the throwing of a single dart. It should take the target (what is being aimed at) as a parameter and return what has actually been hit. This function should not read anything from the keyboard or display anything on the screen. You will come back to simulating a single throw as

3 (pair)

development proceeds, for now provide a function that returns its parameter (that is, the throw always hits what it is aimed at).

When you come back later to revise this function, comment out the original code and add the revised code (that is, do not overwrite the original version), so that when you submit the program the marker can see that you have completed this step.

3

Write a function to display the result of a single Throw.

2 (pair)

4

Write a function that gives a user a throw by asking them to enter a target for the dart to be thrown. For example, the user could enter “20 D“ to aim for a double 20. The function should call the function defined in 2 above to perform the throw and then the function defined in 3 above to display the result, and it should return what was hit (e.g. {`20, DOUBLE`}).

5 (pair)

5

Write a function to simulate a complete turn. This function should call the function defined in 4 above up to three times and accumulate the score. The function will need to be passed a parameter that indicates the remaining score required so that it can stop the turn if a win is achieved on the first or second dart, and it should return the total value of all of the throws taken.

8 (pair)

6

Write a function to display the result of a turn (including a player winning or going bust).

2 (pair)

7

Modify the game code so that the complete history of throws for each player is stored over the duration of the game. You could use an array of turns for this. This would then be used to display a ‘replay’ of the game once a player has won.

10 (pair)

8

Create a strategy to simulate the real throwing of a dart (i.e. where it is possible to miss). A reasonable strategy would be to base this on the layout of a dart-board – e.g. missing a 20 would more likely be a score of 5 or 1 (since 5 are 1 are the two numbers on either side of 20) than other values, a complete miss (scoring zero) is more likely when aiming for a double as it is on the edge of the board, etc.

10

(individual mark)

9

Provide a facility to save a complete game to file, to be viewed later, and a facility to read and display the stored game.

10

(individual mark)

10

Create a command system to allow users to control a game. This should be menu based to provide commands to 1) Start a new game, 2) Replay the last game, 3) Save the game just played, 4) Replay the last saved game, 5) Quit.

10 (pair)

11

Additional marks are available for good coding standards and documentation. Marks will be awarded for a) neatness of code, b) use of sensible names for variables, classes., constants etc., c) Good use of constants, methods

(subroutines), data structures etc. in your code, d) Documenting the code, such as use of javadoc comments to document classes, methods and variables.

10 (pair)

12

Write a report of the work including a critical appraisal of the work done (see below)

10

(individual mark)

Total

80

Library Support

You will probably want to use TextIO for input/output and file handling and you should look at examples of applications in the textbook that use a menu for help in designing and implementing this. You are not expected to provide a graphical representation of the game, text input/output via the console is all that is required.

Note that you must include an acknowledgement in your report for any sources you have used (on the web, textbooks etc) in developing or commenting on design, code and in your testing, and any source code used from sources other than the course textbook should be indicated in the code by a comment at the beginning and end of the code stating the source from which it was taken. If you receive any advice from anyone you should acknowledge this also and indicate what part of the work it related to. You should not share any of the code that you produce with anyone other than your partner.