home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ultra Mac Games 1 & 2
/
UltraMacGames2.iso
/
Puzzles
/
Maze
/
MazeGenAll.p
< prev
Wrap
Text File
|
1987-08-29
|
5KB
|
171 lines
(*
MazeGenAll.p -- a HyperCard external command to draw a random maze!
by Chris Knepper, August 1987
CompuServe: 76347,1757
Call this from HyperCard as follows:
MazeGenAll(x,y,lineDir)
x,y are the starting point of the line. We determine a "random" direction, either right or down
by looking at lineDir: true -> go right, false -> go left.
It returns error in returnValue.
To compile and link this file using Macintosh Programmer's Workshop:
pascal -w "{MPW}"HCard.xcmd:MazeGenAll.p
link -m ENTRYPOINT # set the main entry point spec'd in the obj files ∂
-o "{MPW}"HCard.xcmd:MazeGenAll.xfcn # place the Linker output here ∂
-rt XFCN=0 # sets the resource: type to XCMD; id to 0 ∂
-sn Main=MazeGenAll # combines the segment Main into MazeGenAll ∂
"{MPW}"HCard.xcmd:MazeGenAll.p.o ∂
"{Libraries}"Interface.o ∂
"{Plibraries}"PasLib.o
*)
{$R-}
{$S MazeGenAll } { Segment name must be the same as the command name. }
UNIT DummyUnit;
INTERFACE
USES MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, HyperXCmd;
{ Note: HyperXCmd.p is available from APDA -- put it in the folder :MPW:PInterfaces: }
PROCEDURE EntryPoint(paramPtr: XCmdPtr);
IMPLEMENTATION
TYPE Str19 = String[19];
Str31 = String[31];
PROCEDURE MazeGenAll(paramPtr: XCmdPtr); FORWARD;
PROCEDURE EntryPoint(paramPtr: XCmdPtr);
BEGIN
MazeGenAll(paramPtr);
END;
PROCEDURE MazeGenAll(paramPtr: XCmdPtr);
VAR str,retStr,myStr: Str255;
x,y,
fromXErase,fromYErase,toXErase,toYErase,
fromXDrag,fromYDrag,toXDrag,toYDrag: INTEGER;
{$I XCmdGlue.inc }
{ Note: XCmdGlue.inc is available from APDA -- put it in the folder :MPW:HCard.xcmd: }
FUNCTION toStr(a: LONGINT): Str255;
{ toStr converts an integer value to its string -- it makes the code readable }
VAR s: Str255;
BEGIN
NumToString(a,s);
toStr := s;
END;
FUNCTION OKDir(x1,y1,x2,y2: INTEGER): BOOLEAN;
{ OKDir returns true if the line has not yet been place or has not yet failed }
VAR tempStr:Str255;
theHandle: Handle;
BEGIN
OKDir:=false;
IF ((x1=0) AND (x2=0)) THEN exit(OKDir);
IF ((y1=0) AND (y2=0)) THEN exit(OKDir);
IF ((x1=15) AND (x2=15)) THEN exit(OKDir);
IF ((y1=9) AND (y2=9)) THEN exit(OKDir);
IF (x2>15) THEN exit(OKDir);
IF (y2>9) THEN exit(OKDir);
{ if str is not in allLines then continue }
theHandle := GetGlobal('allLines'); { GetGlobal is in XCmdGlue.inc }
tempStr := Concat(toStr(x1),toStr(y1),toStr(x2),toStr(y2),' ');
IF StringMatch(tempStr,theHandle^)<>NIL THEN exit(OKDir); { StringMatch is in XCmdGlue.inc }
SetGlobal('lastLine',PasToZero(tempStr)); { SetGlobal is in XCmdGlue.inc }
OKDir:=true;
END;
BEGIN
WITH paramPtr^ DO BEGIN
IF paramCount <> 3 THEN
retStr := 'error'
ELSE BEGIN
retStr := 'false';
{ first param is x coordinate }
ZeroToPas(params[1]^,str); { ZeroToPas is in XCmdGlue.inc }
x := StrToNum(str);
{ second param is y coordinate }
ZeroToPas(params[2]^,str);
y := StrToNum(str);
{ third param is lineDir }
ZeroToPas(params[3]^,str);
IF Odd(StrToNum(str)) THEN BEGIN {go down -- StrToNum is in XCmdGlue.inc }
IF OKDir(x,y,x,y+1) THEN BEGIN
retStr := 'true';
fromXDrag := x*24+65;
fromYDrag := y*24+60;
toXDrag := fromXDrag;
toYDrag := (y+1)*24+60;
fromXErase := fromXDrag;
fromYErase := fromYDrag+3;
toXErase := fromXDrag;
toYErase := toYDrag-3;
END { IF OKDir }
END ELSE IF OKDir(x,y,x+1,y) THEN BEGIN {go right}
retStr := 'true';
fromXDrag := x*24+65;
fromYDrag := y*24+60;
toXDrag := (x+1)*24+65;
toYDrag := fromYDrag;
fromXErase := fromXDrag+3;
fromYErase := fromYDrag;
toXErase := toXDrag-3;
toYErase := fromYDrag;
END; {IF OKDir}
IF retStr = 'true' THEN BEGIN { ie. line is OK as per OKDir }
str := Concat('drag from ',toStr(fromXDrag),',',toStr(fromYDrag),' to ');
str := Concat(str,toStr(toXDrag),',',toStr(toYDrag));
SendHCMessage(str); { SendHCMessage is in XCmdGlue.inc }
str := Concat('drag from ',toStr(fromXErase),',',toStr(fromYErase),' to ');
str := Concat(str,toStr(toXErase),',',toStr(toYErase));
SetGlobal('eraseLine',PasToZero(str));
str := 'doClick';
SendCardMessage(str); { SendCardMessage is in XCmdGlue.inc }
{ look at pixels in the current grafport and set a HyperCard global variable }
IF (fromXDrag = toXDrag) THEN { line is up/down }
SetGlobal('GetPixelRes',
PasToZero(BoolToStr(GetPixel(fromXDrag+5,fromYDrag+5) AND GetPixel(fromXDrag-5,fromYDrag+5))))
ELSE { line is across }
SetGlobal('GetPixelRes',
PasToZero(BoolToStr(GetPixel(fromXDrag+5,fromYDrag-5) AND GetPixel(fromXDrag+5,fromYDrag+5))));
END; {IF}
END; {IF}
returnValue := PasToZero(retStr);
passFlag := false;
END; {WITH}
END; {PROCEDURE}
END. {UNIT}