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)",
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",
35 0,0,2,0,JAM1
,3,bp1
,&b2
45 0,0,1,0,JAM1
,3,bp1
,&b2
48 struct TextAttr topaz8
= {
49 ( STRPTR
)"topaz.font", 8, 0x00, 0x01 };
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
);
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
);
123 int tilesClicked( void )
125 /* routine when gadget "Tiles" is clicked. */
126 info
.res
= Project0Msg
.Code
;
130 int shuffleClicked( void )
132 /* routine when gadget "Shuffle" is clicked. */
133 info
.shuffle
= atol(shuffle0Labels
[Project0Msg
.Code
]);
134 info
.m_shuffles
= Project0Msg
.Code
;
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
);
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
);
157 int Project0loadconfig( void )
159 /* routine when (sub)item "Load configuration" is selected. */
164 int Project0saveasconfig( void )
166 /* routine when (sub)item "Save configuration" is selected. */
167 save_config(SAVE_AS
);
171 int Project0saveconfig( void )
173 /* routine when (sub)item "Save configuration" is selected. */
174 save_config(SAVE_NAME
);
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
);
186 int Project0about( void )
188 /* routine when (sub)item "About..." is selected. */
189 EasyRequestArgs(info
.wd
,&AboutReq
,NULL
,NULL
);
193 int Project0quit( void )
195 /* routine when (sub)item "Quit" is selected. */
196 return (Project0CloseWindow());;
201 info
.writeicon
= (info
.writeicon
) ? FALSE
: TRUE
;
205 int Project0CloseWindow( void )
207 /* routine for "IDCMP_CLOSEWINDOW". */
208 return(EasyRequestArgs(info
.wd
,&ExitReq
,NULL
,NULL
) == 1) ? FALSE
: TRUE
;
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
)))
230 CloseWindow(info
.wd
);
235 if(info
.oldcmap
)info
.sc
->ViewPort
.ColorMap
= info
.oldcmap
;
237 CloseScreen(info
.sc
);
242 struct Screen
* CloneScreen(struct Screen
*wb
)
244 struct DimensionInfo dinfo
;
246 mode_id
= GetVPModeID(&(wb
->ViewPort
));
247 (void)GetDisplayInfoData(NULL
,(APTR
)&dinfo
,sizeof(dinfo
),DTAG_DIMS
,mode_id
);
248 return OpenScreenTags(NULL
,
250 SA_Height
,wb
->Height
,
251 SA_Depth
,info
.dri
->dri_Depth
,
252 SA_Pens
,info
.dri
->dri_Pens
,
253 SA_DisplayID
,mode_id
,
256 SA_DClip
,&dinfo
.TxtOScan
,
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
,
276 struct IntuiMessage
*msg
;
283 /* SetBPen(info.wd->RPort,1); */
285 sigs
= (1L<<Project0Wnd
->UserPort
->mp_SigBit
) |
286 (1L<<info
.wd
->UserPort
->mp_SigBit
);
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
)))
300 ReplyMsg((struct Message
*)msg
);
303 case IDCMP_VANILLAKEY
:
318 ntext
.NextText
= &s2
;
319 sprintf(number
,"%3ld",(long)info
.moves
);
325 if( EasyRequestArgs(info
.wd
,&ExitReq
,NULL
,NULL
) == 1)
341 if(info
.mode
== MODE_GAP
)
347 if(info
.mode
== MODE_GAP
)
353 if(info
.mode
== MODE_GAP
)
359 if(info
.mode
== MODE_GAP
)
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]))
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]))
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]))
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]))
406 ntext
.NextText
= &end4
;
407 sprintf(number
,"%3ld",(long)info
.moves
);
409 ScreenToBack(info
.sc
);
421 ClipBlit(&(Scr
->RastPort
),0,0,info
.wd
->RPort
,0,0,Scr
->Width
,Scr
->Height
,0xc0);
423 ScreenToFront(info
.sc
);
426 void SetUpValues(void)
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
);
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;
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
;
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
;
468 shuffle(info
.shuffle
);
472 void SliceBoard(void)
475 struct RastPort
*rp
= info
.wd
->RPort
;
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));
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
)
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
)
512 void MoveRect(UWORD to
)
515 struct RastPort
*rp
= info
.wd
->RPort
;
518 case DIR_UP
: if(info
.cy
> 0)
522 for(i
=0;i
< info
.step_y
; i
++)
523 ScrollRaster(rp
,0L,- info
.size_y
,
526 info
.x_pos
[info
.cx
+ 1] - 1,
527 info
.y_pos
[info
.cy
+ 2] - 1
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
,
537 info
.x_pos
[info
.cx
+ 1] - 1,
538 info
.y_pos
[info
.cy
+ 2] - 1
544 case DIR_LEFT
: if(info
.cx
> 0)
548 for(i
=0;i
< info
.step_x
;i
++)
549 ScrollRaster(rp
,- info
.size_x
,0,
552 info
.x_pos
[info
.cx
+ 2] - 1,
553 info
.y_pos
[info
.cy
+ 1] - 1
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,
563 info
.x_pos
[info
.cx
+ 2] - 1,
564 info
.y_pos
[info
.cy
+ 1] - 1
575 return(!(memcmp(info
.solved
,info
.current
,sizeof(info
.solved
))));
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
;
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
;
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
;
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
;
603 int Project0VanillaKey()
606 switch(Project0Msg
.Code
)
609 case 'q' : rc
= Project0CloseWindow();
612 case 'S' : startClicked();
615 case 'N' : numbersClicked();
618 case 'T' : if(info
.res
== NUMTILES
- 1)
622 GT_SetGadgetAttrs(Project0Gadgets
[GDX_tiles
],Project0Wnd
,NULL
,
623 GTCY_Active
,info
.res
,TAG_DONE
);
626 case 'F' : if(info
.m_shuffles
== NUMSHUFFLES
- 1)
630 info
.shuffle
= atol(shuffle0Labels
[info
.m_shuffles
]);
631 GT_SetGadgetAttrs(Project0Gadgets
[GDX_shuffle
],Project0Wnd
,NULL
,
632 GTCY_Active
,info
.m_shuffles
,TAG_DONE
);
635 case 'M' : modeClicked();
642 void DisplayReq(struct IntuiText
*text
)
646 if((hwd
= OpenWindowTags(NULL
,
647 WA_Left
,(ULONG
)(info
.sc
->Width
/ 2 - 120),
648 WA_Top
,(ULONG
)(info
.sc
->Height
/ 2 - 60),
651 WA_IDCMP
,IDCMP_MOUSEBUTTONS
| IDCMP_VANILLAKEY
,
652 WA_Flags
,WFLG_ACTIVATE
|WFLG_BORDERLESS
|WFLG_SMART_REFRESH
| WFLG_RMBTRAP
,
653 WA_CustomScreen
,info
.sc
,
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
);