home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 138.lha / Cycle / manager.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  4KB  |  167 lines

  1. /* "manager.c" */
  2.  
  3. #include "cycles.h"
  4. #include <intuition/intuition.h>
  5.  
  6. #define PER_ROW   3 /* windows per row       */
  7. #define HEIGHT   50 /* height of each window */
  8.  
  9. #ifdef AZTEC_C
  10. extern long   Enable_Abort;
  11. #endif
  12. extern char player_name[];
  13.  
  14. static struct Window   *war_window;
  15. static struct RastPort *rp;
  16.  
  17. struct IntuitionBase   *IntuitionBase;
  18. struct GfxBase         *GfxBase;
  19.  
  20. struct Window          *OpenWindow();
  21. void                   *OpenLibrary();
  22.  
  23. long wins,losses;
  24. long colour;
  25.  
  26. char *colours[] = {"Red","Blue","White","Green","Yellow"};
  27.  
  28. main()
  29. {
  30.   long status;
  31. #ifdef AZTEC_C
  32.   Enable_Abort = 0;
  33. #endif
  34.   if (Register(&colour)) exit(0);
  35.  
  36.   if (strategy_init()) {
  37.     Retire();
  38.     exit(0);
  39.   }
  40.   if (g_init((colour % PER_ROW)*(640/PER_ROW),(colour/PER_ROW)*HEIGHT)) {
  41.     strategy_finish();
  42.     Retire();
  43.     exit(0);
  44.   }
  45.   g_show();
  46.   status = STATUS_NEED_NEW;
  47.  
  48.   for (;;) {
  49.     if (GetMsg(war_window->UserPort)) {
  50.       strategy_finish();
  51.       Retire();
  52.       g_finish();
  53.       exit(0);
  54.     }
  55.     switch (status) {
  56.       case STATUS_WINNER:
  57.         wins++;
  58.         g_show();
  59.         status = Await();
  60.         break;
  61.       case STATUS_LOSER:
  62.         losses++;
  63.         g_show();
  64.         status = Await();
  65.         break;
  66.       case STATUS_NEED_NEW:
  67.         status = strategy();
  68.         if (status < 0) {
  69.           strategy_finish();
  70.           Retire();
  71.           g_finish();
  72.           exit(0);
  73.         }
  74.         status = Direction(status);
  75.         break;
  76.       case STATUS_REMOVED:
  77.         WaitPort(war_window->UserPort);
  78.         GetMsg(war_window->UserPort);
  79.         strategy_finish();
  80.         Retire();
  81.         g_finish();
  82.         exit(0);
  83.     }
  84.   }
  85. }
  86. /* here we have all of the graphics rendering ode for the player...
  87.  */
  88.  
  89. static struct NewWindow newwindow = {
  90.   0L,0L,                             /* left edge, top edge            */
  91.   640L / PER_ROW - 2L, HEIGHT - 1L,  /* width, height                  */
  92.   0L,1L,                             /* detail pen, block pen          */
  93.   CLOSEWINDOW,                       /* IDCMP Flags                    */
  94.   WINDOWCLOSE                        /* flags                          */
  95.   | NOCAREREFRESH
  96.   | SMART_REFRESH
  97.   | WINDOWDRAG
  98.   | WINDOWDEPTH,
  99.   NULL,                              /* first gadget                   */
  100.   NULL,                              /* checkmark                      */
  101.   (UBYTE *)player_name,              /* title                          */
  102.   NULL,                              /* screen will be filled in later */
  103.   NULL,                              /* bitmap                         */
  104.   0L,0L,                             /* min width, height              */
  105.   -1L,-1L,                           /* max width, height              */
  106.   WBENCHSCREEN                       /* type                           */
  107. };
  108.  
  109. g_init(x,y)
  110. {
  111.   IntuitionBase = OpenLibrary("intuition.library",0L);
  112.   if (!IntuitionBase) {
  113.     g_finish();
  114.     printf("unable to open intuition\n");
  115.     return(1);
  116.   }
  117.   GfxBase = OpenLibrary("graphics.library",0L);
  118.   if (!GfxBase) {
  119.     g_finish();
  120.     printf("unable to open graphics library\n");
  121.     return(1);
  122.   }
  123.   newwindow.LeftEdge = x;
  124.   newwindow.TopEdge = y + 20L;
  125.   war_window = OpenWindow(&newwindow);
  126.   if (!war_window) {
  127.     g_finish();
  128.     printf("unable to open window\n");
  129.     return(1);
  130.   }
  131.   rp = war_window->RPort;
  132.   SetBPen(rp,0);
  133.   SetAPen(rp, 1);
  134.   SetDrMd(rp,JAM2);
  135.   return(0);
  136. }
  137.  
  138. g_finish()
  139. {
  140.   if (war_window)    CloseWindow(war_window);
  141.   if (GfxBase)       CloseLibrary(GfxBase);
  142.   if (IntuitionBase) CloseLibrary(IntuitionBase);
  143. }
  144.  
  145. g_show()
  146. {
  147.   char buf[40];
  148.   long y = 8;
  149.   long x = 8;
  150.  
  151.   Move(rp,x,y +=9);
  152.   sprintf(buf,"%s player",colours[colour]);
  153.   Text(rp,buf,strlen(buf));
  154.  
  155.   Move(rp,x,y += 9);
  156.   sprintf(buf,"  Wins: %d",wins);
  157.   Text(rp,buf,strlen(buf));
  158.  
  159.   Move(rp,x,y += 9);
  160.   sprintf(buf,"  Losses: %d",losses);
  161.   Text(rp,buf,strlen(buf));
  162.  
  163.   Move(rp,x,y += 9);
  164.   sprintf(buf,"  Games: %d",wins + losses);
  165.   Text(rp,buf,strlen(buf));
  166. }
  167.