home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / Rhapsody / Games / How-5.0-I / HowObject.m < prev    next >
Encoding:
Text File  |  1998-02-14  |  16.7 KB  |  509 lines

  1. #import "HowObject.h"
  2.  
  3. @implementation HowObject
  4.  
  5.     // Global Varibales
  6.     int TOTAL = 0;
  7.     int i; // dummy variable 
  8.     int X; // X screen coordinate
  9.     int Y; // Y screen coordinate
  10.  
  11.  
  12.         
  13.  
  14. - (void)applicationDidFinishLaunching:(NSNotification *)notification
  15. // In order for your object to receive this notification make sure that
  16. // your object is a delegate or "File's Owner" in IB.
  17. // Connected from "File's Owner" to HowObject in this case.
  18. {
  19.  
  20.     NSTimer *aTimer;
  21.  
  22.     // Activate the application
  23.     [NSApp activateIgnoringOtherApps:YES];
  24.  
  25.     // Displays the Info Panel
  26.     [InfoPanel center];
  27.     [InfoPanel makeKeyAndOrderFront:NULL];
  28.  
  29.  
  30.     // Registers a new timer with the NSRunLoop object
  31.     // DisplayTime is the amount of time the panel will be displayed
  32.     // CloseInfoPanel is the method executed when the timer "rings"
  33.     // userInfo:nil is NOT used at this time
  34.     aTimer = [NSTimer scheduledTimerWithTimeInterval:(10) target:self  selector:@selector(CloseInfoPanel:)  userInfo:nil  repeats:NO]; 
  35.  
  36.         // Selection Card
  37.         [Image1 setImage:[NSImage imageNamed:@"Image1"]];
  38.         [Image2 setImage:[NSImage imageNamed:@"Image2"]];
  39.         [Image3 setImage:[NSImage imageNamed:@"Image3"]];
  40.         [Image4 setImage:[NSImage imageNamed:@"Image4"]];
  41.         [Image5 setImage:[NSImage imageNamed:@"Image5"]];
  42.         [Image6 setImage:[NSImage imageNamed:@"Image6"]];
  43.         [Image7 setImage:[NSImage imageNamed:@"Image7"]];
  44.         [Image8 setImage:[NSImage imageNamed:@"Image8"]];
  45.         [Image9 setImage:[NSImage imageNamed:@"Image9"]];
  46.         [Image10 setImage:[NSImage imageNamed:@"Image10"]];
  47.         [Image11 setImage:[NSImage imageNamed:@"Image11"]];
  48.         [Image12 setImage:[NSImage imageNamed:@"Image12"]];
  49.         [Image13 setImage:[NSImage imageNamed:@"Image13"]];
  50.         [Image14 setImage:[NSImage imageNamed:@"Image14"]];
  51.         [Image15 setImage:[NSImage imageNamed:@"Image15"]];
  52.  
  53.         // Card One
  54.         [Image1_C1 setImage:[NSImage imageNamed:@"Image1"]];
  55.         [Image3_C1 setImage:[NSImage imageNamed:@"Image3"]];
  56.         [Image5_C1 setImage:[NSImage imageNamed:@"Image5"]];
  57.         [Image7_C1 setImage:[NSImage imageNamed:@"Image7"]];
  58.         [Image9_C1 setImage:[NSImage imageNamed:@"Image9"]];
  59.         [Image11_C1 setImage:[NSImage imageNamed:@"Image11"]];
  60.         [Image13_C1 setImage:[NSImage imageNamed:@"Image13"]];
  61.         [Image15_C1 setImage:[NSImage imageNamed:@"Image15"]];
  62.  
  63.         // Card Two
  64.         [Image15_C2 setImage:[NSImage imageNamed:@"Image15"]];
  65.         [Image2_C2 setImage:[NSImage imageNamed:@"Image2"]];
  66.         [Image14_C2 setImage:[NSImage imageNamed:@"Image14"]];
  67.         [Image6_C2 setImage:[NSImage imageNamed:@"Image6"]];
  68.         [Image7_C2 setImage:[NSImage imageNamed:@"Image7"]];
  69.         [Image10_C2 setImage:[NSImage imageNamed:@"Image10"]];
  70.         [Image11_C2 setImage:[NSImage imageNamed:@"Image11"]];
  71.         [Image3_C2 setImage:[NSImage imageNamed:@"Image3"]];
  72.  
  73.         // Card Three
  74.         [Image14_C3 setImage:[NSImage imageNamed:@"Image14"]];
  75.         [Image5_C3 setImage:[NSImage imageNamed:@"Image5"]];
  76.         [Image6_C3 setImage:[NSImage imageNamed:@"Image6"]];
  77.         [Image7_C3 setImage:[NSImage imageNamed:@"Image7"]];
  78.         [Image15_C3 setImage:[NSImage imageNamed:@"Image15"]];
  79.         [Image13_C3 setImage:[NSImage imageNamed:@"Image13"]];
  80.         [Image4_C3 setImage:[NSImage imageNamed:@"Image4"]];
  81.         [Image12_C3 setImage:[NSImage imageNamed:@"Image12"]];
  82.  
  83.         // Card Four
  84.         [Image10_C4 setImage:[NSImage imageNamed:@"Image10"]];
  85.         [Image9_C4 setImage:[NSImage imageNamed:@"Image9"]];
  86.         [Image8_C4 setImage:[NSImage imageNamed:@"Image8"]];
  87.         [Image15_C4 setImage:[NSImage imageNamed:@"Image15"]];
  88.         [Image12_C4 setImage:[NSImage imageNamed:@"Image12"]];
  89.         [Image14_C4 setImage:[NSImage imageNamed:@"Image14"]];
  90.         [Image13_C4 setImage:[NSImage imageNamed:@"Image13"]];
  91.         [Image11_C4 setImage:[NSImage imageNamed:@"Image11"]];
  92.  
  93.         // Displays the Selection Window
  94.         [Select center];
  95.         [Select makeKeyAndOrderFront:NULL];
  96.  
  97. }
  98.  
  99.  
  100.  
  101.  
  102. - (void)IntroAndHelp:(id)sender
  103. {
  104.     if (![NSBundle loadNibNamed:@"HelpIntro" owner:self])  {
  105.         NSLog(@"Failed to load HelpIntro.nib");
  106.         NSBeep();
  107.         return;
  108.         }
  109.  
  110. }
  111.  
  112. - (void)MoreInfo:(id)sender
  113. {
  114.     if (![NSBundle loadNibNamed:@"MoreInfo" owner:self])  {
  115.         NSLog(@"Failed to load MoreInfo.nib");
  116.         NSBeep();
  117.         return;
  118.         }
  119.  
  120. }
  121.  
  122.  
  123. - (void)Chosen:(id)sender
  124. // This is for the button is the Selection Window once the user has chosen a number
  125. // he will click on this button
  126. // Drop Select window at the bottom of the screen.
  127. {
  128.     // Local Variables
  129.         NSRect frame;
  130.         TOTAL = 0;
  131.  
  132.         frame = [Select frame]; // Gets current window coordinates (position)
  133.         X = NSMinX(frame); // Figures out the current X coordinates (Vertical)
  134.         Y = NSMinY(frame); // Figures out the current Y coordinates (Horizontal)
  135.  
  136.  
  137.     // Loops the window all the way down the screen out of sight
  138.         // The windows actual size is 432 so we drop it to -435 below 0 (end of screen)
  139.           for (i = Y; i > -435; i = i - 10) {
  140.             [Select setFrameOrigin:NSMakePoint((X), (i))];
  141.         }
  142.  
  143.           [Select close];  // Closes the window (Even if theres no close button on the window)
  144.           [Select center]; // Re-position the Window at the center of the screen
  145.  
  146.     // End of Drop for Selection Window
  147.  
  148.         [CardOne center]; // Repositions the Window at the center of the screen
  149.         [CardOne makeKeyAndOrderFront:NULL]; // Display CardOne window on the screen
  150. }
  151.  
  152. - (void)DropCardOne:(id)sender
  153. // "Drops" CardOne window to the left of the screen.
  154. {
  155.          
  156.         // Local Variables
  157.         NSRect frame;
  158.  
  159.         frame = [CardOne frame]; // Gets current window coordinates (position)
  160.         X = NSMinX(frame); // Figures out the current X coordinates (Vertical)
  161.         Y = NSMinY(frame); // Figures out the current Y coordinates (Horizontal)
  162.         
  163.           // Loops the window all the way left the screen out of sight
  164.           // The windows actual size is 354 so we drop it to -354 below 0 (edge of screen)
  165.           for (i = X; i > -354; i = i - 10) {
  166.               [CardOne setFrameOrigin:NSMakePoint((i), (Y))]; // Moves the window all the way to the left
  167.                                         }
  168.  
  169.  
  170.           [CardOne close];  // Closes the window (Even if theres no close button on the window)
  171.           [CardOne center]; // Repositions the Window at the center of the screen
  172.  
  173.           [CardTwo center]; // Repositions the Window at the center of the screen
  174.           [CardTwo makeKeyAndOrderFront:NULL]; // Display CardTwo window on the screen
  175.  
  176.          // End of Drop for CardOne Window
  177. }
  178.  
  179. - (void)DropCardTwo:(id)sender
  180. // Drop CardTwo window at the bottom of the screen.
  181. {
  182.  
  183.         // Local Variables
  184.     NSRect windowframe;
  185.         NSRect screenframe = [[NSScreen  mainScreen]  frame]; 
  186.         float height = screenframe.size.height; // Assigns the screen resolution to height
  187.  
  188.  
  189.         windowframe = [CardTwo frame]; // Gets current window coordinates (position)
  190.         X = NSMinX(windowframe);       // Figures out the current X coordinates (Vertical)
  191.         Y = NSMinY(windowframe);       // Figures out the current Y coordinates (Horizontal)
  192.  
  193.            for (i = Y; i > -435; i=i-10) {
  194.                 [CardTwo setFrameOrigin:NSMakePoint((X), (i))];}
  195.  // Moves the window down
  196.  
  197.  
  198.             Y = -435;  // Window is at buttom of screen
  199.  
  200.            // height is the mainScreen height (screen resolution)
  201.            for (i = Y; i < height; i=i+7) {
  202.                 [CardTwo setFrameOrigin:NSMakePoint((X), (i))];}
  203.  // Moves the window upwards
  204.  
  205.  
  206.             for (i = X; i > -440; i=i-5) {
  207.                 [CardTwo setFrameOrigin:NSMakePoint((i), (height))];}
  208.  // Moves window to the left
  209.            
  210.           [CardTwo close]; // Closes the window (Even if theres no close button on the window)
  211.           [CardTwo center]; // Repositions the Window at the center of the screen
  212.  
  213.           [CardThree center]; // Repositions the Window at the center of the screen
  214.           [CardThree makeKeyAndOrderFront:NULL]; // Display CardThree window on the screen
  215.  
  216.     // end of Drop CardTwo panel
  217.  
  218. }
  219.  
  220. - (void)DropCardThree:(id)sender
  221. // Drop CardThree window at the bottom of the screen.
  222. {
  223.  
  224.       // Local Variables
  225.       NSRect windowframe;
  226.       NSRect screenframe = [[NSScreen  mainScreen]  frame];
  227.       float width = screenframe.size.width; // Assigns the screen resolution to height
  228.  
  229.  
  230.       windowframe = [CardThree frame]; // Gets current window coordinates (position)
  231.       X = NSMinX(windowframe);         // Figures out the current X coordinates (Vertical)
  232.       Y = NSMinY(windowframe);         // Figures out the current Y coordinates (Horizontal)
  233.  
  234.           [CardThree makeKeyWindow]; // Selects the window
  235.           [CardThree orderFront:sender]; // Places the window in front
  236.  
  237.           for (i = X; i < width; i=i+20) {
  238.                 [CardThree setFrameOrigin:NSMakePoint((i), (Y))];} // Moves window to the right of the screen
  239.  
  240.  
  241.          [CardThree close];  // Closes the window (Even if theres no close button on the window)
  242.          [CardThree center]; // Repositions the Window at the center of the screen
  243.  
  244.     [CardFour center]; // Repositions the Window at the center of the screen
  245.     [CardFour makeKeyAndOrderFront:NULL]; // Display CardThree window on the screen
  246.  
  247.     // end of Drop CardThree panel
  248.  
  249. }
  250.  
  251.  
  252.  
  253. - (void)DropCardFour:(id)sender
  254. // Drop CardFour window at the bottom of the screen. 
  255. {
  256.  
  257.           // Local Variables
  258.           NSRect windowframe;
  259.  
  260.           windowframe = [CardFour frame]; // Gets current window coordinates (position)
  261.           X = NSMinX(windowframe);         // Figures out the current X coordinates (Vertical)
  262.           Y = NSMinY(windowframe);         // Figures out the current Y coordinates (Horizontal)
  263.  
  264.           for (i = Y; i > -435; i=i-5)
  265.           {
  266.  [CardFour setFrameOrigin:NSMakePoint((X), (i))];  // Moves window down
  267.              [CardFour setFrameOrigin:NSMakePoint((X=X-5), (i))]; }
  268.  // Moves window to the left
  269.           
  270.              [CardFour close];  // Closes the window (Even if theres no close button on the window)
  271.              [CardFour center]; // Repositions the Window at the center of the screen
  272.  
  273.              [Result center]; // Repositions the Window at the center of the screen
  274.              [Result makeKeyAndOrderFront:NULL]; // Display Result window on the screen
  275.  
  276.     // end of Drop CardFour panel
  277. }
  278.  
  279. - (void)FourNo:(id)sender
  280. // CardFour answer NO 
  281. {
  282.         [self DropCardFour:sender]; // Drop the card method
  283.         [self WhichImage:sender];
  284. }
  285.  
  286. - (void)FourYes:(id)sender
  287. // CardFour answer YES 
  288. {
  289.         [self DropCardFour:sender]; // Drop the card method
  290.         TOTAL=TOTAL + 8;
  291.         [self WhichImage:sender];
  292. }
  293.  
  294.  
  295. - (void)OneNo:(id)sender
  296. // CardOne answer NO
  297. {
  298.         [self DropCardOne:sender]; // Drop the card method
  299.         [CardTwo orderFront:sender];
  300. }
  301.  
  302. - (void)OneYes:(id)sender
  303. // CardOne answer YES
  304. {
  305.         [self DropCardOne:sender]; // Drop the card method
  306.         TOTAL=TOTAL + 1;
  307.         [CardTwo orderFront:sender];
  308. }
  309.  
  310. - (void)StartHow:(id)sender
  311. // This is used by the menu item How
  312. {
  313.     [Result close]; // Close the Result panel
  314.     [ResultImage setImage:[NSImage imageNamed:@"Empty.tiff"]]; // places an empty image to clean-up other images
  315.     [Select orderFront:sender]; // Selection panel "Let's start"
  316.     
  317. }
  318.  
  319. - (void)ThreeNo:(id)sender
  320. // CardOne answer NO
  321. {
  322.         [self DropCardThree:sender]; // Drop the card method
  323.         [CardFour orderFront:sender];
  324. }
  325.  
  326. - (void)ThreeYes:(id)sender
  327. // CardThree answer YES
  328. {
  329.         [self DropCardThree:sender]; // Drop the card method
  330.         TOTAL=TOTAL + 4;
  331.         [CardFour orderFront:sender];
  332. }
  333.  
  334. - (void)TwoNo:(id)sender
  335. // CardTwo answer NO
  336. {
  337.         [self DropCardTwo:sender]; // Drop the card method
  338.         [CardThree orderFront:sender];
  339. }
  340.  
  341. - (void)TwoYes:(id)sender
  342. // CardTwo answer YES
  343. {
  344.         [self DropCardTwo:sender]; // Drop the card method
  345.         TOTAL=TOTAL + 2;
  346.         [CardThree orderFront:sender];
  347. }
  348.  
  349. - (void)WhichImage:(id)sender
  350. // Assigns the number total with the proper image
  351. {
  352.       // Local Variables
  353.       NSRect windowframe;
  354.       NSRect screenframe = [[NSScreen  mainScreen]  frame];
  355.       float width = screenframe.size.width; // Assigns the screen resolution to width
  356.  
  357.       windowframe = [Result frame]; // Gets current window coordinates (position)
  358.       X = NSMinX(windowframe);         // Figures out the current X coordinates (Vertical)
  359.       Y = NSMinY(windowframe);         // Figures out the current Y coordinates (Horizontal)
  360.  
  361.        [ResultImage setImage:[NSImage imageNamed:@"Eric"]];
  362.        [ResultImage display];
  363.  
  364.       for (i = Y; i > 4; i=i-10) {
  365.             [Result setFrameOrigin:NSMakePoint((X), (i))];
  366. } // Moves the window down
  367.  
  368.        [ResultImage setImage:[NSImage imageNamed:@"Image5"]];
  369.        [ResultImage display];
  370.  
  371.       for (i = X; i > 5; i=i-10) {
  372.             [Result setFrameOrigin:NSMakePoint((i), (0))];}
  373.  // Move window to the left
  374.       
  375.     [self ResultAnimation:sender];
  376.     [self ResultAnimation:sender];
  377.     [self ResultAnimation:sender];
  378.  
  379.     for (i = 5; i < (width/2-137); i=i+10) {
  380.             [Result setFrameOrigin:NSMakePoint((i), (4))];} // Moves window to the right
  381.  
  382.       Y = 4; // Window is at buttom of screen
  383.       for (i = Y; i <430; i=i+10) {
  384.           [Result setFrameOrigin:NSMakePoint(((width/2-137)), (i))];}
  385. // Moves the window upwards
  386.  
  387.  
  388.    switch (TOTAL)  { // Start switch
  389.  
  390.    case 1:
  391.        [ResultImage setImage:[NSImage imageNamed:@"Image1"]];
  392.           break;
  393.  
  394.    case 2:
  395.        [ResultImage setImage:[NSImage imageNamed:@"Image2"]];
  396.           break;
  397.  
  398.    case 3:
  399.        [ResultImage setImage:[NSImage imageNamed:@"Image3"]];
  400.             break;
  401.  
  402.    case 4:
  403.        [ResultImage setImage:[NSImage imageNamed:@"Image4"]];
  404.             break;
  405.  
  406.    case 5:
  407.        [ResultImage setImage:[NSImage imageNamed:@"Image5"]];
  408.             break;
  409.  
  410.    case 6:
  411.        [ResultImage setImage:[NSImage imageNamed:@"Image6"]];
  412.             break;
  413.  
  414.    case 7:
  415.             [ResultImage setImage:[NSImage imageNamed:@"Image7"]];
  416.             break;
  417.  
  418.    case 8:
  419.        [ResultImage setImage:[NSImage imageNamed:@"Image8"]];
  420.             break;
  421.  
  422.    case 9:
  423.        [ResultImage setImage:[NSImage imageNamed:@"Image9"]];
  424.             break;
  425.  
  426.    case 10:
  427.        [ResultImage setImage:[NSImage imageNamed:@"Image10"]];
  428.             break;
  429.  
  430.    case 11:
  431.        [ResultImage setImage:[NSImage imageNamed:@"Image11"]];
  432.             break;
  433.  
  434.    case 12:
  435.        [ResultImage setImage:[NSImage imageNamed:@"Image12"]];
  436.             break;
  437.  
  438.    case 13:
  439.        [ResultImage setImage:[NSImage imageNamed:@"Image13"]];
  440.             break;
  441.  
  442.    case 14:
  443.        [ResultImage setImage:[NSImage imageNamed:@"Image14"]];
  444.             break;
  445.  
  446.    case 15:
  447.        [ResultImage setImage:[NSImage imageNamed:@"Image15"]];
  448.             break;
  449.  
  450.    default:
  451.        [ResultImage setImage:[NSImage imageNamed:@"Image16"]]; // if the user does not answer properly
  452.            break;
  453.  
  454.                                 } // end switch
  455.  
  456. }
  457.  
  458. - (void)ResultAnimation:(id)sender
  459. // This is the amimation for the Result panel
  460. {
  461.  
  462.     // Local Variables
  463.     NSRect windowframe;
  464.     NSRect screenframe = [[NSScreen  mainScreen]  frame];
  465.     float width = screenframe.size.width; // Assigns the screen resolution to width
  466.     float height = screenframe.size.height; // Assigns the screen resolution to height
  467.  
  468.  
  469.     windowframe = [Result frame]; // Gets current window coordinates (position)
  470.     X = NSMinX(windowframe);         // Figures out the current X coordinates (Vertical)
  471.     Y = NSMinY(windowframe);         // Figures out the current Y coordinates (Horizontal)
  472.  
  473.          [ResultImage setImage:[NSImage imageNamed:@"Image7"]];
  474.          [ResultImage display];
  475.  
  476.         Y = 4; // Window is at bottom of screen
  477.         for (i = Y; i < height; i=i+10) {
  478.             [Result setFrameOrigin:NSMakePoint((5), (i))];} 
  479. // Moves the window up
  480.  
  481.            [ResultImage setImage:[NSImage imageNamed:@"Image6"]];
  482.            [ResultImage display];
  483.      
  484.            for (i = 5; i < (width-275); i=i+10) {
  485.                [Result setFrameOrigin:NSMakePoint((i), (height))];} // Moves window to the right
  486.  
  487.            [ResultImage setImage:[NSImage imageNamed:@"Image9"]];
  488.            [ResultImage display];
  489.  
  490.         Y = height; // Window is at the top of the screen
  491.         for (i = Y; i > 4; i=i-10) {
  492.             [Result setFrameOrigin:NSMakePoint(((width-275)), (i))];
  493. } // Moves the window down
  494.  
  495.             [ResultImage setImage:[NSImage imageNamed:@"Image15"]];
  496.             [ResultImage display];
  497.  
  498.             for (i = (width-275); i > 5; i=i-10) {
  499.             [Result setFrameOrigin:NSMakePoint((i), (4))];}
  500.  // Moves the window to the left
  501.             [ResultImage setImage:[NSImage imageNamed:@"Image6"]];
  502.             [ResultImage display];
  503.  
  504. }
  505.  
  506.  
  507. - CloseInfoPanel:(id)timer
  508. {
  509.         // Closes the InfoPanel
  510.         [InfoPanel orderOut:self];
  511.  
  512.  
  513.     return self;
  514. }
  515.  
  516.  
  517.  
  518.  
  519.  
  520. @end
  521.