home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 333.lha / Lotto / lotto.c < prev    next >
C/C++ Source or Header  |  1989-12-28  |  3KB  |  196 lines

  1. /*************************************/
  2. /*                                   */
  3. /* AUoH Progressive Door Prize Lotto */
  4. /*                                   */
  5. /*  Michael D. Groshart - 16 Aug 89  */
  6. /*                                   */
  7. /*************************************/
  8.  
  9. #include <intuition/intuition.h>
  10. #include <functions.h>
  11. #include <stdio.h>
  12.  
  13. #include "lotto.h"
  14.  
  15. struct IntuitionBase    *IntuitionBase;
  16. struct GfxBase        *GfxBase;
  17. struct Screen        *scr;
  18. struct ViewPort        *vp;
  19. struct Window        *win;
  20. struct RastPort        *rp;
  21. struct TmpRas        tr;
  22. PLANEPTR        plane;
  23.  
  24. unsigned long rand();
  25. void srand();
  26.  
  27. #define GetIMsg(p) ((struct IntuiMessage *) GetMsg(p))
  28.  
  29. #define ESC 0x1b
  30. #define SPC 0x20
  31. #define MAX 1000
  32.  
  33. #define ARRAYSIZE 400
  34.  
  35. struct user_data
  36. {
  37.     short user;
  38.     char *name;
  39. } array[ARRAYSIZE];
  40.  
  41. int nent = 0;
  42.  
  43. init_screen()
  44. {
  45.     long sec,mic;
  46.  
  47.     IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0L);
  48.     GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0L);
  49.  
  50.     if (!(scr = OpenScreen(&NewScreenStructure))) quit();
  51.  
  52.     NewWindowStructure1.Screen = scr;
  53.  
  54.     if (!(win = OpenWindow(&NewWindowStructure1))) quit();
  55.  
  56.     vp = &(scr->ViewPort);
  57.     rp = win->RPort;
  58.  
  59.     if (!(plane = AllocRaster(320L,200L))) quit();
  60.  
  61.     InitTmpRas(&tr,plane,RASSIZE(320,200));
  62.     rp->TmpRas = &tr;
  63.  
  64.     LoadRGB4(vp,&Palette,32L);
  65.     SetMenuStrip(win,&Menu1);
  66.  
  67.     CurrentTime(&sec,&mic);
  68.     srand(sec + mic);
  69. }
  70.  
  71. quit()
  72. {
  73.     exit_beep();
  74.     if (plane) FreeRaster(plane,320L,200L);
  75.     if (win)
  76.     {
  77.         ClearMenuStrip(win);
  78.         CloseWindow(win);
  79.     }
  80.     if (scr) CloseScreen(scr);
  81.  
  82.     CloseLibrary(GfxBase);
  83.     CloseLibrary(IntuitionBase);
  84.  
  85.     exit(0);
  86. }
  87.  
  88. pick()
  89. {
  90.     register struct IntuiMessage *im;
  91.     register int i,num;
  92.  
  93.     erase();
  94.  
  95.     while (!(im = GetIMsg(win->UserPort)))
  96.     {
  97.         for (i = 0; i < 21; i++)
  98.             flash();
  99.         beep((int)rand(7168L),3);
  100.     }
  101.     ReplyMsg(im);
  102.  
  103.     num = rand((long) nent);
  104.  
  105.     printf("%4d %s\n",array[num].user,array[num].name);
  106.  
  107.     display(array[num].user);
  108.     scroll(array[num].name);
  109. }
  110.  
  111. void *malloc();
  112.  
  113. char *strdup(s)
  114. char *s;
  115. {
  116.     register char *p;
  117.  
  118.     if (p = (char *) malloc(strlen(s) + 1))
  119.     {
  120.         strcpy(p, s);
  121.     }
  122.     return p;
  123. }
  124.  
  125. add(num,nam)
  126. char *num, *nam;
  127. {
  128.     register int i;
  129.  
  130.     if (nent < ARRAYSIZE)
  131.     {
  132.         if ((i = atoi(num)) < 400)
  133.         {
  134.             if (array[nent].name = strdup(nam))
  135.             {
  136.                 array[nent++].user = i;
  137.             }
  138.         }
  139.     }
  140. }
  141.  
  142. main(argc,argv)
  143. int argc;
  144. char *argv[];
  145. {
  146.     struct IntuiMessage *im;
  147.     USHORT code;
  148.     ULONG class;
  149.     char *datafile;
  150.  
  151.     if (argc == 1)
  152.         datafile = "members.sbf";
  153.     else
  154.         datafile = argv[1];
  155.  
  156.     if (*datafile == '?')
  157.     {
  158.         fprintf(stderr,"Usage: %s [members.sbf]\n",argv[0]);
  159.         exit(5);
  160.     }
  161.  
  162.     if (read_db(datafile,add) == 0)
  163.     {
  164.         fprintf(stderr,"Error: can't open %s\n",datafile);
  165.         exit(10);
  166.     }
  167.  
  168.     init_screen();
  169.     init_digits();
  170.     init_beep();
  171.     display(0);
  172.  
  173.     for (;;)
  174.     {
  175.         Wait(1L << win->UserPort->mp_SigBit);
  176.         while (im = GetIMsg(win->UserPort))
  177.         {
  178.             class = im->Class;
  179.             code = im->Code;
  180.             ReplyMsg(im);
  181.  
  182.             if (class == MENUPICK)
  183.             {
  184.                 if (ITEMNUM(code) == 0) quit();
  185.             }
  186.             else if (class == VANILLAKEY)
  187.             {
  188.                 if (code == SPC) pick();
  189.                 if (code == ESC) quit();
  190.             }
  191.         }
  192.     }
  193. }
  194.  
  195. _wb_parse() {}
  196.