home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Examples / AppKit / BreakApp / BreakApp.m < prev    next >
Encoding:
Text File  |  1992-03-15  |  2.6 KB  |  100 lines

  1. /*
  2.  * BreakApp.m, subclass of Application for BreakApp.
  3.  * Author: Ali Ozer
  4.  * Written for 1.0 July 89.
  5.  * Modified for 2.0 Sept 90; separated the panels into their own .nib files.
  6.  * Modified for 3.0 March 92
  7.  *
  8.  * This class manages the windows & such for the BreakApp application.
  9.  *
  10.  *  You may freely copy, distribute and reuse the code in this example.
  11.  *  NeXT disclaims any warranty of any kind, expressed or implied,
  12.  *  as to its fitness for any particular use.
  13.  */
  14.  
  15. #import <appkit/appkit.h>
  16. #import <libc.h>
  17.  
  18. #import "BreakApp.h"
  19. #import "BreakView.h"
  20.  
  21.  
  22. @implementation BreakApp
  23.  
  24. + new
  25. {
  26.     self = [super new];
  27.     [self setDelegate:self];    // For appDidHide:
  28.     return self;
  29. }
  30.    
  31. // appDidInit is called as the first thing in the run loop of the 
  32. // application. At this point, everything is created, but we haven't entered
  33. // the event loop yet. appDidInit: initializes a few things and
  34. // calls the gotoFirstLevel: method of the BreakView instance to get
  35. // started on a new game.
  36.  
  37. - appDidInit:app 
  38. {
  39.     [game gotoFirstLevel:self];
  40.     [controlWindow removeFromEventMask:NX_KEYDOWNMASK|NX_KEYUPMASK];
  41.     [controlWindow orderFront:self];
  42.     [gameWindow setDelegate:self];    // For windowDidMiniaturize:
  43.     [gameWindow makeKeyAndOrderFront:self];
  44.     return self;
  45. }
  46.  
  47. // appDidHide is called when the application is hidden. It doesn't
  48. // make sense to run the game while the application is running, also,
  49. // in case the boss walks by you want to be able to hit just Command-h and
  50. // have the game hide and pause at the same time. This way the boss won't
  51. // ask where "ping-ping" noises are coming from and you will not have lost
  52. // a high-score game.
  53.  
  54. - appDidHide:app
  55. {
  56.    [game stop:self];
  57.    return self;
  58. }
  59.  
  60. // We do pretty much the same if the user miniaturizes the game window.
  61.  
  62. - windowDidMiniaturize:window
  63. {
  64.    if (window == gameWindow) [game stop:self];
  65.    return self;
  66. }
  67.  
  68. // printGame: allows us to print the game window. We could've just connected
  69. // t@Print..." menu item to the window's smartPrintPSCode:; however, we
  70. // wanted to be able to change the title to reflect the status.
  71.  
  72. - printGame:sender
  73. {
  74.     char *savedTitle = NXCopyStringBuffer([gameWindow title]);
  75.     char statusString[100];
  76.  
  77.     sprintf (statusString, "Score: %d  Level: %d", [game score], [game level]);
  78.     [gameWindow setTitle:statusString];
  79.     [gameWindow smartPrintPSCode:sender];
  80.     [gameWindow setTitle:savedTitle];
  81.     free (savedTitle);
  82.  
  83.     return self;
  84. }
  85.  
  86.  
  87. // Method to load the .nib file for the info panel.
  88.  
  89. - showInfo:sender
  90. {
  91.     if (!infoPanel) {
  92.     [self loadNibSection:"Info.nib" owner:self withNames:NO];
  93.     }
  94.     [infoPanel makeKeyAndOrderFront:sender];
  95.     return self;
  96. }
  97.  
  98.  
  99. @end
  100.