home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / wbgames / shuffle / source / shuffle_temp.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  20KB  |  659 lines

  1.  
  2. #include "shuffle.h"
  3.  
  4. struct EasyStruct ExitReq =
  5.        {
  6.         0L,0L,(UBYTE *)"Quit the Game ?",
  7.               (UBYTE *)"Really quit ?",
  8.               (UBYTE *)"Yes (L-AMIGA+V) | No (L-AMIGA + B)",
  9.        };
  10.  
  11. struct EasyStruct AboutReq =
  12.        {
  13.         0L,0L,(UBYTE *)"About Shuffle",
  14.               (UBYTE *)"Shuffle V1.1 is Copyright (©) 1993 CEKASOFT\nKarlheinz Klingbeil\nElzstr. 42\n7809 Gutach\nGERMANY\n\n    *ENJOY*",
  15.               (UBYTE *)"stupid|silly|incredible",
  16.        };
  17.  
  18. WORD bp1[] =
  19.       {
  20.        0,0,0,0,0,0
  21.       };
  22.  
  23. WORD bp2[] =
  24.       {
  25.        0,0,0,0,0,0
  26.       };
  27.  
  28. struct Border b2 =
  29.        {
  30.          0,0,1,0,JAM1,3,bp2,       
  31.        };
  32.  
  33. struct Border b1 =
  34.        {
  35.         0,0,2,0,JAM1,3,bp1,&b2       
  36.        };
  37.         
  38. struct Border b2r =
  39.        {
  40.          0,0,2,0,JAM1,3,bp2,       
  41.        };
  42.  
  43. struct Border b1r =
  44.        {
  45.         0,0,1,0,JAM1,3,bp1,&b2       
  46.        };
  47.  
  48. struct TextAttr topaz8 = {
  49.     ( STRPTR )"topaz.font", 8, 0x00, 0x01 };
  50.  
  51. UBYTE  number[8];
  52.  
  53. struct IntuiText ntext =
  54.        {
  55.         1,2,JAM2,0,0,&topaz8,number,NULL
  56.        };
  57.  
  58. struct IntuiText anykey = {1,2,JAM2,4,100,&topaz8,"--- Any key to continue ---",NULL};
  59.  
  60. struct IntuiText intro4 = {1,2,JAM2,0,50,&topaz8,"Press h for Help, Q to Quit ",&anykey};
  61. struct IntuiText intro3 = {1,2,JAM2,0,40,&topaz8,"to their proper places !",&intro4};
  62. struct IntuiText intro2 = {1,2,JAM2,0,30,&topaz8,"by moving the tiles around",&intro3};    
  63. struct IntuiText intro1 = {1,2,JAM2,0,20,&topaz8,"Try  to clean up this mess",&intro2};
  64.  
  65. struct IntuiText h5 = {1,2,JAM2,0,60,&topaz8,"A for About shuffle...",&anykey};
  66. struct IntuiText h4 = {1,2,JAM2,0,50,&topaz8,"S for Score Display",&h5};
  67. struct IntuiText h3 = {1,2,JAM2,0,40,&topaz8,"q or ESC Key to Quit",&h4};
  68. struct IntuiText h2 = {1,2,JAM2,0,30,&topaz8,"H or Help Key for Help",&h3};    
  69. struct IntuiText h1 = {1,2,JAM2,0,20,&topaz8,"Move Tiles with cursor keys",&h2};
  70.  
  71. struct IntuiText s2 = {1,2,JAM2,0,50,&topaz8,"       Moves so far",&anykey};    
  72. struct IntuiText s1 = {1,2,JAM2,0,30,&topaz8,"       You have done",&ntext};
  73.  
  74. struct IntuiText end4 = {1,2,JAM2,0,50,&topaz8,"          Moves",&anykey};
  75. struct IntuiText end3 = {1,2,JAM2,0,30,&topaz8,"          with ",&ntext};
  76. struct IntuiText end2 = {1,2,JAM2,0,20,&topaz8,"You  have solved the problem",&end3};    
  77. struct IntuiText end1 = {1,2,JAM2,0,10,&topaz8,"      Congratulations !",&end2};
  78.  
  79. struct IntuiText a9 = {1,2,JAM2,0,90,&topaz8," * ENJOY * ENJOY * ENJOY *",&anykey};
  80. struct IntuiText a8 = {1,2,JAM2,0,80,&topaz8,"    All Rights Reserved",&a9};
  81. struct IntuiText a7 = {1,2,JAM2,0,70,&topaz8,"      Copyright © 1993",&a8};
  82. struct IntuiText a6 = {1,2,JAM2,0,60,&topaz8,"          GERMANY",&a7};    
  83. struct IntuiText a5 = {1,2,JAM2,0,50,&topaz8,"        7809 Gutach",&a6};
  84. struct IntuiText a4 = {1,2,JAM2,0,40,&topaz8,"        Elzstr. 42",&a5};
  85. struct IntuiText a3 = {1,2,JAM2,0,30,&topaz8,"    Karlheinz Klingbeil",&a4};
  86. struct IntuiText a2 = {1,2,JAM2,0,20,&topaz8,"    to you by CEKASOFT",&a3};    
  87. struct IntuiText a1 = {1,2,JAM2,0,10,&topaz8,"This weird Game is brought",&a2};
  88.  
  89.  
  90.     
  91. int startClicked( void )
  92. {
  93.     /* routine when gadget "Start" is clicked. */
  94.  GT_SetGadgetAttrs(Project0Gadgets[GDX_start],Project0Wnd,NULL,
  95.                    GA_Disabled,TRUE,TAG_DONE);
  96.  GT_SetGadgetAttrs(Project0Gadgets[GDX_tiles],Project0Wnd,NULL,
  97.                    GA_Disabled,TRUE,TAG_DONE);
  98.  GT_SetGadgetAttrs(Project0Gadgets[GDX_shuffle],Project0Wnd,NULL,
  99.                    GA_Disabled,TRUE,TAG_DONE);
  100.  GT_SetGadgetAttrs(Project0Gadgets[GDX_numbers],Project0Wnd,NULL,
  101.                    GA_Disabled,TRUE,TAG_DONE);
  102.  GT_SetGadgetAttrs(Project0Gadgets[GDX_mode],Project0Wnd,NULL,
  103.                    GA_Disabled,TRUE,TAG_DONE);
  104.  SetMenuStrip( Project0Wnd,NULL); 
  105.  ModifyIDCMP(Project0Wnd,IDCMP_REFRESHWINDOW);
  106.  Play();
  107.  SetMenuStrip( Project0Wnd, Project0Menus );
  108.  ModifyIDCMP(Project0Wnd,IDCMP_VANILLAKEY|IDCMP_MENUPICK | BUTTONIDCMP|CYCLEIDCMP|CHECKBOXIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW);
  109.  GT_SetGadgetAttrs(Project0Gadgets[GDX_start],Project0Wnd,NULL,
  110.                    GA_Disabled,FALSE,TAG_DONE);
  111.  GT_SetGadgetAttrs(Project0Gadgets[GDX_tiles],Project0Wnd,NULL,
  112.                    GA_Disabled,FALSE,TAG_DONE);
  113.  GT_SetGadgetAttrs(Project0Gadgets[GDX_shuffle],Project0Wnd,NULL,
  114.                    GA_Disabled,FALSE,TAG_DONE);
  115.  GT_SetGadgetAttrs(Project0Gadgets[GDX_numbers],Project0Wnd,NULL,
  116.                    GA_Disabled,FALSE,TAG_DONE);
  117.  GT_SetGadgetAttrs(Project0Gadgets[GDX_mode],Project0Wnd,NULL,
  118.                    GA_Disabled,FALSE,TAG_DONE); 
  119.  
  120.  return (TRUE);
  121. }
  122.  
  123. int tilesClicked( void )
  124. {
  125.     /* routine when gadget "Tiles" is clicked. */
  126.  info.res = Project0Msg.Code;
  127.  return (TRUE);
  128. }
  129.  
  130. int shuffleClicked( void )
  131. {
  132.     /* routine when gadget "Shuffle" is clicked. */
  133.  info.shuffle = atol(shuffle0Labels[Project0Msg.Code]); 
  134.  info.m_shuffles = Project0Msg.Code;
  135.  return (TRUE);
  136. }
  137.  
  138. int numbersClicked( void )
  139. {
  140.     /* routine when gadget "Numbers" is clicked. */
  141.  info.numbers = (info.numbers) ? FALSE : TRUE;
  142.  GT_SetGadgetAttrs(Project0Gadgets[GDX_numbers],Project0Wnd,NULL,
  143.                    GTCB_Checked,info.numbers,TAG_DONE);
  144.  
  145.  return (TRUE);
  146. }
  147.  
  148. int modeClicked( void )
  149. {
  150.     /* routine when gadget "Mode" is clicked. */
  151.  info.mode = (info.mode == MODE_TILES) ? MODE_GAP : MODE_TILES;
  152.  GT_SetGadgetAttrs(Project0Gadgets[GDX_mode],Project0Wnd,NULL,
  153.                    GTCY_Active,info.mode,TAG_DONE);
  154.  return  (TRUE);
  155. }
  156.  
  157. int Project0loadconfig( void )
  158. {
  159.     /* routine when (sub)item "Load configuration" is selected. */ 
  160.  load_config(NULL);
  161.  return (TRUE);
  162. }
  163.  
  164. int Project0saveasconfig( void )
  165. {
  166.     /* routine when (sub)item "Save configuration" is selected. */
  167.  save_config(SAVE_AS);
  168.  return (TRUE);
  169. }
  170.  
  171. int Project0saveconfig( void )
  172. {
  173.     /* routine when (sub)item "Save configuration" is selected. */
  174.  save_config(SAVE_NAME);
  175.  return (TRUE);
  176. }
  177.  
  178. int Project0savedefault( void )
  179. {
  180.     /* routine when (sub)item "Save as default" is selected. */
  181.  save_config(SAVE_DEF_ENVARC);
  182.  save_config(SAVE_DEF_ENV);
  183.  return (TRUE);
  184. }
  185.  
  186. int Project0about( void )
  187. {
  188.     /* routine when (sub)item "About..." is selected. */
  189.  EasyRequestArgs(info.wd,&AboutReq,NULL,NULL);
  190.  return(TRUE);
  191. }
  192.  
  193. int Project0quit( void )
  194. {
  195.     /* routine when (sub)item "Quit" is selected. */
  196.  return (Project0CloseWindow());;
  197. }
  198.  
  199. int Project0Icon()
  200. {
  201.  info.writeicon = (info.writeicon) ? FALSE : TRUE;
  202.  return (TRUE);
  203. }
  204.  
  205. int Project0CloseWindow( void )
  206. {
  207.     /* routine for "IDCMP_CLOSEWINDOW". */
  208.  return(EasyRequestArgs(info.wd,&ExitReq,NULL,NULL) == 1) ? FALSE : TRUE;
  209. }
  210.  
  211. int  MakeScWd(void)
  212. {
  213.  if(info.sc = CloneScreen(Scr))
  214.  {
  215.   info.oldcmap = info.sc->ViewPort.ColorMap;
  216.   info.sc->ViewPort.ColorMap = Scr->ViewPort.ColorMap;
  217.   if(info.wd = MakeWd(info.sc))
  218.   {
  219.    CopyWBGfx();
  220.    return (TRUE);
  221.   }
  222.  }
  223.  return (FALSE);
  224. }
  225.  
  226. void  FreeScWd(void)
  227. {
  228.  if(info.wd)
  229.  {
  230.   CloseWindow(info.wd);
  231.   info.wd = NULL;
  232.  }
  233.  if(info.sc)
  234.  {
  235.   if(info.oldcmap)info.sc->ViewPort.ColorMap = info.oldcmap;
  236.  
  237.   CloseScreen(info.sc);
  238.   info.sc = NULL;
  239.  }
  240. }
  241.  
  242. struct Screen *  CloneScreen(struct Screen *wb)
  243. {
  244.  struct DimensionInfo dinfo;
  245.  ULONG  mode_id;
  246.  mode_id = GetVPModeID(&(wb->ViewPort));
  247.  (void)GetDisplayInfoData(NULL,(APTR)&dinfo,sizeof(dinfo),DTAG_DIMS,mode_id); 
  248.  return OpenScreenTags(NULL,
  249.         SA_Width ,wb->Width,
  250.         SA_Height,wb->Height,
  251.         SA_Depth,info.dri->dri_Depth,
  252.         SA_Pens ,info.dri->dri_Pens,
  253.         SA_DisplayID,mode_id,
  254.         SA_FullPalette,TRUE,
  255.         SA_Behind,TRUE,
  256.         SA_DClip,&dinfo.TxtOScan,
  257.         SA_AutoScroll,TRUE,
  258.         TAG_DONE
  259.                       );
  260. }
  261.  
  262. struct Window  *MakeWd(struct Screen *screen)
  263. {
  264.  return OpenWindowTags(NULL,
  265.         WA_IDCMP,IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_MOUSEBUTTONS,
  266.                     WA_Flags,WFLG_ACTIVATE|WFLG_BORDERLESS|WFLG_RMBTRAP|WFLG_SMART_REFRESH,
  267.            WA_CustomScreen,screen,
  268.         TAG_DONE
  269.         );
  270. }
  271.  
  272. void Play(void)
  273. {
  274.  int  end = FALSE;
  275.  ULONG sigs,sigrcvd;
  276.  struct IntuiMessage *msg;
  277.  ULONG  class;
  278.  USHORT code;
  279.  WORD   mx,my;
  280.  SetBPen(info.wd->RPort,1);
  281.  if(MakeScWd())
  282.  {
  283.   SetUpValues();
  284.   sigs = (1L<<Project0Wnd->UserPort->mp_SigBit) | 
  285.          (1L<<info.wd->UserPort->mp_SigBit);
  286.   DisplayReq(&intro1);
  287.   while(!end)
  288.   {
  289.    sigrcvd = Wait(sigs);
  290.    if(sigrcvd & (1L<<Project0Wnd->UserPort->mp_SigBit))end = TRUE;
  291.    if(sigrcvd & (1L<<info.wd->UserPort->mp_SigBit))
  292.    {
  293.     while(msg = (struct IntuiMessage *)GetMsg(info.wd->UserPort))
  294.     {
  295.      class = msg->Class;
  296.      code  = msg->Code;
  297.      mx    = msg->MouseX;
  298.      my    = msg->MouseY; 
  299.      ReplyMsg((struct Message *)msg);
  300.      switch(class)
  301.      {
  302.       case IDCMP_VANILLAKEY   :
  303.            switch(code)
  304.            {
  305.             case 'a'    :
  306.             case 'A'    : DisplayReq(&a1); 
  307.                           break;
  308.             case 'h'    :
  309.             case 'H'    : DisplayReq(&h1);
  310.                           break;
  311.             case 's'    :
  312.             case 'S'    : ntext.TopEdge  = 40;
  313.                           ntext.LeftEdge = 40;
  314.                           ntext.NextText = &s2;
  315.                           sprintf(number,"%3ld",info.moves);
  316.                           DisplayReq(&s1);
  317.                           break;
  318.             case 0x1b   :
  319.             case 'Q'    :
  320.             case 'q'    : if( EasyRequestArgs(info.wd,&ExitReq,NULL,NULL) == 1)
  321.                           end = TRUE;
  322.                           break;
  323.             default     : break;
  324.            }
  325.            break;
  326.       case IDCMP_RAWKEY :
  327.            switch(code)
  328.            {
  329.             case 0x5f   : DisplayReq(&h1);
  330.                           break;
  331.             case 0x45   : end = TRUE;
  332.                           break;
  333.             case 0x4c   : if(info.mode == MODE_GAP)
  334.                            MoveRect(DIR_UP);
  335.                           else
  336.                            MoveRect(DIR_DOWN);
  337.                           break;
  338.             case 0x4d   : if(info.mode == MODE_GAP)
  339.                            MoveRect(DIR_DOWN);
  340.                           else
  341.                            MoveRect(DIR_UP);
  342.                           break;
  343.             case 0x4f   : if(info.mode == MODE_GAP)
  344.                            MoveRect(DIR_LEFT);
  345.                           else
  346.                            MoveRect(DIR_RIGHT);
  347.                           break;
  348.             case 0x4e   : if(info.mode == MODE_GAP)
  349.                            MoveRect(DIR_RIGHT);
  350.                           else
  351.                            MoveRect(DIR_LEFT);
  352.                           break;
  353.             default     : break;
  354.            }
  355.         break;
  356.       case IDCMP_MOUSEBUTTONS :
  357.            if((mx < info.x_pos[info.cx]) && (mx > info.x_pos[info.cx - 1]))
  358.            {
  359.             if((my > info.y_pos[info.cy]) && (my <  info.y_pos[info.cy + 1]))
  360.             {
  361.               MoveRect(DIR_LEFT);
  362.             }
  363.            }  
  364.            if((mx > info.x_pos[info.cx + 1]) && (mx < info.x_pos[info.cx + 2]))
  365.            {
  366.             if((my > info.y_pos[info.cy]) && (my <  info.y_pos[info.cy + 1]))
  367.             {
  368.               MoveRect(DIR_RIGHT);
  369.             }
  370.            } 
  371.            if((mx > info.x_pos[info.cx]) && (mx < info.x_pos[info.cx + 1]))
  372.            {
  373.             if((my < info.y_pos[info.cy]) && (my > info.y_pos[info.cy - 1]))
  374.             {
  375.               MoveRect(DIR_UP);
  376.             }
  377.            }        
  378.            if((mx > info.x_pos[info.cx] ) && (mx < info.x_pos[info.cx + 1]))
  379.            {
  380.             if((my > info.y_pos[info.cy  + 1 ]) && (my < info.y_pos[info.cy + 2]))
  381.             {
  382.               MoveRect(DIR_DOWN);
  383.             }
  384.            }
  385.                         break;
  386.       default           :break;
  387.      }
  388.     }
  389.                if(_solved())
  390.            {
  391.             CopyWBGfx();
  392.             ntext.TopEdge  = 40;
  393.             ntext.LeftEdge = 70;
  394.             ntext.NextText = &end4;
  395.             sprintf(number,"%3ld",info.moves);
  396.             DisplayReq(&end1);
  397.             ScreenToBack(info.sc);
  398.             end = TRUE;
  399.            }
  400.   
  401.    }
  402.   }
  403.  }
  404.  FreeScWd();     
  405. }
  406.  
  407. void  CopyWBGfx(void)
  408. {
  409.  ClipBlit(&(Scr->RastPort),0,0,info.wd->RPort,0,0,Scr->Width,Scr->Height,0xc0);
  410.  WaitBlit();
  411.  ScreenToFront(info.sc);
  412. }
  413.  
  414. void SetUpValues(void)
  415. {
  416.  UWORD w,h;
  417.  UWORD i,v,n;
  418.  setmem(&info.x_pos,sizeof(info.x_pos),'\0');
  419.  setmem(&info.y_pos,sizeof(info.y_pos),'\0');
  420.  setmem(&info.solved,sizeof(info.solved),'\0');
  421.  setmem(&info.current,sizeof(info.current),'\0');
  422.  w = (UWORD)(Scr->Width  / info.resolution[info.res].x_res);
  423.  h = (UWORD)(Scr->Height / info.resolution[info.res].y_res);
  424.  info.w =  w;
  425.  info.h =  h;
  426.  if(((w >= 64) && (h >= 64)) || (info.dri->dri_Depth > 4))
  427.  {
  428.   info.size_x = w; info.size_y = h; 
  429.   info.step_x = 1; info.step_y = 1;
  430.  }
  431.  else
  432.  {
  433.   info.size_x = 1; info.size_y = 1; 
  434.   info.step_x = w; info.step_y = h;
  435.  }
  436.  for(i = 0;i <= info.resolution[info.res].x_res;i++)
  437.     info.x_pos[i] = w * i;
  438.  for(i = 0;i <= info.resolution[info.res].y_res;i++)
  439.     info.y_pos[i] = h * i;
  440.  n = 1;
  441.  bp1[0] =  0     ; bp1[1] = h - 1; 
  442.  bp1[2] =  0     ; bp1[3] = 0; 
  443.  bp1[4] =  w - 1 ; bp1[5] = 0; 
  444.  bp2[0] =  w - 1 ; bp2[1] = 0; 
  445.  bp2[2] =  w - 1 ; bp2[3] = h - 1; 
  446.  bp2[4] =  0     ; bp2[5] = h - 1;
  447.  for(i = 0;i < info.resolution[info.res].x_res;i++)
  448.  {
  449.   for(v = 0;v < info.resolution[info.res].y_res;v++,n)
  450.   {
  451.    info.solved[i][v]  = n;
  452.    info.current[i][v] = n;
  453.    n++;
  454.   }
  455.  }  
  456.  SliceBoard();
  457.  shuffle(info.shuffle);
  458.  info.moves = 0;
  459. }
  460.  
  461. void SliceBoard(void)
  462. {
  463.  int i,j,n;
  464.  struct RastPort   *rp = info.wd->RPort;
  465.  SetAPen(rp,1);
  466.  SetBPen(rp,1);
  467.  n = 1;
  468.  ntext.LeftEdge = 0;
  469.  ntext.TopEdge  = 0;
  470.  ntext.NextText = NULL;
  471.  for(j = 0;j < info.resolution[info.res].y_res;j++)
  472.  {
  473.   for(i = 0;i < info.resolution[info.res].x_res;i++)
  474.   {
  475.    DrawBorder(rp,&b1,info.x_pos[i],info.y_pos[j]);
  476.    sprintf(number,"%3ld",n);
  477.    if(info.numbers)PrintIText(rp,&ntext,info.x_pos[i] + ( info.w / 2),
  478.                                         info.y_pos[j] + ( info.h / 2));
  479.    n++;
  480.   }
  481.  }  
  482.  info.cx = RangeRand(info.resolution[info.res].x_res - 1);
  483.  info.cy = RangeRand(info.resolution[info.res].y_res - 1 );
  484.  RectFill(rp,info.x_pos[info.cx],info.y_pos[info.cy],info.x_pos[info.cx + 1] - 1,info.y_pos[info.cy + 1] - 1);
  485. }   
  486.  
  487. void shuffle(UWORD howmuch)
  488. {
  489.  UWORD i,n;
  490.  info.old_dir = DIR_UP;
  491.  for(i = 0;i < howmuch;i++)
  492.  {
  493.   while((n = (UWORD)RangeRand(4)) != info.dirs[info.old_dir].opposite)
  494.   {
  495.    MoveRect(n);
  496.    info.old_dir = n;
  497.   }
  498.  } 
  499. }
  500.  
  501. void MoveRect(UWORD to)
  502. {
  503.  int i;
  504.  struct RastPort *rp = info.wd->RPort;
  505.  switch(to)
  506.  {
  507.   case DIR_UP  : if(info.cy > 0)
  508.                 {
  509.                  swap(to);
  510.                  info.cy -= 1;
  511.                  for(i=0;i < info.step_y ; i++)
  512.                  ScrollRaster(rp,0L,- info.size_y,
  513.                               info.x_pos[info.cx],
  514.                               info.y_pos[info.cy],
  515.                               info.x_pos[info.cx + 1] - 1,
  516.                               info.y_pos[info.cy + 2] - 1
  517.                              );
  518.                 }
  519.                 break;
  520.  case DIR_DOWN : if(info.cy < info.resolution[info.res].y_res - 1 )
  521.                 {
  522.                  for(i=0;i < info.step_y;i++)
  523.                  ScrollRaster(rp,0L,info.size_y,
  524.                               info.x_pos[info.cx],
  525.                               info.y_pos[info.cy],
  526.                               info.x_pos[info.cx + 1] - 1,
  527.                               info.y_pos[info.cy + 2] - 1
  528.                              );
  529.                 swap(to);
  530.                 info.cy  += 1;
  531.                 }
  532.                 break;
  533.   case DIR_LEFT : if(info.cx > 0)
  534.                 {
  535.                  swap(to);
  536.                  info.cx -= 1;
  537.                  for(i=0;i < info.step_x;i++)
  538.                  ScrollRaster(rp,- info.size_x,0,
  539.                               info.x_pos[info.cx],
  540.                               info.y_pos[info.cy],
  541.                               info.x_pos[info.cx + 2] - 1,
  542.                               info.y_pos[info.cy + 1] - 1
  543.                              );
  544.                 }
  545.                 break;
  546.   case DIR_RIGHT : if(info.cx < info.resolution[info.res].x_res - 1)
  547.                 {
  548.                  for(i=0;i < info.step_x;i++)
  549.                  ScrollRaster(rp,info.size_x,0,
  550.                               info.x_pos[info.cx],
  551.                               info.y_pos[info.cy],
  552.                               info.x_pos[info.cx + 2] - 1,
  553.                               info.y_pos[info.cy + 1] - 1
  554.                              );
  555.                  swap(to);
  556.                  info.cx += 1;
  557.                 }
  558.                 break;  
  559.  }
  560. }
  561.  
  562. int  _solved(void)
  563. {
  564.  return(!(memcmp(info.solved,info.current,sizeof(info.solved))));
  565. }
  566.  
  567. void swap(UWORD to)
  568. {
  569.  UWORD t;
  570.  info.moves += 1;
  571.  switch(to)
  572.  {
  573.   case DIR_UP     : t = info.current[info.cx][info.cy];
  574.                     info.current[info.cx][info.cy] = info.current[info.cx][info.cy - 1];
  575.                     info.current[info.cx][info.cy - 1] = t;
  576.                     break;
  577.   case DIR_DOWN   : t = info.current[info.cx][info.cy];
  578.                     info.current[info.cx][info.cy] = info.current[info.cx][info.cy + 1];
  579.                     info.current[info.cx][info.cy + 1] = t;
  580.                     break;
  581.   case DIR_LEFT   : t = info.current[info.cx][info.cy];
  582.                     info.current[info.cx][info.cy] = info.current[info.cx - 1][info.cy];
  583.                     info.current[info.cx - 1][info.cy] = t;
  584.                     break;
  585.   case DIR_RIGHT  : t = info.current[info.cx][info.cy];
  586.                     info.current[info.cx][info.cy] = info.current[info.cx + 1][info.cy];
  587.                     info.current[info.cx + 1][info.cy] = t;
  588.                     break;
  589.  }
  590. }
  591.  
  592. int Project0VanillaKey()
  593. {
  594.  int rc = TRUE;
  595.  switch(Project0Msg.Code)
  596.  {
  597.   case 'Q'    :
  598.   case 'q'    : rc = Project0CloseWindow();
  599.                 break;
  600.   case 's'    :
  601.   case 'S'    : startClicked();
  602.                 break;
  603.   case 'n'    :
  604.   case 'N'    : numbersClicked();
  605.                 break;
  606.   case 't'    :
  607.   case 'T'    : if(info.res == NUMTILES - 1)
  608.                    info.res = 0;
  609.                 else
  610.                    info.res++;
  611.                 GT_SetGadgetAttrs(Project0Gadgets[GDX_tiles],Project0Wnd,NULL,
  612.                                   GTCY_Active,info.res,TAG_DONE);
  613.                 break;
  614.   case 'f'    :
  615.   case 'F'    : if(info.m_shuffles == NUMSHUFFLES - 1)
  616.                    info.m_shuffles = 0;
  617.                 else
  618.                    info.m_shuffles++;
  619.                 info.shuffle = atol(shuffle0Labels[info.m_shuffles]); 
  620.                 GT_SetGadgetAttrs(Project0Gadgets[GDX_shuffle],Project0Wnd,NULL,
  621.                                   GTCY_Active,info.m_shuffles,TAG_DONE);
  622.                 break;
  623.   case 'm'    :
  624.   case 'M'    : modeClicked();
  625.                 break;
  626.   default     : break;
  627.  }
  628.  return rc;
  629. }
  630.  
  631. void DisplayReq(struct IntuiText *text)
  632. {
  633.  struct Message *msg;
  634.  struct Window *hwd;
  635.  if(hwd = OpenWindowTags(NULL,
  636.           WA_Left,(ULONG)(info.sc->Width  / 2 - 120),
  637.           WA_Top ,(ULONG)(info.sc->Height / 2 - 60),
  638.           WA_Width,240,
  639.           WA_Height,120,
  640.           WA_IDCMP,IDCMP_MOUSEBUTTONS | IDCMP_VANILLAKEY,
  641.           WA_Flags,WFLG_ACTIVATE|WFLG_BORDERLESS|WFLG_SMART_REFRESH | WFLG_RMBTRAP,
  642.           WA_CustomScreen,info.sc,
  643.           TAG_DONE
  644.  ))
  645.  {
  646.   SetRast(hwd->RPort,2);
  647.   SetAPen(hwd->RPort,1);
  648.   Move(hwd->RPort,2,2);
  649.   Draw(hwd->RPort,236,2);
  650.   Draw(hwd->RPort,236,116);
  651.   Draw(hwd->RPort,2,116);
  652.   Draw(hwd->RPort,2,2);
  653.   PrintIText(hwd->RPort,text,6,6);
  654.   WaitPort(hwd->UserPort);
  655.   while(msg = GetMsg(hwd->UserPort))ReplyMsg(msg);
  656.   CloseWindow(hwd);  
  657.  }
  658. }
  659.