diff_months: 19

Design, code (in C89 version of C) and test a program.

Download Solution Now
Added on: 2022-10-15 10:58:59
Order Code: 462677
Question Task Id: 0

In summary, your program will:

  • Able to create dynamically-allocated 2D char array to make a simple ASCII-based
  • Receive user input to control the flow of the game.
  • Utilize pre-written random number generator and terminal behaviour configuration for the game.
  • Write a suitable Without the makefile, we will assume it cannot be compiled and it will negatively affect your mark.

1 Code Design

You must comment your code sufficiently in a way that we understand the overall design of your program. Remember that you cannot use “//” to comment since it is C99-specific syntax. You can only use “/*………*/” syntax.

Your code should be structured in a way that each file has a clear scope and goal. For example, “main.c” should only contain a main function, “game.c” should contain functions that handle and control the game features, and so on. Basically, functions should be located on reasonably appropriate files and you will link them when you write the makefile. DO NOT put everything together into one single source code file. Make sure you use the header files and header guard correctly. Never include .c files directly.

Make sure you free all the memories allocated by the malloc() function. Use valgrind to detect any memory leak and fix them. Memory leaks might not break your program, but penalty will still be applied if there is any. If you do not use malloc, you will lose marks.

Please be aware of our coding standard (can be found on Blackboard and the marking criterias) Violation of the coding standard will result in penalty on the assignment. Keep in mind that it is possible to lose significant marks with a fully-working program that is written messily, has no clear structure, full of memory leaks, and violates many of the coding standards. The purpose of this unit is to teach you a good habit of programming.

2 Academic Integrity

This is an assessable task, and as such there are strict rules. You must not ask for or accept help from anyone else on completing the tasks. You must not show your work at any time to another student enrolled in this unit who might gain unfair advantage from it. These things are considered plagiarism or collusion. To be on the safe side, never ever release your code to the public.

Do NOT just copy some C source codes from internet resources. If you get caught, it will be considered plagiarism. If you put the reference, then that part of the code will not be marked since it is not your work.

Staff can provide assistance in helping you understand the unit material in general, but nobody is allowed to help you solve the specific problems posed in this specification. The purpose of the assignment is for you to solve them on your own, so that you learn from it. Please see Curtin’s Academic Integrity website for information on academic misconduct (which includes plagiarism and collusion).

The unit coordinator may require you to attend quick interview to answer questions about any piece of written work submitted in this unit. Your response(s) may be referred to as evidence in an Academic Misconduct inquiry. In addition, your assignment submission may be analysed by systems to detect plagiarism and/or collusion.

3 Task Details

3.1 Quick Preview

First of all, please watch the supplementary videos on the Assignment link on Blackboard. These videos demonstrates what we expect your program should do. You will implement a simple game that you can play on Linux terminal. Further details on the specification will be explained on the oncoming sections.

3.2 Command Line Arguments

Please ensure that the executable is called “escape”. Your executable should accept 6 command- line parameters/arguments:

./escape

and define the size of the playable map area for the player (the size does not include the border of the map). and are the location coordinates of the player, while and are the location coordinates of the goal. The coordinates start from 0 (e.g row 0 is the first row)). You can assume the user will provide proper datatype (integer). The minimum number for and are 5. Your program should reject negative numbers.

If the amount of the arguments are too many or too few, your program should print a mes- sage on the terminal and end the program accordingly (do NOT use exit() function). If the argument is NOT in the correct range, please end the program in the same manner as well.


Since the player can enter arbitrary number for the map size, it means you need to use malloc() function to properly allocate sufficient memory for the 2D array for the map. Keep in mind that in C89, you cannot allocate the size of stack-based array with a variable, that is why you need malloc() function.

3.3 Main Interface

Once you run the program, it should clear the terminal screen (watch the video about the method to clear the screen) and print the 2D map along with the player and the goal:

Figure 1: Main visual interface of the game with the player and the goal.

This is the main interface of the game. The user can type the command to move the player. Every time the user inputs the command, the program should update the map accordingly and refresh the screen (clear the screen and reprint the map). Please refer to Section ?? for more detail on the user input.

3.4 Character on the Map

You have to use the correct characters on the game interface:

  • Use char ’*’ for the map
  • Use char ’P’ for the Player location.
  • Use char ’G’ for the Goal
  • Use char ’X’ to indicate collapsed floor

3.5 Randomized Collapsing Floor Grid

Please watch the supplementary video to learn how to use the pre-written random number generator. You will need this function to be randomly causing one of the floor grid to collapse on every player movement. The player cannot access the collapsed area. You need to make sure that the collapsed floor grid only happens on the empty grid. This means that it should not collapse on the player location OR the goal location OR when the floor already collapsed.

Figure 2: Each floor grid will collapse on every player movement.

3.6 User Input

The user only needs to type 1 character for each command (lower case). Here is the list of the possible commands:

  • ‘w’ moves the player one block
  • ‘s’ moves the player one block
  • ‘a’ moves the player one block left.
  • ‘d’ moves the player one block right.
  • Any other character should be ignored, and nothing changes on the map. Feel free to print a warning message such as ”invalid key”.

Your program should be able to receive each input without pressing ”enter” key everytime. Please refer to the supplementary video for a sample code to disable the Echo and Canonical feature on Linux terminal temporarily. If your terminal is stuck on this mode, you only need to re-open a new terminal.


