Assignment 1 - CS Defence

Tower Defence is a specific genre of games that boomed in the late 2000s. Many innovative games were created under this genre that pushed new and exciting ideas!

The core mechanics of these types of games are actually very simple! Waves of enemies continuously spawn (often forever!) and the player has the task of placing towers that will automatically fight these enemies. Both the player and enemies increase in strength over time and the defences need to be upgraded and improved to avoid enemies reaching a particular destination that could end the game!

CS Defence is heavily inspired by this genre, and specifically, one of the more famous games under its belt - Bloons Tower Defense. In this game, as well as CS Defence, enemies spawn from some start position and try to move to some end position via a path on the map. The player's goal is to place down towers that attack these enemies as they move. As towers destroy enemies, the player earns money that they can use to either upgrade or place down new towers.

Overview

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 land land_type
      • The type of land this tile has.
      • All land types are found in the enum land definition.
    • enum entity entity
      • The type of entity that exists on top of the land for this tile.
      • All entity types are found in the enum entity definition.
    • int n_enemies
      • Represents the number of enemies at this tile in the map.

The provided enums are quite extensive. Definitions of each are provided below:

enum land

  • Purpose:
    • Represent the type of land.
  • Possible values:
    • GRASS
      • Represents a piece of grass. It is notable that towers can be placed on this land.
    • WATER
      • Represents a block of water. It is notable that towers cannot be placed on this land, with an exception mentioned in later stages.
    • PATH_START
      • Represents the start of the path on the map. It is notable that this is where enemies will spawn.
    • PATH_END
      • Represents the end of the path on the map. It is notable that enemies move to this location, and when reached, the player loses lives.
    • PATH_UP, PATH_RIGHT, PATH_DOWN, PATH_LEFT
      • Represents the “flow” of a path on this piece of land. Each of these types indicates the direction that the path is heading.
    • TELEPORTER
      • Represents a teleporter on the path that links to another teleporter. Similar use case as the path tiles mentioned, but allows for more complex path flow.

enum entity

  • Purpose:
    • Represent the kind of entity.
  • Possible values:
    • EMPTY
      • Represents no entity. Some tiles will only have land and no entity, this allows us to represent that.
    • ENEMY
      • Represents single or multiple enemies. Used when enemies are spawned and will move along the path.
    • BASIC_TOWER, POWER_TOWER, FORTIFIED_TOWER
      • Represents all the different types of towers that exist. Each tower has different abilities, specified in Stage 3.

Mental Model

A tile can always be thought of as a piece of land with an entity on top of it. Click through the different combination of land + entities below to build up this mental model of what a tile is!

In this assignment, you will have a 2D array of these tiles. This could represent a map like the one below:

example-map.png

Implementation Model

Although the mental model mentioned above is a great way to understand how the map works in this assignment, it is also important to understand how it works in the code itself.

In this assignment, you will be need to manipulate a map provided which is defined as

struct tile map[MAP_ROWS][MAP_COLUMNS];,

where MAP_ROWS is 6 and MAP_COLUMNS is 12.

This means that we have a 2D array of struct tiles, which themselves have both entity + land enums associated with them. Change attributes in the interactive below to get an understanding of how you should access each part of this map.

Note that the indices indicate which struct in the array you are accessing, and the word after the . indicates which member of that struct that you are accessing.

map[][].

How To Get Started

There are a few steps to getting started with CS Defence.

  1. Create a new folder for your assignment work and move into it.

    mkdir ass1
    cd ass1

  2. Download the starter code (cs_defence.c) here or use this command on your CSE account to copy the file into your current directory:

    cp -n /web/cs1511/23T1/activities/cs_defence/cs_defence.c .

  3. Run 1511 autotest cs_defence to make sure you have correctly downloaded the file.

    1511 autotest cs_defence
  1. Read through Stage 1.

  2. Spend a few minutes playing with the reference solution -- get a feel for how the assignment works.

    1511 cs_defence

  3. Think about your solution, draw some diagrams, write some pseudocode to help you get started.

  1. Start coding!

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:

  1. Imported the standard input/output library.
  2. Defined some initial #define's and enums.
  3. Defined the struct described above.

In the main function, the starter code:

  1. Creates a 2D array of struct tiles called map.
  2. Initialises this map with some default values.
  3. Prompts you to write your own code!

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 1.1 - Setup

To start off the assignment, you will need to initialise some basic information for the game. The starter code currently creates a 2D array of struct tiles and initialises them using the initialise_map() function that we’ve provided.

Your job is to take input from the user, asking them for their initial lives and money. An example of this is shown below:

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500

Once you have the above working, you will need to scan in the “starting” point on the map and the “ending” point on the map. We describe a point as 2 integers, indicating a row then column. The starting and ending points will indicate where enemies will spawn from, and where they need to get to respectively. Implementing this, your program should behave in the same manner as below:

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 2
End Point: 4 10

In the example above, the start point is at row 1, column 2 and the ending point is at row 4, column 10.

These points can be visualised on the map like so:

1.1.1.jpg

You will need to modify the given 2D array, map, to account for these points.

Make sure to read through the overview of the given structs/enums to understand how they work before continuing.

Once you understand how each struct/enum works, it is important to know that the map variable in the code is a 2D array of struct tiles. Alternatively, it can also be thought of as a 2D array of land with optional entities on top of it, since this is what each tile represents.

Currently, all the land is simply grass. However, given the starting/ending point that was just scanned in, you should update the relevant tiles such that their land is now PATH_START and PATH_END respectively.

After this, you should print out the map using the provided print_map() function. When printing out the map, the start point will be printed as S and the ending point will be printed as E, assuming you’ve updated the land correctly!

Assumptions/Restrictions/Clarifications

  • Starting lives and money will always be given as numbers greater than 0.
  • Start/End points will always be valid indexes in the map array. They will never be out of bounds.
  • Start/End points will never be the same point.

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 2
End Point: 4 10

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  S  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  E  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 16
Starting Money($): 2
Start Point: 3 7
End Point: 0 0

Lives: 16 Money: $2
                                    
 E  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  S  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

Stage 1.2 - Initial Enemies

Tower defence games aren’t quite so fun when enemies don’t exist! For Stage 1.2, you will add some initial enemies to the starting point on the map. After printing out the map in the previous section, you should scan in how many enemies to put at the starting point:

Initial Enemies: [num]

To add enemies to the starting tile, you need to do two things:

  • Set the entity component at that tile to ENEMY.
  • Set the n_enemies component of that tile to the number scanned in.

In the case where num is 0 or negative, the starting tile should not change.

After scanning in the enemies, you will need to print out the map again. If done correctly, the map will now show a number above the 'S' on the starting tile!

Assumptions/Restrictions/Clarifications

  • You can assume that the initial enemies will never be greater than 999.

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 1
End Point: 3 4

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 14

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
   014                              
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 1
End Point: 3 4

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: -5

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

Stage 1.3 - Lake

A common way to increase the difficulty of Tower Defence games is to add environmental obstacles, rather than just bombarding the player with more enemies. For Stage 1.3, you will add the ability to create a lake on the map! Lakes restrict the types of towers that can be placed on them.

After printing out the map in the previous section, you should scan in information about this lake:

Enter Lake: [row] [column] [height] [width]

The row and column that are scanned in indicate where the lake starts. The height and width indicate how far the lake stretches out in both dimensions. The lake always stretches down and to the right with these dimensions.

For every tile that appears in the lake on the map, their land component should be set to WATER.

After filling in the lake, the map should be printed again.

As an example, assume we give the program the following input:

Enter Lake: 1 2 4 6

The map would then look like this (ignoring start/ending tiles and initial enemies):

1.3.1.png

Error Handling

If the row and column provided is outside the map, or the height or width would stretch the lake outside the map, the message below should be printed and no lake should be added.

"Error: Lake out of bounds, ignoring...".

Assumptions/Restrictions/Clarifications

  • The given lake will never overlap with the start/end points.
  • The height and width entered will always be positive integers.
  • When handling the lake out-of-bounds error mentioned, the program should still continue normally. This error should only cause the lake to be ignored, and no water to be added to the map.
  • The map should still be printed even if the lake out-of-bounds error occurs.

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 2
End Point: 2 8

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  S  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  E  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 5

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
      005                           
 .  .  S  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  E  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 2 2 3 6

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
      005                           
 .  .  S  .  .  .  .  .  .  .  .  . 
                                    
 .  .  ~  ~  ~  ~  ~  ~  E  .  .  . 
                                    
 .  .  ~  ~  ~  ~  ~  ~  .  .  .  . 
                                    
 .  .  ~  ~  ~  ~  ~  ~  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 4 4

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  S  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 8

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
         008                        
 .  .  .  S  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: -1 1 1 1
Error: Lake out of bounds, ignoring...

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
         008                        
 .  .  .  S  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 1
End Point: 2 2

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  E  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  E  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 4 8 3 1
Error: Lake out of bounds, ignoring...

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  E  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

