Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Programming Project
1. Assignment guidance
You are tasked with creating a basic treasure hunt game in C, where players navigate a map to find hidden treasures using command-line inputs.
You should design your code to be defensive and handle a range of errors in a graceful way,
without crashing unexpectedly. Consider the full range of mistakes which a user could make when trying to run the program.
Treasure Island Game
The game loads a map file, which is provided on the command line in the format:
./island <mapfilepath> <dimension> A map file can contain:
Symbol |
Meaning |
‘ ‘ (space) |
Land which the player can move across. |
‘w’ (lower case w) |
Water – this surrounds the island and the player cannot move through it. There must be only water in the first and last row and column. |
‘T’ (upper case t) |
Palm trees which block the player from moving on land. |
3 x ‘H’ (upper case h) |
Hidden treasures which the player is searching for. |
1 x ‘S’ (upper case s) |
The starting point, where your player will be placed when you start the game. |
And is always a square with the width and height dimension which is also provided on the command line.
The game involves the player moving around the island looking for hidden treasure. The player can move using the WASD keys (w/W = up, a/A = left, s/S = down, d/D = right) or display a map using the m/M key.
The locations of the hidden treasure and the starting point should not be shown by the map, these should be showed by blank spaces ‘ ‘ .
When the player finds the hidden treasure, they should receive some message telling them how many they have found such as ‘You have found 1 out of 3 hidden treasures’ .
When the player has found all 3 hidden treasures, they have won and the game ends successfully. There is no exit or quit option, so the only way to complete the game is to find all treasures.
Return codes and Outputs to the User
Any outputs such as error messages can be any text you like, as the grader does not read them. However, there are certain return codes which you have to use:
0 = success (the game was able to run correctly)
1 = argument error (bad number of arguments, or bad dimension)
2 = file error (the file cannot be read – doesn’t exist or no read permissions) 3 = data error (the file is not a valid map)
Where an error could fall into multiple categories, the autograder will accept either – or you can ask me via Teams.
Map Files
Map files are text files containing a ‘map’ for the game. They have some rules:
- The map should always have a border of water (‘w’s) around the edges (i.e. every first and last character of a row and column should be a ‘w’).
- A map is always a square (width and height equal), and should match the dimension given on the command line.
- There is exactly one start point marked by ‘S’ .
- There are exactly 3 treasures marked by ‘H’ .
- The map only contains characters ‘w’,’T’,’ ‘, ‘H’ and ‘S’ .
- The size is a minimum of 5x5 and a maximum of 100x100.
- They may end with a trailing newline character (a ‘\n’ as the final character).
A selection of map files have been provided to help you test your code – note that these will not be the final files used to test your code, so it’s important for you to ensure that your code works on a
variety of different files.
These example files also do not contain every possible error – try and think of other ways in which a map file could be wrong, and make some of your own to test your code.
You do not need to check whether there is a valid route between the start and the 3 treasures
- you can assume there always is.
Additional Task - Map Generator - 30 marks
This task is optional and should not be attempted if you are sitting a capped resit - this is
only for those with uncapped marks who are aiming for higher marks and may take significantly longer than the suggested time for this assignment.
The developer wants to procedurally generate a range of different maps to build up a website of maps which people can download and use with the game. They would like you to create a script which is able to generate these maps.
You may use C, Python, or Java for this extension.
You will produce a program which can generate maps with a given filename and size. For example: ./islandGenerator new_island.txt 40
Would create a random, solvable 40x40 map and save it into new_island.txt.