home *** CD-ROM | disk | FTP | other *** search
- /*
- * Boxes game
- *
- * 14 Dec 90 Paul DuBois dubois@primate.wisc.edu
- *
- * 14 Dec 90 V1.00
- * 13 Jun 92
- * - Updated to compile under THINK C 5.02. No functional changes except that
- * calls to alerts and modal dialogs were modified to use SkelDlogFilter().
- * 03 Oct 93
- * - Updated to compile under THINK C 6.0. Also checks for color depth and
- * disables Colors... menu item if it doesn't apply.
- *
- * 21 Feb 94
- * - Updated for TransSkel 3.11.
- */
-
- # include "TransSkel.h"
-
- # include "Boxes.h"
-
-
- # define bailString "\pBoxes"
-
-
- typedef enum
- {
- fileMenuNum = 1000,
- editMenuNum,
- optionsMenuNum
- };
-
-
- typedef enum /* File menu item numbers */
- {
- info = 1,
- /* --- */
- quit = 3
- };
-
-
- enum /* edit menu item numbers */
- {
- editUndo = 1,
- /* ---- */
- editCut = 3,
- editCopy = 4,
- editPaste = 5,
- editClear = 6
- };
-
-
- typedef enum /* Options menu item numbers */
- {
- newGame = 1,
- boardSize,
- colorSelect,
- /* --- */
- onePlayer = 5,
- twoPlayer,
- threePlayer,
- fourPlayer
- };
-
-
- static void Terminate (void);
-
-
- FontInfo fontInfo; /* info about system font */
-
-
- static WindowPtr dispWind;
- static MenuHandle fileMenu;
- static MenuHandle editMenu;
- static MenuHandle optionsMenu;
-
-
- static void
- Bail (StringPtr msg)
- {
- Message4 (bailString, "\p: ", msg, "\p Bailing out.");
- Terminate ();
- }
-
-
-
- /*
- * Handle selection of About… item from Apple menu
- */
-
- static pascal void
- DoAppleMenu (short item)
- {
- short alrtNum;
-
- alrtNum = ((SkelGetModifiers () & optionKey) == 0 ? aboutAlrt : authorAlrt);
- (void) SkelAlert (alrtNum, SkelDlogFilter (nil, true),
- skelPositionOnParentDevice);
- SkelRmveDlogFilter ();
- }
-
-
- /*
- * File menu handler
- */
-
- static pascal void
- DoFileMenu (short item)
- {
- switch (item)
- {
- case info:
- (void) SkelAlert (infoAlrt, SkelDlogFilter (nil, true),
- skelPositionOnParentDevice);
- SkelRmveDlogFilter ();
- break;
- case quit:
- SkelStopEventLoop ();
- break;
- }
- }
-
-
- /*
- * Edit menu handler. Since the menu has no meaning for Boxes, all
- * that is done is to route the selection to any desk accessory that
- * might want it.
- */
-
- static pascal void
- DoEditMenu (short item)
- {
- (void) SystemEdit (item - 1);
- }
-
-
- /*
- * Options menu handler
- */
-
- static pascal void
- DoOptionsMenu (short item)
- {
- switch (item)
- {
- case newGame:
- NewGame ();
- break;
- case boardSize:
- BoardDialog ();
- break;
- case colorSelect:
- ColorDialog ();
- break;
- case onePlayer:
- SetPlayerCount (1);
- NewGame ();
- break;
- case twoPlayer:
- SetPlayerCount (2);
- NewGame ();
- break;
- case threePlayer:
- SetPlayerCount (3);
- NewGame ();
- break;
- case fourPlayer:
- SetPlayerCount (4);
- NewGame ();
- break;
- }
- }
-
-
- void
- SetOptionsMenuPlayerCount (void)
- {
- short n = GetPlayerCount ();
-
- SetItemMark (optionsMenu, onePlayer, n == 1 ? checkMark : noMark);
- SetItemMark (optionsMenu, twoPlayer, n == 2 ? checkMark : noMark);
- SetItemMark (optionsMenu, threePlayer, n == 3 ? checkMark : noMark);
- SetItemMark (optionsMenu, fourPlayer, n == 4 ? checkMark : noMark);
- }
-
-
- static pascal void
- AdjustMenus (void)
- {
- WindowPeek wPeek;
-
- if ( (wPeek = (WindowPeek) FrontWindow ()) != nil
- && wPeek->windowKind < 0) /* DA window in front */
- {
- EnableItem (editMenu, editUndo);
- EnableItem (editMenu, editCut);
- EnableItem (editMenu, editCopy);
- EnableItem (editMenu, editPaste);
- EnableItem (editMenu, editClear);
- }
- else /* DA not in front */
- {
- DisableItem (editMenu, editUndo);
- DisableItem (editMenu, editCut);
- DisableItem (editMenu, editCopy);
- DisableItem (editMenu, editPaste);
- DisableItem (editMenu, editClear);
- }
- }
-
-
-
- /*
- * Initialize menus. \311 is the ellipsis character
- */
-
- static void
- SetupMenus (void)
- {
- long result;
- short enoughColors = 0;
- GDHandle gDevice;
-
- SkelApple ((StringPtr) "\pAbout Boxes\311", DoAppleMenu);
-
- if ((fileMenu = GetMenu (fileMenuNum)) == (MenuHandle) nil
- || !SkelMenu (fileMenu, DoFileMenu, nil, false, false))
- Bail ("\pProblem creating File menu.");
-
- if ((editMenu = GetMenu (editMenuNum)) == (MenuHandle) nil
- || !SkelMenu (editMenu, DoEditMenu, nil, false, false))
- Bail ("\pProblem creating Edit menu.");
-
- if ((optionsMenu = GetMenu (optionsMenuNum)) == (MenuHandle) nil
- || !SkelMenu (optionsMenu, DoOptionsMenu, nil, false, false))
- Bail ("\pProblem creating Options menu.");
-
- DrawMenuBar ();
-
- /* determine whether screen has at least 8 non-BW colors */
-
- if (SkelQuery (skelQHasColorQD))
- {
- if ((gDevice = GetMainDevice ()) != (GDHandle) NULL)
- {
- if ((**(**gDevice).gdPMap).pixelSize >= 4)
- enoughColors = 1;
- }
- }
- if (!enoughColors)
- {
- DisableItem (optionsMenu, colorSelect);
- /*
- (void) NoteAlert (depthAlrt, SkelDlogFilter (nil, true));
- SkelRmveDlogFilter ();
- */
- }
- SkelSetMenuHook (AdjustMenus);
- }
-
-
- int
- main (void)
- {
- /* Initialize TransSkel, create windows */
-
- SkelInit ((SkelInitParamsPtr) nil);
- SetMessageAlertNum (gnrlAlrt);
- SetupMenus ();
-
- WindInit ();
- InitColor ();
-
- /* Process events until user quits, then clean up and exit */
-
- SkelEventLoop ();
-
- Terminate ();
- }
-
-
- static void
- Terminate (void)
- {
- SkelCleanup ();
- ExitToShell ();
- }