home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pcad!johns
- From: johns@pcad.UUCP (John Storey)
- Newsgroups: comp.lang.c++
- Subject: Beginner OOD question
- Keywords: OOD dungeon interface
- Message-ID: <625@pcad.UUCP>
- Date: 23 Nov 92 18:33:29 GMT
- Organization: Personal CAD Systems, Westford, MA
- Lines: 44
-
- Just learning C++ (and MS-Windows, as an aside). I was putting together a test program
- for the following two classes: STICON and STBITMAP, which basically are just encapsulating
- some functionality for manipulating icons and bitmaps on a Microsoft Windows window.
-
- So I decided the classic hero and monster in a dungeons would work nicely, and came up
- with the following classes:
-
- Dungeon ('has a' hero, a monster (as icons) and walls and corridors (as bitmaps))
- Hero
- Monster
- VIO (basically, I want to hide the MS-Windows specific stuff - handles to windows,
- etc., from the first three classes, so I figured that I could have them
- communicate their information to VIO who would take care of it -
- so Hero would say to Dungeon "Move me north one space" and if that
- was ok Dungeon would say to VIO "Draw a corridor at (x,y)" which is
- Hero's previous position, and then tell Hero "Draw yourself at (x,y)"
- causing Hero to tell VIO "Draw Hero at (x,y)"
-
-
- My problem with all this, is that the Hero and the Dungeon know all about each other. So I wanted
- to separate them. This led me to recreating (so I'm told) the Smalltalk interface - I had everyone
- have a common ancestor object UMC (Universal Message Center) which allowed them to send messages to
- each other - at the same time learning how to use static data members, Borland's Templates, and
- the importance of virtual destructors, so even though is the wrong approach I at least learned alot.
-
- So, does anyone have any suggestions as to how to best keep the Dugeon and Hero separate here? I've
- been thinking that another class which keeps the position of all moveable objects in the dungeon stored,
- which makes replacing one Dungeon with another easy, but it seems like now that both the Dungeon and
- Hero class still have a pretty high degree of coupling, just now with the new class instead of each other.
-
- My other problem here is that there is no reason for my original two classes (STICON and STBITMAP
- ) to be known about by anyone other that the VIO class, so I have to have the Hero class and
- the VIO class would contain an STICON corressponding to the Hero. This actually strikes me as the
- correct approach, but it's seems needlessly complicated to have two classes representing the
- same icon on the screen.
-
- Sorry if I'm a bit unclear hear - I really explain things much better with a whiteboard so I can
- draw the class interactions as I talk, and truth to tell some points are muddled in my mind as well
- (else I wouldn't need to post, eh?)
-
- Thanks in advance,
- John Storey
- mail to: uunet!pcad.odin!johns
-
-