Testing and Submission

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1511 style, and clean up any issues a human may have reading your code. Don't forget -- 10% of your mark in the assignment is based on style!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_defence.c
1511 autotest-stage 01 cs_defence
give cs1511 ass1_cs_defence cs_defence.c

Stage 2

Stage 2.1 - Path

At the moment, it is possible to spawn enemies at the start point, however, we need a way for them to get to the ending point. For Stage 2.1, you will add the ability to create a path from the start point to the ending point. This will be done by taking in a sequence of directions from the start point.

Consider the following map below:

1.2.1.jpg

Your program will add functionality to take in a command like the following:

Enter Path: r r d d d

This indicates a path from the start point taking the route of right->right->down->down->down. After taking this input, the map will look like this:

1.2.2.jpg

There is no single path to the ending point. Alternatively, the following command could have been given instead:

Enter Path: r u r r d r r d d l d d l l u

As a result, the map would then look like this:

1.2.3.jpg

The only restriction on a path is that it must eventually reach the ending point.

For each tile on the path, the land component must specify what direction the path should be going. There are 4 different directions specified in enum land_type:

  • PATH_UP
  • PATH_RIGHT
  • PATH_DOWN
  • PATH_LEFT

After creating this path, make sure to call the print_map() function again!

Play around with the interactive below to get comfortable with how drawing a path will work.

Assumptions/Restrictions/Clarifications

  • You will only be given 'u', 'd', 'l', 'r' characters as input.
  • The given path will always reach the ending point.
  • The given path will never go out of bounds of the map.
  • The given path can go through water. This will just change the land of the tile.
  • The given path will never go back onto itself.

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 1
End Point: 1 5

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  E  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  E  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 4 4 1 1

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  E  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Path: r r r r

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  >  >  >  >  E  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 4
End Point: 4 6

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  S  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  S  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 3 2 2 2

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  S  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  ~  ~  .  .  .  .  .  .  .  . 
                                    
 .  .  ~  ~  .  .  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Path: r r d d d

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  >  >  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  ~  ~  .  .  v  .  .  .  .  . 
                                    
 .  .  ~  ~  .  .  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 4
End Point: 4 6

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  S  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  S  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 3 2 2 2

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  S  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  ~  ~  .  .  .  .  .  .  .  . 
                                    
 .  .  ~  ~  .  .  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Path: r u r r d r r d d l d d l l u

Lives: 100 Money: $500
                                    
 .  .  .  .  .  >  >  v  .  .  .  . 
                                    
 .  .  .  .  >  ^  .  >  >  v  .  . 
                                    
 .  .  .  .  .  .  .  .  .  v  .  . 
                                    
 .  .  ~  ~  .  .  .  .  v  <  .  . 
                                    
 .  .  ~  ~  .  .  E  .  v  .  .  . 
                                    
 .  .  .  .  .  .  ^  <  <  .  .  .

Stage 2.2 - Command Loop + Spawning Enemies

From this stage onwards, each new feature you implement will be done in a command loop. The command loop will consist of 4 steps:

  1. Prompt the user to enter a command
  2. Scan in the command
  3. Execute code relevant for that command
  4. Go back to step 1

This repeats continuously until the user presses CTRL+D, indicating that no more scanning will occur. After this occurs, "Game Over" should be printed, and the program should exit. As an extra note, a new line should be printed before AND after this "Game Over".

The first command you will implement is adding the ability to spawn enemies. In Stage 1.2, you added functionality to spawn enemies once, Stage 2.2 will allow for enemies to spawn whenever prompted.

Command

e [num]

Description

As mentioned in Stage 1.2, enemies are an extremely important aspect of Tower Defence games. It is also important that they can be spawned multiple times at different intervals. Stage 2.2 will allow this through the command e [num], combined with the use of a command loop.

When this command is used, num amount of enemies should be added to the starting point, in the exact same manner as Stage 1.2.

Using this command when there are already enemies at the start point should simply add to that number.

Assumptions/Restrictions/Clarifications

  • You can assume that adding enemies will never result in more than 999 enemies at the starting tile.
  • The num given with this command will always be a positive integer

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 4 3
End Point: 2 7

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  S  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  S  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 1 1 2 3

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  ~  ~  ~  .  .  .  .  .  .  .  . 
                                    
 .  ~  ~  ~  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  S  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Path: r r r r u u

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  ~  ~  ~  .  .  .  .  .  .  .  . 
                                    
 .  ~  ~  ~  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  ^  .  .  .  . 
                                    
 .  .  .  >  >  >  >  ^  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: e 5

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  ~  ~  ~  .  .  .  .  .  .  .  . 
                                    
 .  ~  ~  ~  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  ^  .  .  .  . 
         005                        
 .  .  .  >  >  >  >  ^  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 2 6
End Point: 4 4

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  S  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 5

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                  005               
 .  .  .  .  .  .  S  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 1 1 2 3

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  ~  ~  ~  .  .  .  .  .  .  .  . 
                  005               
 .  ~  ~  ~  .  .  S  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Path: d d l l

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  ~  ~  ~  .  .  .  .  .  .  .  . 
                  005               
 .  ~  ~  ~  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  E  <  <  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: e 7

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  ~  ~  ~  .  .  .  .  .  .  .  . 
                  012               
 .  ~  ~  ~  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  E  <  <  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 2
End Point: 4 4

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  S  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  S  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 2 5 2 2

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  S  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  ~  ~  .  .  .  .  . 
                                    
 .  .  .  .  .  ~  ~  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Path: r r d d d

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  >  >  v  .  .  .  .  .  .  . 
                                    
 .  .  .  .  v  ~  ~  .  .  .  .  . 
                                    
 .  .  .  .  v  ~  ~  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: e 5

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
      005                           
 .  .  >  >  v  .  .  .  .  .  .  . 
                                    
 .  .  .  .  v  ~  ~  .  .  .  .  . 
                                    
 .  .  .  .  v  ~  ~  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: e 3

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
      008                           
 .  .  >  >  v  .  .  .  .  .  .  . 
                                    
 .  .  .  .  v  ~  ~  .  .  .  .  . 
                                    
 .  .  .  .  v  ~  ~  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: e 10

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
      018                           
 .  .  >  >  v  .  .  .  .  .  .  . 
                                    
 .  .  .  .  v  ~  ~  .  .  .  .  . 
                                    
 .  .  .  .  v  ~  ~  .  .  .  .  . 
                                    
 .  .  .  .  E  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

Stage 2.3 - Basic Tower

Command

t [row] [column]

Description

Now that you can successfully spawn enemies, we need a way of fighting them! The t command spawns a tower at the provided [row] [column] . This is done by updating the entity component of that tile to BASIC_TOWER.

Error Handling

There are a few restrictions for placing a tower:

  • The player must have at least $200. Upon placing the tower, this money is subtracted from their bank (Remember that we initialised the starting money in Stage 1.1!)
  • Towers cannot be placed outside the map
  • Towers can only be placed on grass tiles
  • Towers can only be placed on tiles where the entity component is EMPTY (This prevents multiple towers from being on the same tile!)

In the case where any of these conditions are not satisfied, the following message should be printed and the map should remain unchanged:

"Error: Tower creation unsuccessful. Make sure you have at least $200 and that the tower is placed on a grass block with no entity.".

Otherwise, "Tower successfully created!" should be printed instead and the map/money updated.

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 3 8

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  S  .  .  .  .  E  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  S  .  .  .  .  E  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 4 1 1 1

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  S  .  .  .  .  E  .  .  . 
                                    
 .  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Path: r r r r r

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  >  >  >  >  >  E  .  .  . 
                                    
 .  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: t 1 5
Tower successfully created!

Lives: 100 Money: $300
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
               [B]                  
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  >  >  >  >  >  E  .  .  . 
                                    
 .  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: t 5 6
Tower successfully created!

Lives: 100 Money: $100
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
               [B]                  
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  >  >  >  >  >  E  .  .  . 
                                    
 .  ~  .  .  .  .  .  .  .  .  .  . 
                  [B]               
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 4 4
End Point: 2 7

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  S  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  S  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 0 0 3 3

Lives: 100 Money: $500
                                    
 ~  ~  ~  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  ~  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  ~  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  S  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Path: r r r u u

Lives: 100 Money: $500
                                    
 ~  ~  ~  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  ~  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  ~  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  ^  .  .  .  . 
                                    
 .  .  .  .  >  >  >  ^  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: t 1 1
Error: Tower creation unsuccessful. Make sure you have at least $200 and that the tower is placed on a grass block with no entity.

Lives: 100 Money: $500
                                    
 ~  ~  ~  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  ~  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  ~  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  ^  .  .  .  . 
                                    
 .  .  .  .  >  >  >  ^  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: t 4 6
Error: Tower creation unsuccessful. Make sure you have at least $200 and that the tower is placed on a grass block with no entity.

Lives: 100 Money: $500
                                    
 ~  ~  ~  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  ~  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  ~  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  ^  .  .  .  . 
                                    
 .  .  .  .  >  >  >  ^  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: t 10 5
