CS 202 - Computer Science II - Spring 2008
Lab 9 - Model/View/Controller


Loyola College > Department of Computer Science > Dr. James Glenn > CS 202 > Labs > Lab 9

Due

Wednesday, April 9th at 11:59pm. Labs submitted one day late will be assessed a 20% penalty. Labs will not be accepted more than one day late.

Objectives

Reading

Wu, Chapter 14

Introduction


The evil Seeborgs have overrun most of planet Javalon. Only the capital city of Oopsonia remains under Javalonian control. Forward Base Omega is the last of the city's defenses, but its control system was damaged in the last Seeborg attack. Dr. Richard G. James, head of Javalonian computer systems, was almost finished reimplementing the control system but went out for a donut break and was never seen again. Presumably he was captured by the Seeborgs. Fortunately he left a prototype and instructions for completing the control system.

You are Javalon's last hope!

Assignment

Complete the code in the Spaceship and OmegaWindow classes.

Spaceship needs paint reimplemented to draw the Seeborg spaceships correctly (the code that is in paint now simply draws a colored rectangle). Your new version of paint should use the x, y, width, and height fields of the Spaceship object to determine the coordinates to use to draw the ship. Note that those fields are doubles and so must be cast to ints to be passed to the Graphics methods.

OmegaWindow needs to be updated to include classes that implement listeners for mouse movement (to aim the cannon) and mouse clicks (to fire the cannon). Instances of those listener classes must be registered on the view object. The event handlers should invoke the aimCannon and fireCannon methods in the model. There is also code that needs to be added to the actionPerformed method in the TimerListener inner class to update the view by getting the values for score, time left, and energy from the model, displaying those values in the appropriate components, and then redrawing the cannon and spaceships.

Files

The Java archive contains

Advice

Exercises

The code that updates the score, time, and energy displays is currently in the OmegaWindow class in one of the listeners. The listeners, however, are the controller part of the Model/View/Controller architecture. Updating the displays should be the responsibility of the view. Explain how the code can be refactored to fix this design flaw. What other violations of the model/view/controller architecture do you see? (Hint: consider the Spaceship class, which is part of the model.)

Submissions

Submit the source code (.java file) for your completed OmegaWindow and Spaceship classes.