Assignment 3 - Sreesudhan, Wangho and Parag

Assignment 3

ramakris, wangho and pmalshe

Overall design

Open / Save functionality:

xml object serialization is used for open / save functionality. JFileChooser library is used for this purpose. A new button name "Save" is added, when clicked, pops up SaveDialog window. This window get the location and input file name to which objects needs to be saved. Once file name is obtained, the objects (requests) present in the array list are stored on to the file.
When open functionality is clicked, the GUI requests to select a file, once file is choosen, all the objects written in that file is loaded back into the array and the last object is executed.

Layout manager:

Strategy pattern is used, and JFrame, JPanel and JButton are contained by custom classes instead of being extended. Composite pattern takes the behavior of MyLayoutList similar to MyLayoutManager, and MyLayoutList implements MyLayoutManager, and MyLayoutManager is also by MyFlowLayout and MyBorderLayout.

Resizing:

Timer is used to trigger the re-painting of the game panel, control panel and clock timer. Whenever timer expires, the game frame size is checked and if the size has changed, then the layout manager method is triggered which paints button at proper locations.

Design patterns:

Three design patterns are implemented: Observer pattern, Command pattern, Iterator pattern.

Observer pattern:

clock and game objects including wall, brick, ball and paddle are subscribers to the observable: changing time, and all these visual objects implement interface Tickable and Drawable, and so all these visual objects implement their own methods tick() and draw(). Method tick() is called whenever timer expires in order to update states of each object, and then method draw() is called to repaint visual objects.

Command pattern:

All requests from control panel and normal
playing are encapsulated into command objects, these command objects all implement command interface Command, and so all implement their own methods execute() and unexecute(). The CommandStack contains all history commands. Normal scenario playing is cut into frames and driven by the timer, and tick() is called once for each frame, and thus returns a corresponding command which is added to CommandStack and then executed immediately. The actually operation of an object is contained in calling execute() and unexecute() methods.

Iterator pattern:

Then, control panel has 4 buttons with 6 functions: Pause/Play, Undo, Rewind, Record/Reset. The Record/Reset button pressed means "Reset" function when the scenario is in recording state, and means "Record" function when the scenario is NOT in recording state. Pressing Reset button is caught by ActionPerformed() method and resettable objects including gameScene and clock will call their own execute() method seperately and clear CommandStack history. Remember, interface Resettable is used for resettable objects including clock and Gamescene, while Gamescene class contains entity objects. The Undo button steps back on game scenario frame, while the Rewind button restart the whole game scenario from the beginning. These buttons take effect on both game scene and clock.

Next, the normal playing scenario is driven by the timer. Each timer interval is a frame, and tick() will be called for each frame and thus same commands will be added into CommandStack history for each frame during normal playing. That's the mechanism the Undo button can go back one command along with objects and corresponding old states. The timer expiration event is caught by scheduled timertask and then ReplayManager run() method. And then if the game scenario state is NOT paused, then it has two cases. Case 1 means the game scenario is recording, which means normal playing, then command object for all observers are added into CommandStack history as one macroCommand (all commands in one frame), and then excute this macroCommand; Case 2 means the game scenario is NOT recording, which means rewinding or replaying, then reexecute() all macroCommands from current postion until the End of CommandStack.

And then, there are some manager classes: Breakout, Commandstack, DrawingManager, Gamescene, macroCommand, Physics manager and Replay manager. All these classes contains other objects as its content or consist of other objects. They provide stages for other objects or encapsulates methods of other objects. The Physics manager consist of only some common methods for collision dectection. The breakout class provide the main frame of the whole program. The Replay manager encapsulates all tick() execute(), and unexecute() methods.

Finally, there are some concrete command implemente the command interface: Destroycommand coresponding to Brick; Restcommand and Tickcommand corresponding to clock; Movecommand corresponding to Entity; setupcommand and destroycommand corresponding to Gamescene; Reflect command corresponding to mobilityEntity; Nullcommand corresponding to nothing will do. Objects from these command are saved into commandStack.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.