Error: Tower creation unsuccessful. Make sure you have at least $200 and that the tower is placed on a grass block with no entity.

Lives: 100 Money: $500
                                    
 ~  ~  ~  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  ~  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  ~  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  ^  .  .  .  . 
                                    
 .  .  .  .  >  >  >  ^  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 1 1
End Point: 2 2

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  E  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  E  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 4 4 2 2

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  E  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  ~  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  ~  .  .  .  .  .  . 
Enter Path: r d

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  >  v  .  .  .  .  .  .  .  .  . 
                                    
 .  .  E  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  ~  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  ~  .  .  .  .  .  . 
Enter Command: t 3 3
Tower successfully created!

Lives: 100 Money: $300
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  >  v  .  .  .  .  .  .  .  .  . 
                                    
 .  .  E  .  .  .  .  .  .  .  .  . 
         [B]                        
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  ~  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  ~  .  .  .  .  .  . 
Enter Command: t 0 5
Tower successfully created!

Lives: 100 Money: $100
               [B]                  
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  >  v  .  .  .  .  .  .  .  .  . 
                                    
 .  .  E  .  .  .  .  .  .  .  .  . 
         [B]                        
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  ~  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  ~  .  .  .  .  .  . 
Enter Command: t 4 1
Error: Tower creation unsuccessful. Make sure you have at least $200 and that the tower is placed on a grass block with no entity.

Lives: 100 Money: $100
               [B]                  
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  >  v  .  .  .  .  .  .  .  .  . 
                                    
 .  .  E  .  .  .  .  .  .  .  .  . 
         [B]                        
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  ~  .  .  .  .  .  . 
                                    
 .  .  .  .  ~  ~  .  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

Testing and Submission

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1511 style, and clean up any issues a human may have reading your code. Don't forget -- 10% of your mark in the assignment is based on style!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_defence.c
1511 autotest-stage 02 cs_defence
give cs1511 ass1_cs_defence cs_defence.c

Stage 3

Stage 3.1 - Moving enemies

Command

m [num]

Description

Another important pillar of Tower Defence games is the ability for enemies to move from their spawn location to the ending location. The m command does this by moving all enemies on the path forwards num amount of times.

Upon reaching the end of the path, the number of lives that the player has should be decreased by the number of enemies that reached the end. A message, "n enemies reached the end!" should also be printed.

In the case where the player loses all their lives after enemies move to the end, the game should end immediately with an additional message "Oh no, you ran out of lives".

Assumptions/Restrictions/Clarifications

  • The num associated with this command will always be greater than 0.

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 2 1
End Point: 5 6

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Lake: 0 0 1 1

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Path: r r r r r d d d

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  >  >  >  >  >  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Command: e 5

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
   005                              
 .  >  >  >  >  >  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
      005                           
 .  >  >  >  >  >  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
         005                        
 .  >  >  >  >  >  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
            005                     
 .  >  >  >  >  >  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 2 1
End Point: 5 6

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Lake: 0 0 1 1

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  S  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Path: r r r r r d d d

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  >  >  >  >  >  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Command: e 5

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
   005                              
 .  >  >  >  >  >  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Command: m 7
0 enemies reached the end!

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  >  >  >  >  >  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                  005               
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Command: m 1
5 enemies reached the end!

Lives: 95 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  >  >  >  >  >  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  v  .  .  .  .  . 
                                    
 .  .  .  .  .  .  E  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 2 2
End Point: 2 7

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  S  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  S  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 0 0 1 1

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  S  .  .  .  .  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Path: r r r r r

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  >  >  >  >  >  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: e 5

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
      005                           
 .  .  >  >  >  >  >  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
         005                        
 .  .  >  >  >  >  >  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: e 2

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
      002005                        
 .  .  >  >  >  >  >  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: m 2
0 enemies reached the end!

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
            002005                  
 .  .  >  >  >  >  >  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: e 7

Lives: 100 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
      007   002005                  
 .  .  >  >  >  >  >  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: m 2
5 enemies reached the end!

Lives: 95 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
            007   002               
 .  .  >  >  >  >  >  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: m 3
9 enemies reached the end!

Lives: 86 Money: $500
                                    
 ~  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  >  >  >  >  >  E  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 3 6

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  S  .  .  E  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 99

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
         099
 .  .  .  S  .  .  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 0 0 2 2

Lives: 100 Money: $500

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
         099
 .  .  .  S  .  .  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r r r

Lives: 100 Money: $500

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
         099                        
 .  .  .  >  >  >  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 2
0 enemies reached the end!

Lives: 100 Money: $500

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
               099
 .  .  .  >  >  >  E  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: e 1

Lives: 100 Money: $500

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
         001   099
 .  .  .  >  >  >  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
99 enemies reached the end!

Lives: 1 Money: $500

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
            001
 .  .  .  >  >  >  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 1 Money: $500

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
               001
 .  .  .  >  >  >  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
1 enemies reached the end!

Lives: 0 Money: $500

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  >  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Oh no, you ran out of lives!
Game Over!

Stage 3.2 - Tower Upgrade

Command

u [row] [col]

Description

The ability to place towers on the board creates a way to fight off enemies (although we are still yet to implement this!). However, we really need different types of towers to fight off as many enemies as possible! For Stage 3.2, you will implement the u command, which will attempt to upgrade a tower at the specified row/col.

There are 3 tower types that exist in CS Defence, BASIC_TOWER, POWER_TOWER, FORTIFIED_TOWER. Each tower has different statistics for how they can attack enemies (implemented in Stage 3.3).

When using the u command on each type of tower,

  • BASIC_TOWER upgrades to POWER_TOWER at the cost of $300,
  • POWER_TOWER upgrades to FORTIFIED_TOWER at the cost of $500 and
  • FORTIFIED_TOWER cannot be upgraded.

Error Handling

There are many potential errors that you will need to handle for Stage 3.2, which are provided below.

  • The row/col provided is out-of-bounds of the map
    • Program should print: "Error: Upgrade target is out-of-bounds."
  • The target tile has no tower on it.
    • Program should print: "Error: Upgrade target contains no tower entity."
  • The target tile has a FORTIFIED_TOWER on it.
    • Program should print: "Error: Tower cannot be upgraded further."
  • The player does not have enough money to purchase this upgrade.
    • Program should print: "Error: Insufficient Funds."

Errors should be handled in the same order as the list above. Only a single error should be displayed at a time.

If, however, the upgrade is successful, "Upgrade Successful!" should be printed.

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 1000
Start Point: 4 4
End Point: 3 3

Lives: 100 Money: $1000

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  E  .  .  .  .  .  .  .  . 

 .  .  .  .  S  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $1000

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  E  .  .  .  .  .  .  .  .

 .  .  .  .  S  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 0 0 3 3

Lives: 100 Money: $1000

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 .  .  .  E  .  .  .  .  .  .  .  .

 .  .  .  .  S  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: u l

Lives: 100 Money: $1000

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 .  .  .  E  <  .  .  .  .  .  .  .

 .  .  .  .  ^  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 2 8
Tower successfully created!

Lives: 100 Money: $800

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  .  .  .  .  .  .  .  .  .
                        [B]
 ~  ~  ~  .  .  .  .  .  .  .  .  .

 .  .  .  E  <  .  .  .  .  .  .  .

 .  .  .  .  ^  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 8
Upgrade Successful!

Lives: 100 Money: $500

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  .  .  .  .  .  .  .  .  .
                        [P]
 ~  ~  ~  .  .  .  .  .  .  .  .  .
                                    
 .  .  .  E  <  .  .  .  .  .  .  .

 .  .  .  .  ^  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 8
Upgrade Successful!

Lives: 100 Money: $0

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  .  .  .  .  .  .  .  .  .
                        [F]
 ~  ~  ~  .  .  .  .  .  .  .  .  .

 .  .  .  E  <  .  .  .  .  .  .  .

 .  .  .  .  ^  .  .  .  .  .  .  .
                                    
 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!


dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 5000
Start Point: 3 3
End Point: 4 4

Lives: 100 Money: $5000

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  S  .  .  .  .  .  .  .  . 

 .  .  .  .  E  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $5000

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 0 0 1 1

Lives: 100 Money: $5000

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r d

Lives: 100 Money: $5000

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: t 1 1
Tower successfully created!

