home *** CD-ROM | disk | FTP | other *** search
/ YPA: Your Privacy Assured / YPA.ISO / other_goodies / games / fiveinline.lha / FiveInLine / Source / mouse.c < prev    next >
C/C++ Source or Header  |  1994-04-22  |  4KB  |  140 lines

  1. #include <intuition/intuition.h>
  2. #include <proto/intuition.h>
  3.  
  4. #include <graphics/gfxmacros.h>
  5. #include <proto/graphics.h>
  6.  
  7. #include <libraries/gadtools.h>
  8. #include <proto/gadtools.h>
  9.  
  10. #include "fil.h"
  11.  
  12. extern APTR        VisualInfo;
  13. extern struct     Gadget    *mwGadgets [ 3 ];
  14. extern struct     Screen    *Scr;
  15. extern struct     Window    *mwWnd;
  16. extern int        boardsize;
  17. extern UBYTE     Board [ MAXBOARDSIZE + 1 ] [ MAXBOARDSIZE + 1 ];
  18. extern BOOL     gamewon;
  19. extern UBYTE    currentplayer;
  20. extern UWORD     offx;
  21. extern UWORD    offy;
  22.  
  23. void draw_x ( int row, int col)
  24. {
  25.     int     x = offx + INTERWIDTH + ( col - 1 ) * BOXSIZE + 2;
  26.     int     y = offy + INTERHEIGHT + ( row - 1 ) * BOXSIZE + 3;
  27.     int     x1 = x + BOXSIZE - 6;
  28.     int     y1 = y + BOXSIZE - 6;
  29.     
  30.     SetAPen ( mwWnd->RPort, 1);
  31.     Move ( mwWnd->RPort, x, y );
  32.     Draw ( mwWnd->RPort, x1, y1 );
  33.  
  34.     Move ( mwWnd->RPort, x1, y );
  35.     Draw ( mwWnd->RPort, x, y1 );
  36. }
  37.  
  38. void draw_o ( int row, int col)
  39. {
  40.     int     x1 = offx + INTERWIDTH + ( col - 1 ) * BOXSIZE + BOXSIZE / 2;
  41.     int     y1 = offy + INTERHEIGHT + ( row - 1 ) * BOXSIZE + BOXSIZE / 2;
  42.  
  43.     SetAPen ( mwWnd->RPort, 2);
  44.     DrawCircle ( mwWnd->RPort, x1, y1, BOXSIZE / 2 - 3 );
  45. }
  46.  
  47. int handlemousebuttons ( struct IntuiMessage *msg , int *amiga_old_row, int amiga_old_col )
  48. {
  49.     static     int     old_row = -1;
  50.     static     int     old_col;
  51.     static  LONG     humanscore = 0;
  52.             int     row;
  53.             int        col;
  54.             BOOL    running = TRUE;
  55.             BOOL     gamewon = FALSE;
  56.  
  57.     if ( msg->MouseY > ( offy + INTERHEIGHT ) )
  58.         row = ( msg->MouseY - offy - INTERHEIGHT ) / BOXSIZE + 1;
  59.     else row = 0;
  60.  
  61.     if ( msg->MouseX > ( offx + INTERWIDTH ) ) 
  62.         col = ( msg->MouseX - offx - INTERWIDTH ) / BOXSIZE + 1;
  63.     else col = 0;
  64.     
  65.     switch ( msg->Code )
  66.     {
  67.         case SELECTDOWN:
  68.             if ( *amiga_old_row != -1 ) {
  69.                 DrawBevelBox ( mwWnd->RPort, offx + INTERWIDTH + ( amiga_old_col - 1 ) * BOXSIZE,
  70.                     offy + INTERHEIGHT + ( *amiga_old_row - 1 ) * BOXSIZE, BOXSIZE, BOXSIZE, 
  71.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  72.                 *amiga_old_row = -1;
  73.             }
  74.             if ( row >= 1 && row <= boardsize && col >= 1 && col <= boardsize ) {
  75.                 if ( Board [ row ] [ col ] == EMPTY ) {
  76.                     DrawBevelBox ( mwWnd->RPort, offx + INTERWIDTH + ( col - 1 ) * BOXSIZE,
  77.                         offy + INTERHEIGHT + ( row - 1 ) * BOXSIZE, BOXSIZE, BOXSIZE, 
  78.                         GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  79.                     old_row = row;
  80.                     old_col = col;
  81.                 }
  82.                 else old_row = -1;
  83.             }
  84.             break;
  85.         case SELECTUP:
  86.             if ( old_row != -1 ) {
  87.                 DrawBevelBox ( mwWnd->RPort, offx + INTERWIDTH + ( old_col - 1 ) * BOXSIZE,
  88.                     offy + INTERHEIGHT + ( old_row - 1 ) * BOXSIZE, BOXSIZE, BOXSIZE, 
  89.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  90.                 if ( row == old_row && col == old_col) {
  91.                     makemove ( row, col , &gamewon );
  92.                     draw_x ( row, col );
  93.                     if ( gamewon ) {
  94.                         showresult ( "You won!" );
  95.                         humanscore ++;
  96.                         GT_SetGadgetAttrs ( mwGadgets [ GD_HUMAN ], mwWnd, NULL,
  97.                             GTNM_Number, humanscore,
  98.                             TAG_END );
  99.                         running = FALSE;
  100.                     }
  101.                     Board [ row ] [ col ] = HUMAN;
  102.                     currentplayer = AMIGA;
  103.                 }
  104.             }
  105.             break;
  106.     }
  107.  
  108.     return ( running );
  109. }
  110.  
  111. int amigamove ( int *old_row, int *old_col, FLOAT playlevel )
  112. {
  113.     static  LONG    amigascore = 0;
  114.             int     row;
  115.             int     col;
  116.             BOOL    running = TRUE;
  117.             BOOL     gamewon = FALSE;
  118.  
  119.     findmove ( &row, &col, playlevel );
  120.     makemove ( row, col , &gamewon );
  121.     DrawBevelBox ( mwWnd->RPort, offx + INTERWIDTH + ( col - 1 ) * BOXSIZE,
  122.         offy + INTERHEIGHT + ( row - 1 ) * BOXSIZE, BOXSIZE, BOXSIZE, 
  123.         GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  124.     *old_row = row;
  125.     *old_col = col;
  126.     draw_o ( row, col );
  127.     if ( gamewon ) {
  128.         showresult ( "I won.");
  129.         amigascore ++;
  130.         GT_SetGadgetAttrs ( mwGadgets [ GD_AMIGA ], mwWnd, NULL,
  131.             GTNM_Number, amigascore,
  132.             TAG_END );
  133.         running = FALSE;
  134.     }
  135.     Board [ row ] [ col ] = AMIGA;
  136.     currentplayer = HUMAN;
  137.  
  138.     return ( running );
  139. }
  140.