Star Wars Game


Program description

Program implements simple game -- Star Wars. User selects ships and ships are started to destroy if user selected three or more similar ships (interface.jpg). Game has time limitation, score calculation and time bonuses. Design of the game could be done easier but it was done in more extended way in order to master OO concepts. Realization

Platform: Win32. Language: C++. Interface: Win32 API. Reference: Jeffrey Richter, Advanced Windows.
Status: not finished.

Classes description (alphabetically)

AbstractTimer -- realize functionality of visible timer (watch). Class implements all functions to manipulate time but still has abstract method draw() from VisibleObject. Class uses objects Digit for each digit and Elements for separators.

AnimatedObject -- realizes animation in system. Class uses functionality of ImageList for storing animation frames and implements methods of VisibleObject what allows inserting this object to Panel. AnimatedObject creates separate thread for output frames, can show each frame, whole animation once and several times in loop. Several AnimatedObjects can be synchronized in order to show complex animation when several animations can overlapped but all frames are showed synchronically (Critical Sections).

BigTimer -- realize representation of visible timer with wide or liquid crystal lines. Class initiates creation of LiquidCrystalDigitElement trough Digit and implements method draw() through calling of draw() of all digits.

Counter -- realizes universal counter. Class uses objects Digit for representation each digit. Size of Counter and type of used classes in each Digit (ThinDigitElement, WideDigitElement or LiquidCrystalDigitElement) can be configured in constructor.

Digit -- realizes electronic type digit. Digit is constructed from seven Elements. Size of digit, brightness and type of used elements (ThinDigitElement, WideDigitElement or LiquidCrystalDigitElement) can be configured in constructor.

Field -- realizes one field of board. Class implements status of field and has reference to Ship appropriate in current status. Ships are shared between fields and Space has set of Ship objects.

ImageList -- loads images from resource, keeps images list and implements functions for manipulation of images.

LiquidCrystalDigitElement -- extends functionality of WideDigitElement and realizes element that looks like liquid crystal one. Size, width and brightness of element can be configured in constructor.

Panel -- realizes two main functions -- implements flat panel with bevels and container for other objects that were derived from VisibleObject. Method draw() draws panel first and calls method draw() of all inserted objects.

ThinDigitElement -- realizes one element of Digit and shows itself as single line. Size and brightness of element can be configured in constructor.

Ship -- realizes representation of each type of ships in each status. Class creates AnimatedObjects for showing of animation and implements specific functions of ship.

SmallTimer -- realize representation of visible timer with thin lines. Class initiates creation of ThinDigitElements trough Digit and implements method draw() through calling of draw() of all digits.

Space -- is manager of program. Class has set of Ships that are shared between Fields, set of Fields, general interface panel and system timer. Class implements construction, destruction and logic of program (random selection of next field and changes status of fields (on timer event)). Class receives all messages and forwards them to appropriate Field. If three or more same ships are selected, Space creates new thread for handling this situation and continues to work. New thread starts animation for appropriate ships and died.

VisibleObject -- is abstract class and provides interface for all visible objects. All classes that were derived from VisibleObject can be inserted to Panel.

WideDigitElement -- realizes one element of Digit and shows itself as multiple line. Size, width and brightness of element can be configured in constructor.

Comments

In this design I used three design patterns (I think, at least three).
1. VisibleObject + Panel -- Decorator
2. Space + Ship -- Flyweight
3. AbstractTimer + DigitElement -- Factory method, though SmallTimer creates instance of ThinDidgitElement and BigTimer creates instance of LiquidCrystalDigitElement through class Digit.