SE 2811, Lab 6: Observations

This is an individual lab.

A common travel game is to find the letters in a word on the license plates of vehicles that you see on the road. For example, the license plates ATT-351 and CPO-OO3 would be sufficient to match "CAT". For this lab, you will be given code that draws cars, buses, and a person moving around a map. As the person comes into contact with a car, that car's plate will be used to match letters in various keywords. The first keyword you will match is "MSOE". Your implementation will use the Observer Pattern.

The starting point for this lab is at se2811-mketour.zip. (Note: if your instructor is using Github Classroom, this code may be in your repository as soon as you create it.) A key class being given to you is CityMap. It displays a portion of Milwaukee. This map is just for reference - your game pieces will not actually follow the roads and will even float across the harbor. This map also includes a Museum represented by a rectangular area you can walk through. The moving objects are subclasses of the abstract class MobileEntity. We use the term "tagging" to mean colliding with another object. The base class Taggable are those objects that can collide with other objects.

The following diagram shows the relationship between the objects on the map:

The CityMap has multiple museums and entities. The entities are in an actors package:

We are giving you code to draw these actors on the map. You will implement a simple game based on a tourist visiting the city and completing three challenges: The BUS challenge is intended to be an Easter egg in that it only starts when the user tags a bus. Show a picture of The Wood Gatherer (in the repository folder src/mketour/img) when the user enters the art museum. Display "MSOE CHALLENGE COMPLETED" when all of the target letters in MSOE are found, and "BUS CHALLENGE COMPLETED" when all of the letters in BUS are found. A sample image of game play in progress is

This shows what it looks like after the player has tagged the art museum, plates with the letters M and O, and a bus. Note all of these items are shown in the right hand window. Also note the BUS challenge only shows after the user tags (hits) a bus. The person is guided on the map by dragging the green circle (the goal circle). The initial game status would be shown as

Challenge: Find all the letters in MSOE
Goal: MSOE
Found: ****

Challenge: Find art

The asterisks show which letters have not yet been found. Announce the challenges being completed (e.g., BUS CHALLENGE COMPLETED) in this same window.

Hints

A good place to start is by implementing an observer that displays The Wood Gatherer when the person enters the Milwaukee Art Museum box. Then implement the observer for license plates matching the goal "MSOE". Finally, you should be able to implement the observer for matching the goal "BUS" by reusing previous observers.

How you use the Observer Pattern is one of the many choices you need to make in this assignment. One approach is to take an existing domain object or objects (such as Person, Car, or MobileEntity) and make that the subject. Another approach is to make the event of tagging an object (such as when the bus tags the person) into a subject. A related question is what data to pass in the operation to update the observers. You could pass the objects being tagged, the subject that is producing the event, or data such as license plates. These choices have no clear answers, and the "best" solution often comes down to the one that makes the most sense to individual students. Do not be afraid to experiment! No matter what you do, make sure how you are using the pattern isolates your observers and your subjects. There should be very little communication between your observers and your subjects.

Additional requirements

A major part of this assignment is implementing the Observer Pattern. You are to write your own classes implementing this pattern; do not use Java.util.Observable or Java.util.Observer. You may use your own names for the Observer Pattern; it may be helpful to use names that are specific to the problem such as "CarObserver" or "TagObserver." Solutions should not need to use casting. For example, you should not need to cast from an Object to Taggable.

One goal of the Observer Pattern (like other patterns) is to simplify future modifications to existing code when supporting new features. You should not need to modify existing classes other than to introduce the code for the pattern and to modify CityMap.addEntities() to support a new challenge.

When you submit, check that CityMap.DEBUG_LEVEL is 0 so any debug code is disabled. Console messages about contacting buses and museums might be useful to you, but large numbers of messages slow down your solution and make it difficult to grade. Make sure all of your output is controlled by DEBUG_LEVEL.

Submission

See your instructor for submission directions.

This lab was developed by Dr. Yoder in Winter 2018-19.