CS 010 - Introduction to Computer Science I
Assignment 4:

DUE: November 5th before 5: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-(group_letter) 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;

// Course: CS 10
//
// Lecture Section: ... 001 or 002
// Lab Section: ... 021, 022, etc)
//
// Assignment #: ... assignment 2, 3, etc.
//
// Last Name: Enter your LAST (family) name here (eg, Doe)
// First Name: Enter your FIRST (given) name here (eg, John)
//
// ID Number: Enter your ID number here (eg, 860-00-0000)
// lab login id: Enter your cs10 login here (eg, jdoe)
//
// Email address: Enter your UCR email address here (eg, jdoe@cs.ucr.edu)
//
// Group: Enter your group here (eg, D4)
// Teammates: List the names of the teammates you worked with
// Meeting Time: Specify the next time your team plans to meet
//
// =======================================================================



Problem Definition:

    For this assignment you will modify the program you wrote for assignment 3.  You will now draw your 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 one more;  a function to draw an explosion.

    The explosion function will return void, and is passed one Point object.  Like the draw ship function, the Point will represent the location in the window to draw the explosion.  Your program should work as in assignment 3, except now the user can continuously move the ship around until the edge of the graphics window makes contact with the ship!  Once the ship is moved such that it hits the window's edge, you will draw an explosion EXACTLY where the ship made contact.

    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 your ship is very close to the edge of the window (but not touching it), and you then move your ship a great distance beyond the window's edge, the explosion that is drawn will not be visible in the window.

    Once the explosion is drawn, your program will just wait for the graphics window to be closed.

    IMPORTANT!  It should take no more than 10 moves to go 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.

2 pts: Allows user to move the ship around as long as it's inside the window
1 pt: Moves the correct direction based on user's input/correctly redraws ship
2 pts: Draws a visable explosion EXACTLY where the ship makes contact with the window's edge
1 pt: Correct function header for ship function
1 pt: Correct function
header for explosion function
1 pt: Takes no more than 10 moves to move across the window (horizontally or vertically)
2 pts: Style
       - Good variable names
       - Proper indentation and spacing
       - Good comments
       - No line wraps
       - No magic numbers

Bonus +1 point
Read ahead and figure out how to use the boolean "or" operator.  Use this in a SINGLE if-else statement to determine whether you should draw the ship, or draw the explosion.