home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d186 / cards'o'rama.lha / Cards'O'Rama / Sources / sources.zoo / event.c < prev    next >
C/C++ Source or Header  |  1989-02-25  |  5KB  |  167 lines

  1. /*                               event.c                                */
  2. /*                                                                      */
  3. /* Okay, this is handleevent(): If I call it with a pointer to an       */
  4. /* IntuiMessage structure, the events in which I have an interest get   */
  5. /* processed and the proper functions are called.                       */
  6. /* Please note that for a quick reply to an Intuition message, I will   */
  7. /* deal with a copy of the original IntuiMessage, so even if I don't    */
  8. /* respond to that message very quicly, Intuition won't eat away at my  */
  9. /* free memory (for more infos see the PROGRAMMER'S GUIDE TO THE AMIGA  */
  10. /* by Robert A. Peck, SYBEX 1987.)                                      */
  11.  
  12. handleevent(ms)
  13.    struct IntuiMessage *ms;
  14.    {
  15.    struct IntuiMessage localms;           /* Our private copy of ms */
  16.    int i, result;
  17.    UBYTE *s, *d;
  18.  
  19.    s = (UBYTE *)ms;                       /* Point to the original ms */
  20.    d = (UBYTE *)&localms;                 /* Point to destination */
  21.  
  22.    for (i = 0; i < sizeof(struct IntuiMessage); i++)
  23.       *d++ = *s++;
  24.  
  25.    ReplyMsg(ms);                          /* Reply to the original ms */
  26.  
  27.  
  28.  
  29. /* Okay, from now on I'll work only with this private copy of the       */
  30. /* original IntuiMessage...                                             */
  31.  
  32.  
  33.  
  34.    switch(localms.Class)
  35.       {
  36.       case MOUSEBUTTONS:
  37.          result = mousebuttons(&localms);
  38.          break;
  39.       case GADGETUP:
  40.          result =     gadgetup(&localms);
  41.          break;
  42.       case MENUPICK:
  43.          result =     menupick(&localms);
  44.          break;
  45.       default:
  46.          break;
  47.       }
  48.    return(result);
  49.    }
  50.  
  51. mousebuttons(ms)
  52.    struct IntuiMessage *ms;
  53.    {
  54.    extern int selectbutton;
  55.    extern int currentmousex;
  56.    extern int currentmousey;
  57.  
  58.    if (ms -> Code == SELECTDOWN)
  59.       {
  60.       selectbutton = TRUE;
  61.       currentmousex = ms -> MouseX;
  62.       currentmousey = ms -> MouseY;
  63.       return(DUMMY_VALUE);
  64.       }
  65.  
  66.    if (ms -> Code == SELECTUP)
  67.       {
  68.       selectbutton = FALSE;
  69.       return(DUMMY_VALUE);
  70.       }
  71.  
  72.    return(DUMMY_VALUE);
  73.    }
  74.  
  75.  
  76.  
  77. gadgetup(ms)
  78.    struct IntuiMessage *ms;
  79.    {
  80.    extern struct Window *w;
  81.    extern struct RastPort *rp;
  82.    extern int score1, score2;
  83.    extern int turn1, turn2;
  84.    extern int peek1, peek2;
  85.    extern int movingplayer;
  86.    extern int peektime;
  87.    extern int percentage;
  88.    extern int calling;
  89.  
  90.    struct Gadget *g;
  91.    int id;
  92.    int result;
  93.  
  94.    g = (struct Gadget *)(ms -> IAddress);
  95.    id = g -> GadgetID;
  96.  
  97.    switch(id)
  98.       {
  99.       case 1:
  100.          result = PICKED_NAAH;
  101.          break;
  102.       case 2:
  103.          result = PICKED_YEAH;
  104.          if(calling == 1)
  105.             {
  106.             percentage += 10;
  107.  
  108.             OffMenu(w, 0x3f00);        /* Menu 0: all */
  109.             OffMenu(w, 0x3f01);        /* Menu 1: all */
  110.             OffMenu(w, 0x3f02);        /* Menu 2: all */
  111.             OffMenu(w, 0x3f03);        /* Menu 3: all */
  112.  
  113.             writestring(rp, PICK_FIRST_STRING, FALSE);
  114.             displaycards(TRUE);              /* Display all cards */
  115.             writestring(rp, PEEK_STRING, COLOR3);
  116.             Delay(50 * peektime);            /* Wait... */
  117.             writestring(rp, PEEK_STRING, FALSE);
  118.             if (movingplayer == 1)
  119.                {
  120.                peek1 += 1;
  121.                score1 -= (score1 * 25 / 100);
  122.                update(FIRST, turn1, score1);
  123.                writestring(rp, PICK_FIRST_STRING, COLOR1);
  124.                }
  125.             else
  126.                {
  127.                peek2 += 1;
  128.                score2 -= (score2 * 25 / 100);
  129.                update(SECOND, turn2, score2);
  130.                writestring(rp, PICK_FIRST_STRING, COLOR2);
  131.                }
  132.  
  133.             OnMenu(w, 0x3f00);         /* Re-enable Menu 0 */
  134.             OnMenu(w, 0x3f01);         /* Re-enable Menu 1 */
  135.             OffMenu(w, 0x0001);        /* Except Item 0! */
  136.             OnMenu(w, 0x0021);         /* Now enable Menu 1: Item 1 */
  137.             OnMenu(w, 0x0041);         /* Now enable Menu 1: Item 2 */
  138.             displaycards(FALSE);       /* Cover all cards */
  139.             }
  140.          if(calling == 2)
  141.             {
  142.             SetRast(rp, 6);
  143.  
  144.             OnMenu(w, 0x0001);         /* Menu 1: Item 0 */
  145.             OnMenu(w, 0x3f02);         /* Menu 2: all */
  146.             OnMenu(w, 0x3f03);         /* Menu 3: all */
  147.  
  148.             OffMenu(w, 0x0021);        /* Disable Menu 1 - Item 1 */
  149.             OffMenu(w, 0x0041);        /* Disable Menu 1 - Item 2 */
  150.  
  151.             result = PICKED_QUIT;
  152.             }
  153.          if (calling == 3)
  154.             {
  155.             cleanup();
  156.             exit(0);
  157.             }
  158.          break;
  159.       case 3:
  160.          result = PICKED_CLICK;
  161.          break;
  162.       default:
  163.          break;
  164.       }
  165.    return(result);
  166.    }
  167.