IMPLEMENTATION MODULE Robot; <* WOFF + *> FROM IO IMPORT RdChar, WrChar, WrStr, RdStr,RdKey, WrLn, RdLn, RdCard, WrCard, RdInt, WrInt, RdReal, WrReal, WrFixReal, RdBool, WrBool; FROM Lib IMPORT Delay; (* Wait n milliseconds *) FROM Graph IMPORT Init, Line, Rectangle, Circle, Disc, _clrBLACK, _clrBLUE, _clrGREEN, _clrCYAN, _clrRED, _clrMAGENTA,SetTextPosition, OutText; FROM Graph IMPORT _clrBROWN, _clrWHITE, _clrGRAY, _clrLIGHTBLUE, _clrLIGHTGREEN, _clrLIGHTCYAN, _clrLIGHTRED, _clrLIGHTMAGENTA, _clrLIGHTYELLOW, _clrBRIGHTWHITE; CONST SCREEN_SIZE = 600; (* constants *) BLOK_GROOTTE=50; SCHERM_GROOTTE=20; AANTAL_FIGUREN=20; TYPE PointRc = RECORD; x,y:INTEGER; END; FIGUUR = RECORD p1,p2 : PointRc; END; VAR (* variable-declarations *) position:PointRc; motorON:BOOLEAN; richting:RichtingEn; richCoord:ARRAY RichtingEn OF PointRc; figuren : ARRAY[1..AANTAL_FIGUREN] OF FIGUUR; scherm : ARRAY[0..SCHERM_GROOTTE],[0..SCHERM_GROOTTE] OF BOOLEAN; PROCEDURE TekenFiguur(p1, p2: PointRc); BEGIN Rectangle((p1.x)*BLOK_GROOTTE,(p1.y)*BLOK_GROOTTE,(p2.x)*BLOK_GROOTTE,(p2.y)*BLOK_GROOTTE, 4,TRUE) ; END TekenFiguur; PROCEDURE StartMotor(r: RichtingEn); BEGIN motorON:=TRUE; richting:=r; END StartMotor; PROCEDURE StopMotor(r: RichtingEn); BEGIN motorON:=FALSE; END StopMotor; PROCEDURE OneStep(r:RichtingEn); VAR i:INTEGER; BEGIN FOR i:= 0 TO (BLOK_GROOTTE-1) DO Delay(1); Rectangle(BLOK_GROOTTE*position.x+(i*richCoord[r].x),BLOK_GROOTTE*position.y+(i*richCoord[r].y),BLOK_GROOTTE*(position.x+1)+(i*richCoord[r].x),BLOK_GROOTTE*(position.y+1)+(i*richCoord[r].y),0,TRUE); Rectangle(BLOK_GROOTTE*position.x+((i+1)*richCoord[r].x)+2,BLOK_GROOTTE*position.y+((i+1)*richCoord[r].y)+2,BLOK_GROOTTE*(position.x+1)+((i+1)*richCoord[r].x)-2,BLOK_GROOTTE*(position.y+1)+((i+1)*richCoord[r].y)-2,2,TRUE); END; position.x:=position.x+richCoord[r].x; position.y:=position.y+richCoord[r].y; END OneStep; PROCEDURE GeefStandSensors(VAR dirs:DetectieStandAr): BOOLEAN; VAR i:RichtingEn; arrived: BOOLEAN; BEGIN OneStep(richting); FOR i:= NOORD TO ZUID DO IF (position.x+richCoord[i].x>-1) AND (position.y+richCoord[i].y>-1) AND (position.x+richCoord[i].x<21) AND (position.y+richCoord[i].y<21) THEN dirs[i]:=scherm[position.x+richCoord[i].x,position.y+richCoord[i].y]; ELSE dirs[i]:=FALSE; END; END; IF position.x = SCHERM_GROOTTE THEN arrived:=TRUE; OutText(" YEAH! I found the exit!"); ELSE arrived:=FALSE; END; RETURN arrived; END GeefStandSensors; (**** INITIALISATIE ******) VAR r : CARDINAL; i,j,k,m,n,l,o:INTEGER; p1,p2: PointRc; BEGIN WrLn; IF NOT Init(1, 1 , 1000, 1000) THEN WrStr("Sorry, graphics doesn't work");WrLn; RETURN; END; WITH figuren[1] DO p1.x := 1 ; p1.y := 0 ; p2.x := 2 ; p2.y := 2 ; END; WITH figuren[2] DO p1.x := 2 ; p1.y := 2 ; p2.x := 5 ; p2.y := 3 ; END; WITH figuren[3] DO p1.x := 4 ; p1.y := 2 ; p2.x := 5 ; p2.y := 5 ; END; WITH figuren[4] DO p1.x := 6 ; p1.y := 4 ; p2.x := 7 ; p2.y := 6 ; END; WITH figuren[5] DO p1.x := 8 ; p1.y := 0 ; p2.x := 9 ; p2.y := 5 ; END; WITH figuren[6] DO p1.x := 10 ; p1.y := 5 ; p2.x := 11 ; p2.y := 6 ; END; WITH figuren[7] DO p1.x := 12 ; p1.y := 2; p2.x := 13 ; p2.y := 7 ; END; WITH figuren[8] DO p1.x := 14 ; p1.y := 2 ; p2.x := 15 ; p2.y := 3 ; END; WITH figuren[9] DO p1.x := 3 ; p1.y := 8 ; p2.x := 5 ; p2.y := 12 ; END; WITH figuren[10] DO p1.x := 17 ; p1.y := 5; p2.x := 18 ; p2.y := 13; END; WITH figuren[11] DO p1.x := 10 ; p1.y := 12; p2.x := 16 ; p2.y := 13; END; WITH figuren[12] DO p1.x := 8 ; p1.y := 8; p2.x := 11 ; p2.y := 10; END; WITH figuren[13] DO p1.x := 11 ; p1.y := 3; p2.x := 13 ; p2.y := 4; END; WITH figuren[14] DO p1.x := 13 ; p1.y := 7; p2.x := 14 ; p2.y := 8; END; WITH figuren[15] DO p1.x := 14 ; p1.y := 8; p2.x := 15 ; p2.y := 9; END; WITH figuren[16] DO p1.x := 15 ; p1.y := 9; p2.x := 16 ; p2.y := 10; END; WITH figuren[17] DO p1.x := 16 ; p1.y := 10; p2.x := 18 ; p2.y := 11; END; WITH figuren[18] DO p1.x := 8 ; p1.y := 8; p2.x := 11 ; p2.y := 10; END; WITH figuren[19] DO p1.x := 8 ; p1.y := 8; p2.x := 11 ; p2.y := 10; END; WITH figuren[20] DO p1.x := 8 ; p1.y := 8; p2.x := 11 ; p2.y := 10; END; FOR i:=1 TO AANTAL_FIGUREN DO TekenFiguur(figuren[i].p1,figuren[i].p2) ; END; FOR i:=0 TO SCHERM_GROOTTE DO FOR j:=0 TO SCHERM_GROOTTE DO scherm[i][j] := TRUE ; END; END; FOR i:=1 TO AANTAL_FIGUREN DO m := figuren[i].p1.x; k := figuren[i].p2.x-1; l := figuren[i].p1.y; o := figuren[i].p2.y-1; FOR j:=m TO k DO FOR n:=l TO o DO scherm[j][n] := FALSE ; END; END; END; (*SetTextPosition(20, 20);*) OutText("Made by Stijn & John!!"); (* write the text *) position.x:=0; (* initiele positie*) position.y:=2; motorON:=FALSE; richCoord[NOORD].x:=0; richCoord[NOORD].y:=-1; richCoord[WEST].x:=-1; richCoord[WEST].y:=0; richCoord[ZUID].x:=0; richCoord[ZUID].y:=1; richCoord[OOST].x:=1; richCoord[OOST].y:=0; END Robot.