Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
DPST1091 Programming Fundamentals
Assignment 1 - CS Pacman
Overview
Welcome to CS Pacman! CS Pacman is an adaptation of the 1980 maze game. In this assignment you will be implementing 1511's
simplified version of this game and trying to get your Pacman to collect all the dots! Please read most of the spec before starting the
assignment. (although you can save reading stages 2, 3 and 4 for later).
Assignment Structure
This assignment will test your ability to create, use and manipulate 2D arrays and structs to solve problems. To do this, the map used
in the game has been implemented as a 2D array of tiles. These tiles are each represented by a
struct tile
, which is outlined
below:
struct tile
Purpose:
To store information about the tiles of the map.
Contains:
enum entity entity
The type of entity that exists on this tile.
All entity types are found in the
enum entity
definition.
struct enemy enemy
Represents the enemy at this location (if one exists).
struct enemy
Purpose:
To store information about a particular enemy
Contains:
enum direction move_direction
The direction the enemy is moving.
All directions are found in the
enum direction
definition.
int is_present
Represents whether the enemy is present
You will need to add more fields to this struct in later stages.
The provided enums are quite extensive. Definitions of each are provided below:
enum entity
Purpose:
Represent possible entities that can exist on a tile
Possible values:
EMPTY_ENTITY
Represents no entity. Some tiles will have no entity present, this allows us to represent that.
WALL
A wall that blocks the movement of Pacman and enemies
DOT
A collectable that gives Pacman points (Stage 2)
APPLE
A collectable that gives points, helps collect
DOT
s and can destroy
WALL
s (Stage 2)
BANANA
A collectable that gives points and helps collect
DOT
s (Stage 2)
POWER_UP
A collectable that gives points and helps catch ghosts (Stage 3)
STAIRCASE_UP
Allows Pacman to travel up to a higher floor (Stage 4)
STAIRCASE_DOWN
Allows Pacman to travel down to a lower floor (Stage 4)
enum direction
Purpose:
Represent the direction of a ghost's movement
Possible values:
UP
DOWN
LEFT
RIGHT
Program phases
There are two main phases to the overall game:
. Create level phase. This is where you will be placing Pacman and adding features to the map. This is started in Stage 1 and
you will add to this throughout the rest of the assignment.
. Gameplay phase. This is where you will handle Pacman's movement throughout the level. This is started in Stage 2 and you
will add to this throughout the rest of the assignment.
How To Get Started
There are a few steps to getting started with CS Pacman.
Create a new folder for your assignment work and move into it.
$ mkdir ass1
$ cd ass1
Download cs_pacman.c here, or copy it to your CSE account using the following command:
$ 1091 autotest cs_pacman
NOTE:
When running the autotest on the starter code (with no modifications), it is expected to see failed tests.
About the Starter Code
The provided starter code has done some setup for you. This is explained below.
Before the main function, the starter code has:
. Imported the standard input/output library.
. Defined some initial
#define
's and enums.
. Defined the struct(s) described above.
In the main function, the starter code:
. Creates a 2D array of
struct tile
s called
map
.
. Initialises this
map
with some default values.
. Prompts you to write your own code!
HINT:
To start with, feel free to write your code in the main function! You can also add in your own functions as you go - we would
definitely recommend this :)
HINT:
You might also find it helpful to draw diagrams and write pseudocode between later stages, especially stage 3 and stage 4!
Reference Solution
To help you understand the proper behaviour of the game, we have provided a reference implementation. If you have any questions
about the behaviour of your assignment, you can check and compare it to the reference implementation.
To run the reference implementation, use the following command:
$ 1091 cs_pacman
Start coding!
Your Tasks
This assignment consists of four stages. Each stage builds on the work of the previous stage, and each stage has a higher
complexity than its predecessor. You should complete the stages in order.
Stage 1 ●◌◌ Stage 2 ●◌◌ Stage 3 ●●◌ Stage 4 ●●● Challenge ☠
Stage 1
Stage 1.1 - Placing Pacman
Your first task for this assignment is to place our Pacman on the map! Currently, the starter code creates a 2D array of
struct
tiles
, and initialises them with the
initialise_map()
function that weʼve provided.
Your program should scan in the coordinates (first row, then column) at which Pacman should be placed. The updated map should
then be printed out, using the provided print_map() function.
Assumptions / Restrictions / Clarifications
You can assume that you will always be provided with two integers for the row and column for Pacman.
The row/column provided will always fall within the map.
Examples
− Example 1.1.1: Place Pacman
Autotest
NOTE:
You may like to autotest this section with the following command:
1091 autotest-stage 01_01 cs_pacman
Stage 1.2 - Adding Features
Now that weʼve placed Pacman, we also need to place some features on the map! At this stage, the only feature that your program
should handle is placing walls — but you will need to extend this to other features in later stages, so have a think about how best to
do that!
To add features, your program should read characters in a loop, followed by a variable number of inputs based on which feature is
being added. The loop should terminate when the user enters the
'S'
character (meaning “Start the game”).
As mentioned, the only feature for this stage is the placement of walls. To place a wall, the user will first type the character
'W'
,
followed by the wall sʼ start and end coordinates (first row, then column).
...
Create the level:
W [start_row] [start_col] [end_row] [end_col]
...
For this stage, you can assume that the walls will either be horizontal or vertical, and that the
start
values will be less than or
equal to their
end
counterparts. In other words, every coordinate pair received will have either the row OR column equal, and go
from left to right, or top to bottom.
In this stage, every wall entered will be valid — meaning that all walls will fall entirely within the map.
Once all of the walls have been placed, the map should be printed.
HINT:
You might like to start by creating a loop that scans in one character repeatedly until an 'S' is entered.
Inside your loop