disable the unrecognized nls flag
[AROS-Contrib.git] / fish / shuffle / shuffle_temp.c
blob4193e2b160158d24d3d3759669c63d46ac9879ab
2 #include "shuffle.h"
4 struct EasyStruct ExitReq =
6 0L,0L,(UBYTE *)"Quit the Game ?",
7 (UBYTE *)"Really quit ?",
8 (UBYTE *)"Yes (L-AMIGA+V) | No (L-AMIGA + B)",
9 };
11 struct EasyStruct AboutReq =
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",
18 WORD bp1[] =
20 0,0,0,0,0,0
23 WORD bp2[] =
25 0,0,0,0,0,0
28 struct Border b2 =
30 0,0,1,0,JAM1,3,bp2,
33 struct Border b1 =
35 0,0,2,0,JAM1,3,bp1,&b2
38 struct Border b2r =
40 0,0,2,0,JAM1,3,bp2,
43 struct Border b1r =
45 0,0,1,0,JAM1,3,bp1,&b2
48 struct TextAttr topaz8 = {
49 ( STRPTR )"topaz.font", 8, 0x00, 0x01 };
51 UBYTE number[8];
53 struct IntuiText ntext =
55 1,2,JAM2,0,0,&topaz8,number,NULL
58 struct IntuiText anykey = {1,2,JAM2,4,100,&topaz8,"--- Any key to continue ---",NULL};
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};
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};
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};
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};
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};
91 int startClicked( void )
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);
120 return (TRUE);
123 int tilesClicked( void )
125 /* routine when gadget "Tiles" is clicked. */
126 info.res = Project0Msg.Code;
127 return (TRUE);
130 int shuffleClicked( void )
132 /* routine when gadget "Shuffle" is clicked. */
133 info.shuffle = atol(shuffle0Labels[Project0Msg.Code]);
134 info.m_shuffles = Project0Msg.Code;
135 return (TRUE);
138 int numbersClicked( void )
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);
145 return (TRUE);
148 int modeClicked( void )
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);
157 int Project0loadconfig( void )
159 /* routine when (sub)item "Load configuration" is selected. */
160 load_config(NULL);
161 return (TRUE);
164 int Project0saveasconfig( void )
166 /* routine when (sub)item "Save configuration" is selected. */
167 save_config(SAVE_AS);
168 return (TRUE);
171 int Project0saveconfig( void )
173 /* routine when (sub)item "Save configuration" is selected. */
174 save_config(SAVE_NAME);
175 return (TRUE);
178 int Project0savedefault( void )
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);
186 int Project0about( void )
188 /* routine when (sub)item "About..." is selected. */
189 EasyRequestArgs(info.wd,&AboutReq,NULL,NULL);
190 return(TRUE);
193 int Project0quit( void )
195 /* routine when (sub)item "Quit" is selected. */
196 return (Project0CloseWindow());;
199 int Project0Icon()
201 info.writeicon = (info.writeicon) ? FALSE : TRUE;
202 return (TRUE);
205 int Project0CloseWindow( void )
207 /* routine for "IDCMP_CLOSEWINDOW". */
208 return(EasyRequestArgs(info.wd,&ExitReq,NULL,NULL) == 1) ? FALSE : TRUE;
211 int MakeScWd(void)
213 if((info.sc = CloneScreen(Scr)))
215 info.oldcmap = info.sc->ViewPort.ColorMap;
216 info.sc->ViewPort.ColorMap = Scr->ViewPort.ColorMap;
217 if((info.wd = MakeWd(info.sc)))
219 CopyWBGfx();
220 return (TRUE);
223 return (FALSE);
226 void FreeScWd(void)
228 if(info.wd)
230 CloseWindow(info.wd);
231 info.wd = NULL;
233 if(info.sc)
235 if(info.oldcmap)info.sc->ViewPort.ColorMap = info.oldcmap;
237 CloseScreen(info.sc);
238 info.sc = NULL;
242 struct Screen * CloneScreen(struct Screen *wb)
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
262 struct Window *MakeWd(struct Screen *screen)
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
272 void Play(void)
274 int end = FALSE;
275 ULONG sigs,sigrcvd;
276 struct IntuiMessage *msg;
277 ULONG class;
278 USHORT code;
279 WORD mx,my;
281 if(MakeScWd())
283 /* SetBPen(info.wd->RPort,1); */
284 SetUpValues();
285 sigs = (1L<<Project0Wnd->UserPort->mp_SigBit) |
286 (1L<<info.wd->UserPort->mp_SigBit);
287 DisplayReq(&intro1);
288 while(!end)
290 sigrcvd = Wait(sigs);
291 if(sigrcvd & (1L<<Project0Wnd->UserPort->mp_SigBit))end = TRUE;
292 if(sigrcvd & (1L<<info.wd->UserPort->mp_SigBit))
294 while((msg = (struct IntuiMessage *)GetMsg(info.wd->UserPort)))
296 class = msg->Class;
297 code = msg->Code;
298 mx = msg->MouseX;
299 my = msg->MouseY;
300 ReplyMsg((struct Message *)msg);
301 switch(class)
303 case IDCMP_VANILLAKEY :
304 switch(code)
306 case 'a' :
307 case 'A' :
308 DisplayReq(&a1);
309 break;
310 case 'h' :
311 case 'H' :
312 DisplayReq(&h1);
313 break;
314 case 's' :
315 case 'S' :
316 ntext.TopEdge = 40;
317 ntext.LeftEdge = 40;
318 ntext.NextText = &s2;
319 sprintf(number,"%3ld",(long)info.moves);
320 DisplayReq(&s1);
321 break;
322 case 0x1b :
323 case 'Q' :
324 case 'q' :
325 if( EasyRequestArgs(info.wd,&ExitReq,NULL,NULL) == 1)
326 end = TRUE;
327 break;
328 default : break;
330 break;
331 case IDCMP_RAWKEY :
332 switch(code)
334 case 0x5f :
335 DisplayReq(&h1);
336 break;
337 case 0x45 :
338 end = TRUE;
339 break;
340 case 0x4c :
341 if(info.mode == MODE_GAP)
342 MoveRect(DIR_UP);
343 else
344 MoveRect(DIR_DOWN);
345 break;
346 case 0x4d :
347 if(info.mode == MODE_GAP)
348 MoveRect(DIR_DOWN);
349 else
350 MoveRect(DIR_UP);
351 break;
352 case 0x4f :
353 if(info.mode == MODE_GAP)
354 MoveRect(DIR_LEFT);
355 else
356 MoveRect(DIR_RIGHT);
357 break;
358 case 0x4e :
359 if(info.mode == MODE_GAP)
360 MoveRect(DIR_RIGHT);
361 else
362 MoveRect(DIR_LEFT);
363 break;
364 default :
365 break;
367 break;
368 case IDCMP_MOUSEBUTTONS :
369 if((mx < info.x_pos[info.cx]) && (mx > info.x_pos[info.cx - 1]))
371 if((my > info.y_pos[info.cy]) && (my < info.y_pos[info.cy + 1]))
373 MoveRect(DIR_LEFT);
376 if((mx > info.x_pos[info.cx + 1]) && (mx < info.x_pos[info.cx + 2]))
378 if((my > info.y_pos[info.cy]) && (my < info.y_pos[info.cy + 1]))
380 MoveRect(DIR_RIGHT);
383 if((mx > info.x_pos[info.cx]) && (mx < info.x_pos[info.cx + 1]))
385 if((my < info.y_pos[info.cy]) && (my > info.y_pos[info.cy - 1]))
387 MoveRect(DIR_UP);
390 if((mx > info.x_pos[info.cx] ) && (mx < info.x_pos[info.cx + 1]))
392 if((my > info.y_pos[info.cy + 1 ]) && (my < info.y_pos[info.cy + 2]))
394 MoveRect(DIR_DOWN);
397 break;
398 default :break;
401 if(_solved())
403 CopyWBGfx();
404 ntext.TopEdge = 40;
405 ntext.LeftEdge = 70;
406 ntext.NextText = &end4;
407 sprintf(number,"%3ld",(long)info.moves);
408 DisplayReq(&end1);
409 ScreenToBack(info.sc);
410 end = TRUE;
416 FreeScWd();
419 void CopyWBGfx(void)
421 ClipBlit(&(Scr->RastPort),0,0,info.wd->RPort,0,0,Scr->Width,Scr->Height,0xc0);
422 WaitBlit();
423 ScreenToFront(info.sc);
426 void SetUpValues(void)
428 UWORD w,h;
429 UWORD i,v,n;
430 setmem(&info.x_pos,sizeof(info.x_pos),'\0');
431 setmem(&info.y_pos,sizeof(info.y_pos),'\0');
432 setmem(&info.solved,sizeof(info.solved),'\0');
433 setmem(&info.current,sizeof(info.current),'\0');
434 w = (UWORD)(Scr->Width / info.resolution[info.res].x_res);
435 h = (UWORD)(Scr->Height / info.resolution[info.res].y_res);
436 info.w = w;
437 info.h = h;
438 if(((w >= 64) && (h >= 64)) || (info.dri->dri_Depth > 4))
440 info.size_x = w; info.size_y = h;
441 info.step_x = 1; info.step_y = 1;
443 else
445 info.size_x = 1; info.size_y = 1;
446 info.step_x = w; info.step_y = h;
448 for(i = 0;i <= info.resolution[info.res].x_res;i++)
449 info.x_pos[i] = w * i;
450 for(i = 0;i <= info.resolution[info.res].y_res;i++)
451 info.y_pos[i] = h * i;
452 n = 1;
453 bp1[0] = 0 ; bp1[1] = h - 1;
454 bp1[2] = 0 ; bp1[3] = 0;
455 bp1[4] = w - 1 ; bp1[5] = 0;
456 bp2[0] = w - 1 ; bp2[1] = 0;
457 bp2[2] = w - 1 ; bp2[3] = h - 1;
458 bp2[4] = 0 ; bp2[5] = h - 1;
459 for(i = 0;i < info.resolution[info.res].x_res;i++)
461 for(v = 0;v < info.resolution[info.res].y_res;v++,n++)
463 info.solved[i][v] = n;
464 info.current[i][v] = n;
467 SliceBoard();
468 shuffle(info.shuffle);
469 info.moves = 0;
472 void SliceBoard(void)
474 int i,j,n;
475 struct RastPort *rp = info.wd->RPort;
476 SetAPen(rp,1);
477 SetBPen(rp,1);
478 n = 1;
479 ntext.LeftEdge = 0;
480 ntext.TopEdge = 0;
481 ntext.NextText = NULL;
482 for(j = 0;j < info.resolution[info.res].y_res;j++)
484 for(i = 0;i < info.resolution[info.res].x_res;i++)
486 DrawBorder(rp,&b1,info.x_pos[i],info.y_pos[j]);
487 sprintf(number,"%3ld",(long)n);
488 if(info.numbers)PrintIText(rp,&ntext,info.x_pos[i] + ( info.w / 2),
489 info.y_pos[j] + ( info.h / 2));
490 n++;
493 info.cx = RangeRand(info.resolution[info.res].x_res - 1);
494 info.cy = RangeRand(info.resolution[info.res].y_res - 1 );
495 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);
498 void shuffle(UWORD howmuch)
500 UWORD i,n;
501 info.old_dir = DIR_UP;
502 for(i = 0;i < howmuch;i++)
504 while((n = (UWORD)RangeRand(4)) != info.dirs[info.old_dir].opposite)
506 MoveRect(n);
507 info.old_dir = n;
512 void MoveRect(UWORD to)
514 int i;
515 struct RastPort *rp = info.wd->RPort;
516 switch(to)
518 case DIR_UP : if(info.cy > 0)
520 swap(to);
521 info.cy -= 1;
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
530 break;
531 case DIR_DOWN : if(info.cy < info.resolution[info.res].y_res - 1 )
533 for(i=0;i < info.step_y;i++)
534 ScrollRaster(rp,0L,info.size_y,
535 info.x_pos[info.cx],
536 info.y_pos[info.cy],
537 info.x_pos[info.cx + 1] - 1,
538 info.y_pos[info.cy + 2] - 1
540 swap(to);
541 info.cy += 1;
543 break;
544 case DIR_LEFT : if(info.cx > 0)
546 swap(to);
547 info.cx -= 1;
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
556 break;
557 case DIR_RIGHT : if(info.cx < info.resolution[info.res].x_res - 1)
559 for(i=0;i < info.step_x;i++)
560 ScrollRaster(rp,info.size_x,0,
561 info.x_pos[info.cx],
562 info.y_pos[info.cy],
563 info.x_pos[info.cx + 2] - 1,
564 info.y_pos[info.cy + 1] - 1
566 swap(to);
567 info.cx += 1;
569 break;
573 int _solved(void)
575 return(!(memcmp(info.solved,info.current,sizeof(info.solved))));
578 void swap(UWORD to)
580 UWORD t;
581 info.moves += 1;
582 switch(to)
584 case DIR_UP : t = info.current[info.cx][info.cy];
585 info.current[info.cx][info.cy] = info.current[info.cx][info.cy - 1];
586 info.current[info.cx][info.cy - 1] = t;
587 break;
588 case DIR_DOWN : t = info.current[info.cx][info.cy];
589 info.current[info.cx][info.cy] = info.current[info.cx][info.cy + 1];
590 info.current[info.cx][info.cy + 1] = t;
591 break;
592 case DIR_LEFT : t = info.current[info.cx][info.cy];
593 info.current[info.cx][info.cy] = info.current[info.cx - 1][info.cy];
594 info.current[info.cx - 1][info.cy] = t;
595 break;
596 case DIR_RIGHT : t = info.current[info.cx][info.cy];
597 info.current[info.cx][info.cy] = info.current[info.cx + 1][info.cy];
598 info.current[info.cx + 1][info.cy] = t;
599 break;
603 int Project0VanillaKey()
605 int rc = TRUE;
606 switch(Project0Msg.Code)
608 case 'Q' :
609 case 'q' : rc = Project0CloseWindow();
610 break;
611 case 's' :
612 case 'S' : startClicked();
613 break;
614 case 'n' :
615 case 'N' : numbersClicked();
616 break;
617 case 't' :
618 case 'T' : if(info.res == NUMTILES - 1)
619 info.res = 0;
620 else
621 info.res++;
622 GT_SetGadgetAttrs(Project0Gadgets[GDX_tiles],Project0Wnd,NULL,
623 GTCY_Active,info.res,TAG_DONE);
624 break;
625 case 'f' :
626 case 'F' : if(info.m_shuffles == NUMSHUFFLES - 1)
627 info.m_shuffles = 0;
628 else
629 info.m_shuffles++;
630 info.shuffle = atol(shuffle0Labels[info.m_shuffles]);
631 GT_SetGadgetAttrs(Project0Gadgets[GDX_shuffle],Project0Wnd,NULL,
632 GTCY_Active,info.m_shuffles,TAG_DONE);
633 break;
634 case 'm' :
635 case 'M' : modeClicked();
636 break;
637 default : break;
639 return rc;
642 void DisplayReq(struct IntuiText *text)
644 struct Message *msg;
645 struct Window *hwd;
646 if((hwd = OpenWindowTags(NULL,
647 WA_Left,(ULONG)(info.sc->Width / 2 - 120),
648 WA_Top ,(ULONG)(info.sc->Height / 2 - 60),
649 WA_Width,240,
650 WA_Height,120,
651 WA_IDCMP,IDCMP_MOUSEBUTTONS | IDCMP_VANILLAKEY,
652 WA_Flags,WFLG_ACTIVATE|WFLG_BORDERLESS|WFLG_SMART_REFRESH | WFLG_RMBTRAP,
653 WA_CustomScreen,info.sc,
654 TAG_DONE
657 SetRast(hwd->RPort,2);
658 SetAPen(hwd->RPort,1);
659 Move(hwd->RPort,2,2);
660 Draw(hwd->RPort,236,2);
661 Draw(hwd->RPort,236,116);
662 Draw(hwd->RPort,2,116);
663 Draw(hwd->RPort,2,2);
664 PrintIText(hwd->RPort,text,6,6);
665 WaitPort(hwd->UserPort);
666 while((msg = GetMsg(hwd->UserPort)))ReplyMsg(msg);
667 CloseWindow(hwd);