The movement should only happen if there is a space for the player to move. If the player hits the map border OR the collapsed floor ’X’, nothing should change on the map. The only excep- tion on the map border is when you implement the conditional compilation BORDERLESS on section ??.

3.7 Win/Lose the Game

The game will continue playing until the player satisfies one of two conditions:

  • If the player reaches the goal, the player wins the game.
  • If the player or the goal is trapped by the collapsed floor grids, the player loses the The definition of ”trapped” is when all four vertical and horizontal neighboring floor grids have collapsed. It means either the player cannot move anymore, OR the goal is completely inaccessible.

Please do NOT use exit() or break to end the program. You must free the malloc’ed memories and ensure the program reaches the end of the main function properly.

3.8 BORDERLESS (with Conditional Compilation)


In this section, you are required to create a conditional compilation that allows the player to traverse to the other end of the map through map border when compiled with BORDERLESS defined. Please watch the practical supplementary videos about makefile to learn about it. Basically, when the player compiles the program with the command ”make BORDERLESS=1”, the player is allowed to go through border to wrap over to the other end of the map.

3.9 Makefile

You should manually write the makefile according to the format explained in the lecture and practical. It should include the Make variables, appropriate flags, appropriate targets, correct prerequisites, conditional compilation, and clean rule. We will compile your program through the makefile. If the makefile is missing, we will assume the program cannot be compiled, and you will lose marks. DO NOT use the makefile that is auto-generated by the VScode. Write it yourself.

3.10 Assumptions

For simplification purpose, these are assumptions you can use for this assignments:

  • The datatype of all the command line arguments provided by the users are all valid. However, you still need to check if the numbers are valid (e.g not too small or negative numbers). (Keep in mind that it will be stored as a string in )
  • The size of the map will be reasonable to be displayed on For example, we will not test the map with gigantic size such as 300 x 500.
  • You only need to handle lowercase inputs (’w’, ’s’, ’a’, ’d’). The other keys should be ignored (feel free to add warning message).

4 Marking Criteria

This is the marking distribution for your guidance:

  • Properly structured makefile according to the lecture and practical content (5 marks)
  • Program can be compiled with the makefile and executed successfully without immedi- ate crashing and showing reasonable output (5 marks)
  • Usage of header guards and sufficient in-code commenting (2 marks)
  • The whole program is readable and has reasonable framework. Multiple files are uti- lized with reasonable category. If you only have one c file for the whole assignment (not counting c and random.c), you will get zero mark on this category. (3 marks)
  • Avoiding bad coding standard. (5 marks) Please refer to the coding standard on Black- Some of the most common mistakes are:
    • Using global variables
    • Calling exit() function to end the program abruptly
    • Using “break’‘ NOT on the switch case statement
    • Using “continue’‘
    • Using goto
    • Having multiple returns on a single function
    • include the .c files directly instead of the .h files
  • No memory leaks (10 marks) Please use valgrind command to check for any memory If your program is very sparse OR does not use any malloc(), you will get zero mark on this category.

• FUNCTIONALITIES:

  • Correct command line arguments verification with proper response. This includes checking the acceptable range of the (5 marks)
  • Proper memory allocation for the 2D map array. (5 marks)
  • Able to clear the screen and re-print the map on every (5 marks)
  • Randomly collapse the floor on every player (15 marks)
  • Able to move the player with the keyboard input from the (5 marks)
  • Successfully disable the Echo and Canonical temporarily so that the user does not need to press the ”enter” key to issue (5 marks)
  • Implement the BORDERLESS feature with the conditional compilation (15 marks)
  • Winning the game when the player reaches the goal OR losing the game when the player or the goal are (15 marks)

5 Short Report

If your program is incomplete/imperfect, please write a comprehensive report explaining what you have done on for each functionality. Inform us which function on which file that is related to that functionality. This report is not marked, but it will help us a lot to mark your assign- ment. Poorly-written report will not help us to understand your code. Please ensure your report reflects your work correctly (no exaggeration). Dishonest report will lead to academic misconduct.

6 Final Check and Submission

After you complete your assignment, please make sure it can be compiled and run on our Linux lab environment. If you do your assignment on other environments (e.g on Windows operating system), then it is your responsibility to ensure that it works on the lab environment. In the case of incompatibility, it will be considered “not working’‘ and some penalties will apply. You have to submit a single zip file containing ALL the files in this list:

  • Declaration of Originality Form – Please fill this form digitally and submit You will get zero mark if you forget to submit this form.
  • Your essential assignment files – Submit all the .c & .h files and your Please do not submit the executable and object (.o) files, as we will re-compile them anyway.
  • Brief Report (if applicable) - If you want to write the report about what you have done on the assignment, please save it as a PDF or TXT file.

The name of the zipped file should be in the format of:

___Assignment1.zip Example: Antoni_12345678_Michael-Bay_Assignment1.zip

If you forget your tutor’s name, please put the lecturer’s name. Please make sure your sub- mission is complete and not corrupted. You can re-download the submission and check if you can compile and run the program again. Corrupted submission will receive instant zero. Late submission will receive zero mark. You can submit it multiple times, but only your latest sub- mission will be marked.

  • Uploaded By : Katthy Wills
  • Posted on : October 15th, 2022
  • Downloads : 0
  • Views : 200

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