CPSC170 Lab 2

Inheritance

Test Cases

This is an unpartnered exercise. You will be provided with a copy of two different sets of test cases. You will also be provided with a copy of the grading rubric that is being used to grade your work. You will grade the other test cases based off of the grading rubric.

Class Hierarchy

Yesterday in class, as a pre-lab assignment, you were asked to write *ON PAPER* code that represents three drawable shapes, all which inherit from a generic shape class. You should make sure that your class layouts look correct, and begin implementation of these classes. You are going to be asked to extend these classes during lab.

Drawing Program

In class, we discussed mouse_test.py. This module defines a handful of functions, which are bound to a mouse listener. These functions are called when the mouse button is clicked, moved, etc. You are going to create a new module based off of this file, as well as the updating window class you worked with last lab.

Create a new class called draw_shapes.py. This class should import the files you used to implement the Class Hierarchy's you brought to lab today. You should also copy and paste a working copy of the UpdatingWindow class in this file. You will need to write a handful of functions that will draw the shapes, as you have defined them, upon the mouse being clicked.

Bind the 'Q', 'W', and 'E' keys so that they allow the user to change the shape that is drawn when they click the screen. You will also want to bind 'Escape' so that the screen is cleared when pressed. You should make sure that all of your shapes continue to exist after the screen updates.

Extending your Classes

You are now going to extend the three classes you wrote, by adding functionality. As a start, add a method called alter to your generic shape class. It should do nothing for a generic shape. You are going to create three new shape classes, which will inherit from your three current shape classes. Right now, there should be no additional functionality.

Bind the keys 'A', 'S', and 'D' to these new shapes. You should be able to draw 6 different shapes, even though by appearance it will only look like 3 different shapes.

These new three classes should override the alter method. The alter method should change the appearance of the shape being drawn. Make sure you can call the alter method on an already drawn shape, and the shape's appearance changes.

Finally, change the behavior of the mouse button click listener. It should determine if you clicked in an empty location, or if you clicked on an already drawn shape. If you clicked on an already drawn shape, you should call the alter method to change the appearance of the shape. Otherwise, draw the currently selected shape.

Make sure first that if you click on an already drawn shape, that a new shape is not drawn. Also make sure that if the already drawn shape is one of the alterable shapes, its appearance changes in some defined way.

Submission

MAKE SURE YOU TURN IN YOUR PAPER COPIES OF THE CLASS HEIRARCHIES! These will count as a quiz grade, graded mostly on completion.

Submit a zip file of your code on the course Inquire site using the format FirstLast.zip as the file name.

If you worked with a partner, use the file format FirstLastFirstLast.zip. Don't forget to also email your partner the lab material.