Conforming Smiley Face       CPS 004.1, 28 July 2003

You are to add your Smiley Face to your previous classwork to make it move in a circle. So you will now have four shapes moving in different kinds of circles. Since your circling behavior works on any kind of shape, you will need to make your Smiley Face into a shape as well to be able to add your Smiley Face to the dance. This means it is no longer sufficient to think of your Smiley Face as simply a collection of shapes, but instead something that can be used exactly as any GP shape can.

This assignment is meant to familiarize you with the following concepts discussed in class and your reading:

Specifications

You will update the code in your Smiley Face class to conform to the interface of other shapes in GP so that it can be used in the same way they can be. To do this, you must write the following eight functions (two for each of the four attributes) within your Smiley face class in addition to your constructor: You have already written the code that will be needed for some of these functions, but may not have thought to separate the code into different pieces because you are currently only using it only once, in the constructor. To animate the Smiley Face, we need to change the attributes of a Smiley face many times during the course of a program, e.g., making it move or shrink.

To make these functions work, you will need to change the variables you use to store the shapes that make up your Smiley Face from variables local to the constructor to instance variables that are available to all functions within the class.

Finally, once you have written the above functions, you should make your Smiley face extend a GP.Shape (i.e., a generic shape). Conceptually, this allows your Smiley face to be treated as simply a shape by any other object and thus be used any where any kind of shape is expected. Concretely, this makes it so that your Smiley face inherits all of the functions already written for shapes that work generically for any kind of shape. The ones listed above need to be rewritten for your specific Smiley face to make them work with your particular implementation.

Once you have completed these tasks, you should be able to use your Smiley face with the behavior you wrote previously --- without changing any part of the behavior! Why? Because other methods in GP are built from the methods you wrote above. For example, recall the code to make a shape, called myTarget, fall by a velocity, myVelocity, in the FallBehavior:

     myTarget.Move(myVelocity);
In GP, Move is implemented in terms of Get and SetPosition that you wrote above:
     public void Move (GP.Attributes.Vector velocity)
     {
         SetPosition(velocity.GetNextPosition(GetPosition()));
     }
In this code, the SetPosition and GetPosition methods that are called are based on the specific kind of shape that implemented them. Thus, your code is called by GP to make your shape move --- all GP does is give you the position to move to. An example can be seen online here. A worked out example can be seen online here.

What to Submit

You should start a new project for this exercise. You should feel free to copy your code from the previous exercise, but you will be making many changes. Additionally, we will want to look at this exercise separately from your previous work. When finished, you and your partner should transfer the entire project folder created by Visual J++ to your respective public_html/cps4 folder in the acpub system and update your course web page to link to the newly transferred project using the guidelines given here.