CS 010 - Introduction to Computer Science I
Assignment 4:

DUE: Thursday, 8/12 before 11:00pm


Collaboration Policy

Collaboration is strongly ENCOURAGED. You will be working in teams, but programs must represent YOUR OWN original work. Teams should work on the algorithm together and help debug/test each others code. However, copying code from ANY source (any book, current or past students, past solutions, the web, etc.) is STRICTLY FORBIDDEN. Code between teamates will be similar, but you are not allowed to just copy a teamate's solution.


Code that is turned in, must be contained in a .cpp file named main.cpp. Files of any other format will not be graded (e.g. main.doc, main.txt, etc…).

You must turn your work in from a lab computer on campus.

Turn in online to as4 folder. If you turn your assignment in to the wrong folder, your assignment may not be graded. If it is graded, you will lose 2 pts (out of 10).

Remember to include the following header information at the top of your program;

// last name, first name
// last 4 digits of SID
// UCR email address
// user name (log in name)


Problem Definition:

    For this assignment you will modify the program you wrote for assignment 3.  You will now draw the ship using a void function that is passed one Point object, the Point will represent the ship's location in the window.  In addition to this function, you must write two more;  a function to draw the landscape, and a function to draw an explosion.

    The landscape function returns void, and isn't passed any parameters--it just draws your landscape.  The explosion function will return void, and is passed one Point object, the Point will represent the location in the window to draw the explosion.  Your program should work as in assignment 3--the user can move the ship around the window until the edge of the window makes contact with the ship.  The difference is that now instead of sending a message to the window saying "the ship has left the window," you will draw an explosion where the ship made contact with the window's edge.  Note that even though you will be drawing the ground, the ship is allowed to pass through it without exploding.

    Note that the explosion must correspond to the location where the ship touches the window's edge.  This means that no matter where the ship makes contact (top, bottom, left, or right side of the window) the explosion should be visible whole or in part at the ship's final position.  Because of this, you will have to pay careful attention to the dimensions of your window (set using cwin.coord()), and to the distance your ship is moved each time the user selects a movement.  For example, if the window's dimensions are 100 X100, and a single move in the x direction places your ship at point (150, 0) the explosion that is drawn will not be visable in the window.
    It should take no more than 10 moves to move from the far left to the far right side of the window, this is also true for moving from the far bottom to the far top of the window.

Example program download
main


Rubric: (10 pts total)

From this point on, any programs turned in that do not compile will receive an automatic zero, no exceptions.

1 pts: Allows user to move the ship around as long as it's inside the window
1 pts: Moves the correct direction based on user's input
3 pts: Draws a visable explosion at the point where the ship makes contact with the window's edge
1 pts: Correct function header for ship function
1 pts: Correct function
header for explosion function
1 pts: Correct function header for ground function
2 pts: Style (0.5 each)
       - Good variable names
       - Proper indentation
       - Good comments
       - No line wraps

Bonus +1 point
Create a fourth function to handle collision detection with the ground.  When called, this function will return true if the ship makes contact with either the landscape, or the window's edge, otherwise it should return false.  Then, from your main function, you should use the value returned by collision() to decide if you should draw a ship, or an explosion.  You should pass this function a Point indicating the current position of the ship.