Lives: 100 Money: $4800

 ~  .  .  .  .  .  .  .  .  .  .  .
   [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command:  t 2 8
Tower successfully created!

Lives: 100 Money: $4600

 ~  .  .  .  .  .  .  .  .  .  .  .
   [B]
 .  .  .  .  .  .  .  .  .  .  .  .
                        [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 4 2
Tower successfully created!

Lives: 100 Money: $4400

 ~  .  .  .  .  .  .  .  .  .  .  .
   [B]
 .  .  .  .  .  .  .  .  .  .  .  .
                        [B]
 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  >  v  .  .  .  .  .  .  .
      [B]
 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 8
Upgrade Successful!

Lives: 100 Money: $4100

 ~  .  .  .  .  .  .  .  .  .  .  .
   [B]
 .  .  .  .  .  .  .  .  .  .  .  .
                        [P]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .
      [B]
 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 1 1
Upgrade Successful!

Lives: 100 Money: $3800

 ~  .  .  .  .  .  .  .  .  .  .  .
   [P]
 .  .  .  .  .  .  .  .  .  .  .  .
                        [P]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .
      [B]
 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 8
Upgrade Successful!

Lives: 100 Money: $3300

 ~  .  .  .  .  .  .  .  .  .  .  .
   [P]
 .  .  .  .  .  .  .  .  .  .  .  .
                        [F]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  . 
      [B]
 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 4 2
Upgrade Successful!

Lives: 100 Money: $3000

 ~  .  .  .  .  .  .  .  .  .  .  .
   [P]
 .  .  .  .  .  .  .  .  .  .  .  .
                        [F]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .
      [P]
 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 1 1
Upgrade Successful!

Lives: 100 Money: $2500

 ~  .  .  .  .  .  .  .  .  .  .  .
   [F]
 .  .  .  .  .  .  .  .  .  .  .  .
                        [F]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .
      [P]
 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 4 2
Upgrade Successful!

Lives: 100 Money: $2000

 ~  .  .  .  .  .  .  .  .  .  .  .
   [F]
 .  .  .  .  .  .  .  .  .  .  .  .
                        [F]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .
      [F]
 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 1300
Start Point: 3 3
End Point: 4 4

Lives: 100 Money: $1300

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Initial Enemies: 0

Lives: 100 Money: $1300

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 0 0 2 2

Lives: 100 Money: $1300

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r d

Lives: 100 Money: $1300

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  >  v  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 2 4
Tower successfully created!

Lives: 100 Money: $1100

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 8 2
Error: Upgrade target is out-of-bounds.

Lives: 100 Money: $1100

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  . 

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 2
Error: Upgrade target contains no tower entity.

Lives: 100 Money: $1100

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 4
Upgrade Successful!

Lives: 100 Money: $800

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [P]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 4
Upgrade Successful!

Lives: 100 Money: $300

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [F]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 4
Error: Tower cannot be upgraded further.

Lives: 100 Money: $300

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [F]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  . 

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 2 2
Tower successfully created!

Lives: 100 Money: $100

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
      [B]   [F]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  .

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 2
Error: Insufficient Funds.

Lives: 100 Money: $100

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
      [B]   [F]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  v  .  .  .  .  .  .  . 

 .  .  .  .  E  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!

Stage 3.3 - Attacking Enemies

Command

a [num]

Description

With the addition of moving enemies and spawning/upgrading towers, we can now add the ability to attack enemies with our towers! For Stage 3.3, you will implement the a command, which causes all existing towers to attack num amount of times, destroying enemies.

Every tower is able to attack in some range around its position. A range is defined by a single integer which indicates how far a tower can reach in each direction (up/down/left/right). The diagram below shows an example when a tower has a range of 2.

This diagram does not represent how your map actually looks. T is some tower with range 2 and each x represents a tile that T can attack.

3.3.1.jpg

When using the a command, towers will attack all enemies within their range. Towers also have another attribute - power. The power of a tower specifies how many enemies at each tile they can destroy. If a tower has a power of 2, then it will destroy 2 enemies at every tile in its range.

There are 3 types of towers in CS Defence, all with different ranges/powers:

Tower Type Range Power
BASIC_TOWER 1 1
POWER_TOWER 1 2
FORTIFIED_TOWER 2 3

During an attack, multiple towers can attack the same tile. If 5 BASIC_TOWERs all have the same 1 tile in range, potentially 5 enemies will be destroyed at it!

For each enemy destroyed, $5 should be added to the player's money. The total number of enemies destroyed should also be printed after an attack, "n enemies destroyed!".

Play around with the interactive below to get a feel for how tower ranges work and how they overlap!

Assumptions/Restrictions/Clarifications

  • The num associated with this command will always be greater than 0.
  • Be careful when a tower has a range that goes outside of the board.

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 3 5

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  S  .  E  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Initial Enemies: 5

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
         005
 .  .  .  S  .  E  .  .  .  .  .  .
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 0 0 3 3

Lives: 100 Money: $500

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  .  .  .  .  .  .  .  .  .
         005
 .  .  .  S  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: u u r r d d

Lives: 100 Money: $500

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  >  >  v  .  .  .  .  .  .

 ~  ~  ~  ^  .  v  .  .  .  .  .  .
         005
 .  .  .  ^  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 2 4
Tower successfully created!

Lives: 100 Money: $300

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  >  >  v  .  .  .  .  .  .
            [B]
 ~  ~  ~  ^  .  v  .  .  .  .  .  .
         005
 .  .  .  ^  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $300

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  >  >  v  .  .  .  .  .  .
         005[B]
 ~  ~  ~  ^  .  v  .  .  .  .  .  .

 .  .  .  ^  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: e 3

Lives: 100 Money: $300

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  >  >  v  .  .  .  .  .  .
         005[B]
 ~  ~  ~  ^  .  v  .  .  .  .  .  .
         003
 .  .  .  ^  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $300

 ~  ~  ~  .  .  .  .  .  .  .  .  .
         005
 ~  ~  ~  >  >  v  .  .  .  .  .  .
         003[B]
 ~  ~  ~  ^  .  v  .  .  .  .  .  .

 .  .  .  ^  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: e 6

Lives: 100 Money: $300

 ~  ~  ~  .  .  .  .  .  .  .  .  .
         005
 ~  ~  ~  >  >  v  .  .  .  .  .  .
         003[B]
 ~  ~  ~  ^  .  v  .  .  .  .  .  .
         006
 .  .  .  ^  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 3
0 enemies reached the end!

Lives: 100 Money: $300

 ~  ~  ~  .  .  .  .  .  .  .  .  .
            006003
 ~  ~  ~  >  >  v  .  .  .  .  .  .
            [B]005
 ~  ~  ~  ^  .  v  .  .  .  .  .  .

 .  .  .  ^  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: e 4

Lives: 100 Money: $300

 ~  ~  ~  .  .  .  .  .  .  .  .  .
            006003
 ~  ~  ~  >  >  v  .  .  .  .  .  .
            [B]005
 ~  ~  ~  ^  .  v  .  .  .  .  .  .
         004
 .  .  .  ^  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: a 1
4 enemies destroyed!

Lives: 100 Money: $320

 ~  ~  ~  .  .  .  .  .  .  .  .  .
            005002
 ~  ~  ~  >  >  v  .  .  .  .  .  .
            [B]004
 ~  ~  ~  ^  .  v  .  .  .  .  .  .
         003
 .  .  .  ^  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: a 2
8 enemies destroyed!

Lives: 100 Money: $360

 ~  ~  ~  .  .  .  .  .  .  .  .  .
            003
 ~  ~  ~  >  >  v  .  .  .  .  .  .
            [B]002
 ~  ~  ~  ^  .  v  .  .  .  .  .  .
         001
 .  .  .  ^  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: a 3
6 enemies destroyed!

Lives: 100 Money: $390

 ~  ~  ~  .  .  .  .  .  .  .  .  .

 ~  ~  ~  >  >  v  .  .  .  .  .  .
            [B]
 ~  ~  ~  ^  .  v  .  .  .  .  .  .

 .  .  .  ^  .  E  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 3 6

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  S  .  .  E  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Initial Enemies: 5

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
         005
 .  .  .  S  .  .  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 0 0 2 2

Lives: 100 Money: $500

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
         005
 .  .  .  S  .  .  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r r r

Lives: 100 Money: $500

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
         005
 .  .  .  >  >  >  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 2 4
Tower successfully created!

Lives: 100 Money: $300

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  .  .  .  .  .  .  .
         005
 .  .  .  >  >  >  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 4 5
Tower successfully created!

Lives: 100 Money: $100

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  .  .  .  .  .  .  .
         005
 .  .  .  >  >  >  E  .  .  .  .  .
               [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: a 1
1 enemies destroyed!

Lives: 100 Money: $105

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  .  .  .  .  .  .  .
         004
 .  .  .  >  >  >  E  .  .  .  .  . 
               [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $105

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  .  .  .  .  .  .  . 
            004
 .  .  .  >  >  >  E  .  .  .  .  .
               [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: a 1
2 enemies destroyed!

Lives: 100 Money: $115

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  .  .  .  .  .  .  .
            002
 .  .  .  >  >  >  E  .  .  .  .  .
               [B]
 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $115

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  .  .  .  .  .  .  .
               002
 .  .  .  >  >  >  E  .  .  .  .  .
               [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: a 1
2 enemies destroyed!

Lives: 100 Money: $125

 ~  ~  .  .  .  .  .  .  .  .  .  .

 ~  ~  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  >  E  .  .  .  .  .
               [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 2000
Start Point: 3 3
End Point: 3 6

Lives: 100 Money: $2000
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  S  .  .  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 30

Lives: 100 Money: $2000
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
         030                        
 .  .  .  S  .  .  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 0 0 2 2

Lives: 100 Money: $2000
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
         030                        
 .  .  .  S  .  .  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Path: r r r

Lives: 100 Money: $2000
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
         030                        
 .  .  .  >  >  >  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: t 2 7
Tower successfully created!

Lives: 100 Money: $1800
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                     [B]            
 .  .  .  .  .  .  .  .  .  .  .  . 
         030                        
 .  .  .  >  >  >  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: u 2 7
Upgrade Successful!

Lives: 100 Money: $1500
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                     [P]            
 .  .  .  .  .  .  .  .  .  .  .  . 
         030                        
 .  .  .  >  >  >  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: u 2 7
Upgrade Successful!

Lives: 100 Money: $1000
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                     [F]            
 .  .  .  .  .  .  .  .  .  .  .  . 
         030                        
 .  .  .  >  >  >  E  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: t 4 2
Tower successfully created!

Lives: 100 Money: $800
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                     [F]            
 .  .  .  .  .  .  .  .  .  .  .  . 
         030                        
 .  .  .  >  >  >  E  .  .  .  .  . 
      [B]                           
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: u 4 2
Upgrade Successful!

Lives: 100 Money: $500
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                     [F]            
 .  .  .  .  .  .  .  .  .  .  .  . 
         030                        
 .  .  .  >  >  >  E  .  .  .  .  . 
      [P]                           
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: t 2 3
Tower successfully created!

Lives: 100 Money: $300
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
         [B]         [F]            
 .  .  .  .  .  .  .  .  .  .  .  . 
         030                        
 .  .  .  >  >  >  E  .  .  .  .  . 
      [P]                           
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: a 1
3 enemies destroyed!

Lives: 100 Money: $315
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
         [B]         [F]            
 .  .  .  .  .  .  .  .  .  .  .  . 
         027                        
 .  .  .  >  >  >  E  .  .  .  .  . 
      [P]                           
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $315
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
         [B]         [F]            
 .  .  .  .  .  .  .  .  .  .  .  . 
            027                     
 .  .  .  >  >  >  E  .  .  .  .  . 
      [P]                           
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: a 1
1 enemies destroyed!

Lives: 100 Money: $320
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
         [B]         [F]            
 .  .  .  .  .  .  .  .  .  .  .  . 
            026                     
 .  .  .  >  >  >  E  .  .  .  .  . 
      [P]                           
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $320
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
         [B]         [F]            
 .  .  .  .  .  .  .  .  .  .  .  . 
               026                  
 .  .  .  >  >  >  E  .  .  .  .  . 
      [P]                           
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: a 1
3 enemies destroyed!

Lives: 100 Money: $335
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
                                    
 ~  ~  .  .  .  .  .  .  .  .  .  . 
         [B]         [F]            
 .  .  .  .  .  .  .  .  .  .  .  . 
               023                  
 .  .  .  >  >  >  E  .  .  .  .  . 
      [P]                           
 .  .  .  .  .  .  .  .  .  .  .  . 
                                    
 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

Stage 3.4 - Rain

Command

r [row_spacing] [column_spacing] [row_offset] [column_offset]

Description

It’s time to add some extra challenge to the game - In the form of an environmental event! For Stage 3.4, you will implement the r command to rain down and form water blocks on the map.

At the code level, rain will fall onto tiles on the map and should change the land of these tiles to WATER.

The water blocks mentioned should be formed in a pattern, described by the attributes given with the r command.

The row_spacing/column_spacing attributes describe the distance between each water block in both dimensions.

The row_offset/column_offset attributes describe how far each water block is offset from the (0, 0) position on the map. Water blocks can appear off the map (in the same pattern), so offsetting by a large enough number can bring them onto the map!

Have a look at the examples below to understand how each of these attributes work.

If the provided command is r 2 3 0 0, then the map will look like this (assuming the map is initially all grass):

3.4.1.jpg

With no offset, the pattern will always start in the top-left corner. It is important to notice that water appears every 2 rows and every 3 columns, as this was our spacing inputs! If we instead add an offset using r 2 3 1 2 as the command, the map would have been filled in like this:

3.4.2.jpg

All water spots are shifting down a row and across 2 columns.

Still confused? Play around with the interactive below until you are confident that you understand Stage 3.4!

Row Spacing
Column Spacing
Row Offset
Column Offset

If rain hits either a BASIC_TOWER or POWER_TOWER, then both are destroyed as they cannot stand on water. FORTIFIED_TOWERS are unaffected.

Assumptions/Restrictions/Clarifications

  • row_spacing/col_spacing will only be integers greater than 0, and can exceed the size of the map in both dimensions.
  • row_offset/col_offset will be any integers, including negative ones.
  • Rain can only form water on GRASS blocks. It will not form on any path tiles.

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 2
End Point: 1 6

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  E  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  S  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Initial Enemies: 0

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  S  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 1 1 1 1

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  ~  .  .  .  .  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  S  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r r r r u u

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  ~  .  .  .  .  E  .  .  .  .  .

 .  .  .  .  .  .  ^  .  .  .  .  .

 .  .  >  >  >  >  ^  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: r 2 3 0 0

Lives: 100 Money: $500

 ~  .  .  ~  .  .  ~  .  .  ~  .  .

 .  ~  .  .  .  .  E  .  .  .  .  .

 ~  .  .  ~  .  .  ^  .  .  ~  .  .

 .  .  >  >  >  >  ^  .  .  .  .  .

 ~  .  .  ~  .  .  ~  .  .  ~  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 2
End Point: 1 6

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  E  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  S  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  S  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: 1 1 1 1

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  ~  .  .  .  .  E  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  S  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
                                    
 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r r r r u u

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  ~  .  .  .  .  E  .  .  .  .  .

 .  .  .  .  .  .  ^  .  .  .  .  .

 .  .  >  >  >  >  ^  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: r 2 3 1 2

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  ~  ~  .  .  ~  E  .  ~  .  .  ~

 .  .  .  .  .  .  ^  .  .  .  .  .

 .  .  >  >  >  >  ^  .  ~  .  .  ~

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  ~  .  .  ~  .  .  ~  .  .  ~
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 3 5

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: -1 0 1 1
Error: Lake out of bounds, ignoring...

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  S  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r r

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  E  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: r 2 4 -5 -3

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  ~  .  .  .  ~  .  .  .  ~  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  ~  .  >  >  E  .  .  .  ~  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  ~  .  .  .  ~  .  .  .  ~  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 3 5

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Initial Enemies: 0

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Lake: -1 0 1 1
Error: Lake out of bounds, ignoring...

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r r

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: r 2 4 101 -199

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  ~  .  .  .  ~  .  .  .  ~  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  ~  .  >  >  E  .  .  .  ~  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  ~  .  .  .  ~  .  .  .  ~  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 2000
Start Point: 3 3
End Point: 3 5

Lives: 100 Money: $2000

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  S  .  E  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Initial Enemies: 0

Lives: 100 Money: $2000

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  E  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: -1 0 1 1
Error: Lake out of bounds, ignoring...

Lives: 100 Money: $2000

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r r

Lives: 100 Money: $2000

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 0 2
Tower successfully created!

Lives: 100 Money: $1800
      [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 2 2
Tower successfully created!

Lives: 100 Money: $1600
      [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
      [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 2 4
Tower successfully created!

Lives: 100 Money: $1400
      [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
      [B]   [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 0 2
Upgrade Successful!

Lives: 100 Money: $1100
      [P]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
      [B]   [B]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: u 2 4
Upgrade Successful!

Lives: 100 Money: $800
      [P]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
      [B]   [P]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 4
Upgrade Successful!

Lives: 100 Money: $300
      [P]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
      [B]   [F]
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  E  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: r 2 2 0 0

Lives: 100 Money: $300

 ~  .  ~  .  ~  .  ~  .  ~  .  ~  .

 .  .  .  .  .  .  .  .  .  .  .  .
            [F]
 ~  .  ~  .  ~  .  ~  .  ~  .  ~  .

 .  .  .  >  >  E  .  .  .  .  .  .

 ~  .  ~  .  ~  .  ~  .  ~  .  ~  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!

Testing and Submission

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1511 style, and clean up any issues a human may have reading your code. Don't forget -- 10% of your mark in the assignment is based on style!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_defence.c
1511 autotest-stage 03 cs_defence
give cs1511 ass1_cs_defence cs_defence.c

Stage 4

Stage 4.1 - Flooding

Command

f [num]

Description

To add even more variety to the game, an additional environmental event will be included! For Stage 4.1, you will implement the f command that will cause flooding on the map.

In CS Defence, upon triggering a flood, all water blocks on the map spill outwards in 4 directions (up/down/left/right). This means that any water created from the initial lake and the rain event have the ability to flood outwards. This flooding repeats num amount of times.

Water that appears from flooding will destroy BASIC_TOWERs and POWER_TOWERs, but not FORTIFIED_TOWERs. Water can only flood to GRASS land, it will not go onto any path tiles.

Create a custom map in the interactive below with at least 1 water block and see all these interactions at work (make sure to click the "flood map" button)!

Assumptions/Restrictions/Clarifications

  • The num associated with this command will always be an integer greater than 0.

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 0 0
End Point: 0 1

Lives: 100 Money: $500

 S  E  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Initial Enemies: 0

Lives: 100 Money: $500

 S  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 2 6 1 1

Lives: 100 Money: $500

 S  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  ~  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r

Lives: 100 Money: $500

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
                                    
 .  .  .  .  .  .  ~  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: f 1

Lives: 100 Money: $500

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  ~  .  .  .  .  .

 .  .  .  .  .  ~  ~  ~  .  .  .  .

 .  .  .  .  .  .  ~  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: f 1

Lives: 100 Money: $500

 >  E  .  .  .  .  ~  .  .  .  .  .

 .  .  .  .  .  ~  ~  ~  .  .  .  .

 .  .  .  .  ~  ~  ~  ~  ~  .  .  .

 .  .  .  .  .  ~  ~  ~  .  .  .  .

 .  .  .  .  .  .  ~  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: f 3

Lives: 100 Money: $500

 >  E  .  ~  ~  ~  ~  ~  ~  ~  .  .

 .  .  ~  ~  ~  ~  ~  ~  ~  ~  ~  .

 .  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~

 .  .  ~  ~  ~  ~  ~  ~  ~  ~  ~  .

 .  .  .  ~  ~  ~  ~  ~  ~  ~  .  .

 .  .  .  .  ~  ~  ~  ~  ~  .  .  .
Enter Command: f 1

Lives: 100 Money: $500

 >  E  ~  ~  ~  ~  ~  ~  ~  ~  ~  .

 .  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~ 

 .  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~

 .  .  ~  ~  ~  ~  ~  ~  ~  ~  ~  .

 .  .  .  ~  ~  ~  ~  ~  ~  ~  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 3 7

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  S  .  .  .  E  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 2 5 1 1

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  S  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: u u u r r r r d d d

Lives: 100 Money: $500

 .  .  .  >  >  >  >  v  .  .  .  .

 .  .  .  ^  .  .  .  v  .  .  .  .

 .  .  .  ^  .  ~  .  v  .  .  .  .

 .  .  .  ^  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: f 1

Lives: 100 Money: $500

 .  .  .  >  >  >  >  v  .  .  .  .

 .  .  .  ^  .  ~  .  v  .  .  .  .

 .  .  .  ^  ~  ~  ~  v  .  .  .  .

 .  .  .  ^  .  ~  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: f 1

Lives: 100 Money: $500

 .  .  .  >  >  >  >  v  .  .  .  .

 .  .  .  ^  ~  ~  ~  v  .  .  .  .

 .  .  .  ^  ~  ~  ~  v  .  .  .  . 

 .  .  .  ^  ~  ~  ~  E  .  .  .  .

 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: f 1

Lives: 100 Money: $500

 .  .  .  >  >  >  >  v  .  .  .  .

 .  .  .  ^  ~  ~  ~  v  .  .  .  .

 .  .  .  ^  ~  ~  ~  v  .  .  .  .

 .  .  .  ^  ~  ~  ~  E  .  .  .  .

 .  .  .  .  ~  ~  ~  .  .  .  .  . 

 .  .  .  .  .  ~  .  .  .  .  .  .
Enter Command: f 1

Lives: 100 Money: $500

 .  .  .  >  >  >  >  v  .  .  .  .

 .  .  .  ^  ~  ~  ~  v  .  .  .  .

 .  .  .  ^  ~  ~  ~  v  .  .  .  .

 .  .  .  ^  ~  ~  ~  E  .  .  .  .

 .  .  .  ~  ~  ~  ~  ~  .  .  .  . 

 .  .  .  .  ~  ~  ~  .  .  .  .  .
Enter Command: f 4

Lives: 100 Money: $500

 .  .  .  >  >  >  >  v  .  .  .  .

 .  .  ~  ^  ~  ~  ~  v  ~  .  .  .

 .  ~  ~  ^  ~  ~  ~  v  ~  ~  .  .

 ~  ~  ~  ^  ~  ~  ~  E  ~  ~  ~  .

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 2000
Start Point: 0 0
End Point: 0 1

Lives: 100 Money: $2000

 S  E  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Initial Enemies: 0

Lives: 100 Money: $2000

 S  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 3 5 1 1

Lives: 100 Money: $2000

 S  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r

Lives: 100 Money: $2000

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
                                    
 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 3 4
Tower successfully created!

Lives: 100 Money: $1800

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 2 5
Tower successfully created!

Lives: 100 Money: $1600

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
               [B]
 .  .  .  .  .  .  .  .  .  .  .  .
            [B]
 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: t 3 6
Tower successfully created!

Lives: 100 Money: $1400

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
               [B]
 .  .  .  .  .  .  .  .  .  .  .  .
            [B]   [B]
 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 2 5
Upgrade Successful!

Lives: 100 Money: $1100

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
               [P]
 .  .  .  .  .  .  .  .  .  .  .  .
            [B]   [B]
 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: u 3 6
Upgrade Successful!

Lives: 100 Money: $800

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
               [P]
 .  .  .  .  .  .  .  .  .  .  .  .
            [B]   [P]
 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: u 3 6
Upgrade Successful!

Lives: 100 Money: $300

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
               [P]
 .  .  .  .  .  .  .  .  .  .  .  . 
            [B]   [F]
 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: f 1

Lives: 100 Money: $300

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  ~  .  .  .  .  .  .
                  [F]
 .  .  .  .  ~  ~  ~  .  .  .  .  .

 .  .  .  .  .  ~  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: f 5

Lives: 100 Money: $300

 >  E  ~  ~  ~  ~  ~  ~  ~  .  .  .

 .  ~  ~  ~  ~  ~  ~  ~  ~  ~  .  .

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  .
                  [F]
 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  .

 .  ~  ~  ~  ~  ~  ~  ~  ~  ~  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 0 0
End Point: 0 1

Lives: 100 Money: $500

 S  E  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Initial Enemies: 0

Lives: 100 Money: $500

 S  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: -1 0 1 1
Error: Lake out of bounds, ignoring...

Lives: 100 Money: $500

 S  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r

Lives: 100 Money: $500

 >  E  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: r 2 3 0 0

Lives: 100 Money: $500

 >  E  .  ~  .  .  ~  .  .  ~  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 ~  .  .  ~  .  .  ~  .  .  ~  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 ~  .  .  ~  .  .  ~  .  .  ~  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: f 1

Lives: 100 Money: $500

 >  E  ~  ~  ~  ~  ~  ~  ~  ~  ~  .

 ~  .  .  ~  .  .  ~  .  .  ~  .  .

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  .

 ~  .  .  ~  .  .  ~  .  .  ~  .  .

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  .

 ~  .  .  ~  .  .  ~  .  .  ~  .  .
Enter Command: f 1

Lives: 100 Money: $500

 >  E  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  .

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  .

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~

 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  .
Enter Command: [CTRL+D]
Game Over!

Stage 4.2 - Creating Teleporters

Command

c [row1] [column1] [row2] [column2]

Description

It is time to make some modifications to the path that enemies follow! For Stage 4.2, you will implement the c command, which will create two teleporters, one at (row1, column1) and another at (row2, column2). These teleporters will appear on the path and enemies that move onto either teleporter are then transported to the other teleporter.

When creating these teleporters, the corresponding tiles should have their land component set to TELEPORTER. Teleporters can only be created on path tiles. When created, all path tiles between the two teleporters along the path should have their land set back to GRASS.

There is no specified order that the teleporters specified in the c command appear on the path. The first could appear before the second, or the second could appear before the first.

It is also possible to use the c command multiple times and create many teleporter pairs. In the case where a teleporter pair “encapsulates” a previous teleporter pair, that previous pair should be deleted (just like path tiles!). See example 4.2.4 for clarification.

Error Handling

In the case where the given teleporter points do not appear on the path (including if they are out of the map!), "Error: Teleporters can only be created on path tiles.” should be printed.

It is important to note that the ending point on the map is not considered as a path tile for this task. The above error should be given if the user attempts to place a teleporter on the ending point.

Assumptions/Restrictions/Clarifications

  • The two teleporter positions provided in a single c command will never be the same. (This means c 0 1 0 1 will never occur)
  • Teleporting occurs when enemies are on a teleporter and then moved. They do not teleport as soon as they are on the teleporter tile.
  • A new teleporter cannot and will not be created at the same tile that a previous teleporter is on.
  • Enemies on the path tiles that get changed to grass should be deleted from the map.
  • Enemies on the path tiles that get changed to teleporters remain in that position, unchanged

Examples

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 3 7

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  S  .  .  .  E  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 5

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
         005
 .  .  .  S  .  .  .  E  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 0 0 1 1

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
         005
 .  .  .  S  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: u u r r r r d d

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  >  >  v  .  .  .  .

 .  .  .  ^  .  .  .  v  .  .  .  .
         005
 .  .  .  ^  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: c 1 3 1 7

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  . ( ) .  .  .  .

 .  .  .  ^  .  .  .  v  .  .  .  .
         005
 .  .  .  ^  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  . ( ) .  .  .  .
         005
 .  .  .  ^  .  .  .  v  .  .  .  .

 .  .  .  ^  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .
         005
 .  .  . ( ) .  .  . ( ) .  .  .  .

 .  .  .  ^  .  .  .  v  .  .  .  .

 .  .  .  ^  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .
                     005
 .  .  . ( ) .  .  . ( ) .  .  .  .

 .  .  .  ^  .  .  .  v  .  .  .  .

 .  .  .  ^  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  . ( ) .  .  .  .
                     005
 .  .  .  ^  .  .  .  v  .  .  .  .

 .  .  .  ^  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
5 enemies reached the end!

Lives: 95 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  . ( ) .  .  .  .

 .  .  .  ^  .  .  .  v  .  .  .  .

 .  .  .  ^  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 3 7

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  S  .  .  .  E  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  .  .  E  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 0 0 1 1

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: u u r r r r d d

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  >  >  v  .  .  .  .

 .  .  .  ^  .  .  .  v  .  .  .  .

 .  .  .  ^  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: c 3 3 2 7

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  . ( ) .  .  .  .

 .  .  . ( ) .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: e 5

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  . ( ) .  .  .  .
         005
 .  .  . ( ) .  .  .  E  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
                     005
 .  .  .  .  .  .  . ( ) .  .  .  .

 .  .  . ( ) .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: e 5

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
                     005
 .  .  .  .  .  .  . ( ) .  .  .  .
         005
 .  .  . ( ) .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
5 enemies reached the end!

Lives: 95 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
                     005
 .  .  .  .  .  .  . ( ) .  .  .  .
                                    
 .  .  . ( ) .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
5 enemies reached the end!

Lives: 90 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  . ( ) .  .  .  .

 .  .  . ( ) .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 4 1
End Point: 2 9

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  E  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  S  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 8

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  E  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
   008
 .  S  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 0 0 1 1

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  E  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
   008
 .  S  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: d r r r u u l u l l u u r r r r r d d d d r r r u u

Lives: 100 Money: $500

 ~  >  >  >  >  >  v  .  .  .  .  .

 .  ^  .  .  .  .  v  .  .  .  .  .

 .  ^  <  <  .  .  v  .  .  E  .  .

 .  .  .  ^  <  .  v  .  .  ^  .  .
   008
 .  v  .  .  ^  .  >  >  >  ^  .  .

 .  >  >  >  ^  .  .  .  .  .  .  .
Enter Command: c 5 2 3 3

Lives: 100 Money: $500

 ~  >  >  >  >  >  v  .  .  .  .  .

 .  ^  .  .  .  .  v  .  .  .  .  .

 .  ^  <  <  .  .  v  .  .  E  .  .

 .  .  . ( ) .  .  v  .  .  ^  .  .
   008
 .  v  .  .  .  .  >  >  >  ^  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: c 2 3 0 1

Lives: 100 Money: $500

 ~ ( ) >  >  >  >  v  .  .  .  .  .

 .  .  .  .  .  .  v  .  .  .  .  .

 .  .  . ( ) .  .  v  .  .  E  .  .

 .  .  . ( ) .  .  v  .  .  ^  .  . 
   008
 .  v  .  .  .  .  >  >  >  ^  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: c 0 4 4 7

Lives: 100 Money: $500

 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .

 .  .  . ( ) .  .  .  .  .  ^  .  . 
   008
 .  v  .  .  .  .  . ( ) >  ^  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: c 4 8 3 9

Lives: 100 Money: $500

 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .

 .  .  . ( ) .  .  .  .  . ( ) .  .
   008
 .  v  .  .  .  .  . ( )( ) .  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .

 .  .  . ( ) .  .  .  .  . ( ) .  .

 .  v  .  .  .  .  . ( )( ) .  .  .
   008
 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .
                                    
 .  .  . ( ) .  .  .  .  . ( ) .  .

 .  v  .  .  .  .  . ( )( ) .  .  .
      008
 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  . 
         008
 .  .  . ( ) .  .  .  .  . ( ) .  .

 .  v  .  .  .  .  . ( )( ) .  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
         008
 .  .  . ( ) .  .  .  .  .  E  .  .

 .  .  . ( ) .  .  .  .  . ( ) .  . 

 .  v  .  .  .  .  . ( )( ) .  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500
   008
 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .

 .  .  . ( ) .  .  .  .  . ( ) .  .

 .  v  .  .  .  .  . ( )( ) .  .  .

 .  > ( ) .  .  .  .  .  .  .  .  . 
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500
      008
 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .

 .  .  . ( ) .  .  .  .  . ( ) .  .

 .  v  .  .  .  .  . ( )( ) .  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500
         008
 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .

 .  .  . ( ) .  .  .  .  . ( ) .  .

 .  v  .  .  .  .  . ( )( ) .  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500
            008
 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .

 .  .  . ( ) .  .  .  .  . ( ) .  .

 .  v  .  .  .  .  . ( )( ) .  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .

 .  .  . ( ) .  .  .  .  . ( ) .  .
                     008
 .  v  .  .  .  .  . ( )( ) .  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  . 

 .  .  . ( ) .  .  .  .  . ( ) .  .
                        008
 .  v  .  .  .  .  . ( )( ) .  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .
                           008
 .  .  . ( ) .  .  .  .  . ( ) .  .

 .  v  .  .  .  .  . ( )( ) .  .  . 

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: m 1
8 enemies reached the end!

Lives: 92 Money: $500

 ~ ( ) >  > ( ) .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  . ( ) .  .  .  .  .  E  .  .

 .  .  . ( ) .  .  .  .  . ( ) .  . 

 .  v  .  .  .  .  . ( )( ) .  .  .

 .  > ( ) .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 4 1
End Point: 2 7

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  E  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  S  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 5

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  E  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
   005
 .  S  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: 0 0 1 1

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
   005
 .  S  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: u u u r r r r r r d

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  >  >  >  >  >  >  v  .  .  .  .

 .  ^  .  .  .  .  .  E  .  .  .  . 

 .  ^  .  .  .  .  .  .  .  .  .  .
   005
 .  ^  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: c 1 2 1 5

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  > ( ) .  . ( ) >  v  .  .  .  .

 .  ^  .  .  .  .  .  E  .  .  .  .

 .  ^  .  .  .  .  .  .  .  .  .  .
   005
 .  ^  .  .  .  .  .  .  .  .  .  .
                                    
 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: c 3 1 1 7

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  . ( ) .  .  .  .

 .  .  .  .  .  .  .  E  .  .  .  .

 . ( ) .  .  .  .  .  .  .  .  .  .
   005
 .  ^  .  .  .  .  .  .  .  .  .  .
                                    
 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  . ( ) .  .  .  .

 .  .  .  .  .  .  .  E  .  .  .  .
   005
 . ( ) .  .  .  .  .  .  .  .  .  .

 .  ^  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
0 enemies reached the end!

Lives: 100 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .
                     005
 .  .  .  .  .  .  . ( ) .  .  .  .

 .  .  .  .  .  .  .  E  .  .  .  . 

 . ( ) .  .  .  .  .  .  .  .  .  .

 .  ^  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: m 1
5 enemies reached the end!

Lives: 95 Money: $500

 ~  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  . ( ) .  .  .  .

 .  .  .  .  .  .  .  E  .  .  .  .

 . ( ) .  .  .  .  .  .  .  .  .  .

 .  ^  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: [CTRL+D]
Game Over!

dcc cs_defence.c -o cs_defence
./cs_defence
Starting Lives: 100
Starting Money($): 500
Start Point: 3 3
End Point: 3 7

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  S  .  .  .  E  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  . 
Initial Enemies: 0

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Lake: -1 0 1 1
Error: Lake out of bounds, ignoring...

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  S  .  .  .  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Path: r r r r

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  >  >  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: c -1 0 3 3
Error: Teleporters can only be created on path tiles.

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  >  >  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: c 3 3 -1 0
Error: Teleporters can only be created on path tiles.

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
                                    
 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  >  >  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: c 3 3 2 2
Error: Teleporters can only be created on path tiles.

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  >  >  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: c 2 2 3 3
Error: Teleporters can only be created on path tiles.

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  >  >  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: c 3 4 3 7
Error: Teleporters can only be created on path tiles.

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  >  >  >  >  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 
Enter Command: c 3 7 3 4
Error: Teleporters can only be created on path tiles.

Lives: 100 Money: $500

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  . 

 .  .  .  >  >  >  >  E  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .

 .  .  .  .  .  .  .  .  .  .  .  .
Enter Command: [CTRL+D]
Game Over!

Testing and Submission

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1511 style, and clean up any issues a human may have reading your code. Don't forget -- 10% of your mark in the assignment is based on style!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_defence.c
1511 autotest-stage 04 cs_defence
give cs1511 ass1_cs_defence cs_defence.c

Extra Challenge

You will be using the SplashKit library to creare a more graphical tower defence game in your terminal window. Please share your GUI images on the forums - we would love to see them!

You will find all the SplashKit Documentation here. SplashKit Text allows for drawing text in a variety of ways to graphic windows. SplashKit Images allow drawing of bitmaps and sprites to graphic windows. SplashKit is already installed on the CSE machines, so you will just need to include it #include "splashkit.h" to have access to the graphics library. Your challenge is to familiarise yourself with the library and to use the included procedures and functions to draw up your perfect Tower Defence game. We look forward to seeing your games! To compile using SplashKit libraries, you will need to skm clang++ program.c -o program.

To help you get started, there is a small starter code to introduce you to a few of the functions challenge_example.c or use this command on your CSE account to copy the file into your current directory:

cp -n /web/cs1511/23T1/activities/cs_defence/challenge_example.c .




Assessment

Assignment Conditions

  • Joint work is not permitted on this assignment.

    This is an individual assignment.

    The work you submit must be entirely your own work. Submission of any work even partly written by any other person is not permitted.

    Except, you may use small amounts (< 10 lines) of general purpose code (not specific to the assignment) obtained from a site such as Stack Overflow or other publically available resources. You should attribute clearly the source of this code in an accompanying comment.

    Assignment submissions will be examined, both automatically and manually for work written by others.

    Do not request help from anyone other than the teaching staff of COMP1511, e.g. in the course forum & help sessions.

    Do not post your assignment code to the course forum - the teaching staff can view assignment code you have recently autotested or submitted with give.

    Rationale: this assignment is designed to develop the individual skills needed to produce an entire working program. Using code written by or taken from other people will stop you learning these skills. Other CSE courses focus on the skill needed for work in a team.

  • The use of code-synthesis tools, such as GitHub Copilot, is not permitted on this assignment.

    Rationale: this assignment is intended to develop your understanding of basic concepts. Using synthesis tools will stop you learning these fundamental concepts.

  • Sharing, publishing, distributing your assignment work is not permitted.

    Do not provide or show your assignment work to any other person other than the teaching staff of COMP1511. For example, do not message your work to friends.

    Do not publish your assignment code via the internet. For example, do not place your assignment in a public GitHub repository.

    Rationale: by publishing or sharing your work you are facilitating other students using your work which is not permitted. If they submit your work, you may become involved in an academic integrity investigation.

  • Sharing, publishing, distributing your assignment work after the completion of COMP1511 is not permitted.

    For example, do not place your assignment in a public GitHub repository after COMP1511 is over.

    Rationale: COMP1511 sometimes reuses assignment themes using similar concepts and content. Students in future terms find your code and use it which is not permitted and you may become involved in an academic integrity investigation.

Violation of the above conditions may result in an academic integrity investigation with possible penalties, up to and including a mark of 0 in COMP1511 and exclusion from UNSW.

Relevant scholarship authorities will be informed if students holding scholarships are involved in an incident of plagiarism or other misconduct. If you knowingly provide or show your assignment work to another person for any reason, and work derived from it is submitted you may be penalised, even if the work was submitted without your knowledge or consent. This may apply even if your work is submitted by a third party unknown to you.

Note, you will not be penalised if your work is taken without your consent or knowledge.

For more information, read the UNSW Student Code, or contact the course account. The following penalties apply to your total mark for plagiarism:

0 for the assignment Knowingly providing your work to anyone and it is subsequently submitted (by anyone).
0 for the assignment Submitting any other person's work. This includes joint work.
0 FL for COMP1511 Paying another person to complete work. Submitting another person's work without their consent.

Submission of Work

You should submit intermediate versions of your assignment. Every time you autotest or submit, a copy will be saved as a backup. You can find those backups here, by logging in, and choosing the yellow button next to 'cs_defence.c'.

Every time you work on the assignment and make some progress you should copy your work to your CSE account and submit it using the give command below.

It is fine if intermediate versions do not compile or otherwise fail submission tests.

Only the final submitted version of your assignment will be marked.

You submit your work like this:

give cs1511 ass1_cs_defence cs_defence.c

Assessment Scheme

This assignment will contribute 20% to your final mark.

80% of the marks for this assignment will be based on the performance of the code you write in cs_defence.c

10% of the marks for this assignment will be given from the automatic style checker that will be run on your code. The utility 1511 style can help with this!

10% of the marks for this assignment will come from manual marking of the readability of the C you have written. The manual marking will involve checking your code for clarity, and readability, which includes the use of functions and efficient use of loops and if statements.

Marks for your performance will be allocated roughly according to the below scheme.

100% for Performance Completely Working Implementation, which exactly follows the spec (Stage 1, 2, 3 and 4).
85% for Performance Completely working implementation of Stage 1, 2 and 3.
65% for Performance Completely working implementation of Stage 1 and Stage 2.
35% for Performance Completely working implementation of Stage 1.

The Challenge stage of the assignment is NOT worth any marks, but is something fun for you to work on getting to know a new library and building something more visual!

Style Marking Rubric

0 1 2 3 4
Formatting (/5)
Indentation (/2) - Should use a consistent indentation scheme. Multiple instances throughout code of inconsistent/bad indentation Code is mostly correctly indented Code is consistently indented throughout the program
Whitespace (/1) - Should use consistent whitespace (for example, 3 + 3 not 3+ 3) Many whitespace errors No whitespace errors
Vertical Whitespace (/1) - Should use consistent whitespace (for example, vertical whitespace between sections of code) Code has no consideration for use of vertical whitespace Code consistently uses reasonable vertical whitespace
Line Length (/1) - Lines should be max. 80 characters long Many lines over 80 characters No lines over 80 characters
Documentation (/5)
Comments (incl. header comment) (/3) - Comments have been used throughout the code above code sections and functions to explain their purpose. A header comment (with name, zID and a program description) has been included No comments provided throughout code Few comments provided throughout code Comments are provided as needed, but some details or explanations may be missing causing the code to be difficult to follow Comments have been used throughout the code above code sections and functions to explain their purpose. A header comment (with name, zID and a program description) has been included
Function/variable/constant naming (/2) - Functions/variables/constants names all follow naming conventions in style guide and help in understanding the code Functions/variables/constants names do not follow naming conventions in style guide and help in understanding the code Functions/variables/constants names somewhat follow naming conventions in style guide and help in understanding the code Functions/variables/constants names all follow naming conventions in style guide and help in understanding the code
Organisation (/5)
Function Usage (/4) - Code has been decomposed into appropriate functions separating functionalities No functions are present, code is one main function Some functions are present, but functions are all more than 50 lines Some functions are present, and all functions are approximately 50 lines long Most code has been moved to sensible/thoought out functions, but they are mostly more than 50 lines (incl. main function) All code has been meaningfully decomposed into functions of approx 50 lines (incl. main function)
Function Prototypes (/1) - Function Prototypes have been used to declare functions above main Functions are used but have not been prototyped All functions have a prototype above the main function or no functions are used
Elegance (/5)
Overdeep nesting (/2) - You should not have too many levels of nesting in your code (nesting which is 5 or more levels deep) Many instances of overdeep nesting <= 3 instances of overdeep nesting No instances of overdeep nesting
Code Repetition (/2) - Potential repetition of code has been dealt with via the use of functions or loops Many instances of repeated code sections <= 3 instances of repeated code sections Potential repetition of code has been dealt with via the use of functions or loops
Constant Usage (/1) - Any magic numbers are #defined None of the constants used throughout program are #defined All constants used are #defined and are used consistently in the code
Illegal elements
Illegal elements - Presence of illegal elements including: Global Variables, Static Variables, Labels or Goto Statements CAP MARK AT 16/20

Due Date

This assignment is due 27 March 2023 20:00:00. For each day after that time, the maximum mark it can achieve will be reduced by 5% (off the ceiling).
  • For instance, at 1 day past the due date, the maximum mark you can get is 95%.
  • For instance, at 3 days past the due date, the maximum mark you can get is 85%.
  • For instance, at 5 days past the due date, the maximum mark you can get is 75%.
  • No submissions will be accepted after 5 days late, unless you have special provisions in place.

    Change Log

    Version 1.0
    (2023-06-03 14:00)
    • Assignment Released
    Version 1.01
    (2023-08-03 22:52)
    • Specify `num` can only be a positive integer in Stage 4.1
    Version 1.02
    (2023-14-03 17:58)
    • Specify that stage 2.2 only takes in positive integers due to reference solution bug
    Version 1.03
    (2023-19-03 23:32)
    • Specify that teleporters provided in 4.2 will never have the same position