Week7

http://www.halcyon.com/amalmin/java.html

Note: This weeks code won't run off the web. It is no longer an applet. Download the code and the two GIF files available on the week6 page, compile it, and run it with the appletviewer if you want to see it work. In the future I hope to be able to inbed the graphics into one of the class files...

/*****************************************************************************/
/* History                                                                   *
 *****************************************************************************
 * ANM	5-7-98	Added splashscreen.
 *              Explicit Frame creation.  Can't get the damned thing to close,
 *                  though.
 *              no more applet code.
 *		5-8-98	More work on exiting properly...
 *				Animated splash screen.
 *				Zapped one un-used frame.
 *		5-9-98	DrawPanel renamed MainPanel.
 *				More fiddling with the splash screen.
 *				General code cleanup.
 */
 
/*
 * Audin Malmin
 * 5-4-98
 * Java/OS week 7 (maybe) (I've lost count).
 *
 * This week has mainly seen the conversion from an Applet to a normal Java program.  An
 * applet isn't allowed to do all the things the program is supposed to do, so we are forced
 * into this conversion.  (Not that I didn't know it was necessary in the beginning.)  I still
 * haven't quite gotten the new code working correctly.  The program still does not exit
 * properly...(all the windows close, but some thread somewhere never quits).
 *
 * Secondly, this week has seen the implimentation of a start up splash screen...(which can
 * optionally bounce around the screen...just to be really annoying...)
 *
 * The Applet -> Java Program conversion went through 2 stages...first by a direct replacemnt
 * of the applet code with normal code, and second with the re-writing of main() and most of
 * the program object code.  This second re-write eliminated one exteranous Frame and just
 * generally cleaned up the startup procedure.
 *
 * Finally were some small changes to the rest of the code...mostly just cleaning up some of
 * the overly verbose sections.
 *
 * Current layout (has-a relationships):
 *
 * ColonyApplet --+
 *       |        |
 *       |    MainPanel --+--------+---------+---------------+---------+---------+
 *       |                |        |         |               |         |         |
 *    Splash*          LocalDL RemoteDL   LocalCL        %RemoteCL PopupMenu PopupMenu
 *       |              |   |    |   |     |  |            |    |
 *     Window          Dude |   Dude |     | CathUpdate*%  |  CathUpdate*%
 *       |                  |        |     |               |
 *   ImgCanvas          DudeUpdate*  | Cathedral       Cathedral%
 *    |     |                        |
 *  Image Label                 DudeUpdate*
 *
 * Key:		*: thread		%: Not yet implimented
 *
 * (is-a relationships):
 *
 * Frame -> ColonyApplet	: The overall program object.  Contains main(), and one
 *                            MainPanel object (which does all the work).
 *
 * Thread-> Splash			: The splash screen thread.  It just throws up a borderless window
 *                            and paints a graphic in it.  It then sleeps for 10 seconds, after
 *                            which time it just zaps the window and exits.
 *
 * Frame -> MainPanel		: The heavy working object...Does everything.
 *                            The main event loop is here...
 *
 * Menu -> PopupMenu		: Just a normal multi-level popup menu.
 *
 * LocalDL -> RemoteDL
 *
 * LocalCL -> RemoteCL	(At least in the future)
 *
 * So basically, MainPanel is the main program loop.  It sets everything up and
 * handles events.  MainPanel contains two popup menus and two DudeList objects.
 *
 * LocalDL is kind of a mutant linked list container.  It does contain a linked list
 * of Dude objects.  In addition it contains a DudeUpdate object.
 *
 * RemoteDL is derived from LocalDL.  It is identical except for the fact that, in the future,
 * it RemoteDL will get it's movement, creation, and destruction information from the remote
 * machine.
 *
 * DudeUpdate is a thread.  It's job is to animate each of the Dudes.  Basically it
 * runs through the linked list on it's own (it gets a pointer to the "first" Dude
 * object), calling the Dude.move() function for each one.  The DudeUpdate constructor
 * also gets a pointer to the main MainPanel object, so that it can get ahold of the
 * Graphics Context and the background color.
 *
 * LocalCL is another bastard linked list container.  It contains a list of Cathedral object.
 * RemoteCL will be derived from it; again adding a network interfact.
 *
 * Cathedral currently just contains an image.  In the future I plan to have it animate a
 * small string of images...  Cathedrals should be created based on the number of followers
 * each player has.  Their design will shift (toward more complicated, larger structures) as
 * the population grows in size and knowledge.
 *
 * So what does it all do???????????????
 *
 * * It compiles and runs.
 *
 * * It displays a splash screen for 10 seconds, during which time the rest of the program
 *   loads and sets itself up.  (The splash screen is in the forground, so you can watch the
 *   main program window set itself up in the background.)
 *
 * * Optionally, the splash screen can slide around the screen, bouncing off the edges of the
 *   monitor.  This doesn't work very well, though..at least on my mid-range PCI video
 *   hardware (it flickers quite a bit).
 *
 * * Two cathedrals are created and displayed.
 *
 * * Left-clicking on the screen will create one red Dude directly under the mouse
 *   cursor, and one blue Dude will be created randomly somewhere else.
 *
 * * The Dudes (both red and blue) will move around the window, bouncing off the
 *   edges.
 *
 * * The Dudes will vary slightly in color.  (Ie: all red dudes are red, but some are
 *   brighter and some are darker.)
 *
 * * Right-clicking on an unoccupied section of screen you will get a popup menu
 *   with a list of acts you can perform on the general area.  These acts will have
 *   a circle of influance on which they will be active.  They will also most likely
 *   "taint" the area with an aura of fear.  (ie: the Dudes should try to stay away
 *   from these areas.)
 *
 * * Right-clicking in a small area around a Dude will give you a popup menu with both
 *   the normal options and acts you can inflict on the Dude itself.  The menu also
 *   gives you the Dude's number.  Currently the only working option is "Mutate", which
 *   causes the dude to double in size.
 *
 * * Right-clicking on a cathedral will try to identify the cathedral.  In the future it will
 *   bring up a menu with cathedral options.
 *
 * So what doesn't it do???
 *
 * * You can't currently kill a Dude.  This isn't hard to add, though.
 *
 * * There's a problem with erasing the first drawing of a Dude...so you get some
 *   fluff left over on the background.
 */
 

The source code.


Audin Malmin