10 REM SNAKE - DIE BILDSCHIRM-SCHLANGE
20 REM A.HERRMANN	18.12.83
30 REM
70 DIM Q%(200,2) : IMAX%=200
80 FF$=CHR$(&H0C)
82 ESC%=&H1B
84 ESC$=CHR$(ESC%)
88 PON%=1 : POF%=0	:REM PEN ON/OFF
90 REM
91 DEF FNR1%     = FIX(RND*2)*2-1
92 DEF FNR2%(R%) = FIX(RND*2)+R%
94 DEF FNR3%     = FIX(RND*3)-1
96 R=.3
98 REM
100 PRINT FF$;"SNAKE - die Bildschirm-Schlange" : PRINT
102 XMIN%=0 : YMIN%=0 : XMAX%=159 : YMAX%=95
104 PRINT "Fenster ";XMIN%;YMIN%,XMAX%;YMAX%
106 CALL WINDOW(XMIN%,YMIN%,XMAX%,YMAX%)
108 XMAX%=XMAX%-XMIN% : XMIN%=0
109 YMAX%=YMAX%-YMIN% : YMIN%=0
110 PRINT "(Abbruch mit ESC)" : PRINT
111 INPUT "Laenge (0 = Ende) = ",L%
112 IF L%=0 GOTO 1000
114 IF L%>IMAX% GOTO 111
120 FOR I%=0 TO L% : Q%(I%,1)=0 : Q%(I%,2)=0 : NEXT I%
130 L%=L%+1
150 PRINT FF$;ESC$;"A "	: REM CLEAR SCREEN, CURSOR OFF
160 CALL FRAME
170 REM
190 IX%=0 : IY%=0
192 I%=0 : EXIT%=0
200 ON IX%+2 GOTO 210,310,410
210 ON IY%+2 GOTO 220,230,240
220 GOSUB 920 : IF IX%=0 THEN GOSUB 924	: GOTO 500	:REM -1 -1
230			      GOSUB 932	: GOTO 500	:REM -1  0
240 GOSUB 920 : IF IX%=0 THEN GOSUB 926	: GOTO 500	:REM -1  1
300 REM
310 ON IY%+2 GOTO 320,330,340
320 GOSUB 930			: GOTO 500	:REM  0 -1
330 IX%=1        : IY%=1	: GOTO 500	:REM  0  0
340 GOSUB 930			: GOTO 500	:REM  0  1
400 REM
410 ON IY%+2 GOTO 420,430,440
420 GOSUB 922 : IF IX%=1 THEN GOSUB 924	: GOTO 500	:REM  1 -1
430			      GOSUB 932	: GOTO 500	:REM  1  0
440 GOSUB 922 : IF IX%=1 THEN GOSUB 926 : GOTO 500	:REM  1  1
490 REM
500 XX%=X%+IX% : YY%=Y%+IY%
510 IF XX%>XMIN% AND XX%<XMAX% GOTO 610
520 IX%=-IX% : XX%=XX%+IX%
530 ON IY%+2 GOTO 610,540,610
540 GOSUB 912
600 REM
610 IF YY%>YMIN% AND YY%<YMAX% GOTO 710
620 IY%=-IY% : YY%=YY%+IY%
630 ON IX%+2 GOTO 710,640,710
640 GOSUB 910 
700 REM
710 X%=Q%(I%,1) : Y%=Q%(I%,2)
720 CALL PUTP(X%,Y%,POF%) 
721 REM PRINT "POF";X%;Y%,
730 X%=XX% : Y%=YY%
740 Q%(I%,1)=X% : Q%(I%,2)=Y%
750 II%=I%
752 CALL PUTP(X%,Y%,PON%) 
754 II%=(II%+1) MOD L%
756 X%=Q%(II%,1) : Y%=Q%(II%,2)
758 IF II%<>I% GOTO 752
759 REM PRINT "PON";X%;Y%,"I=";I%,IX%;IY%
760 I% = (I%+1) MOD (L%)
762 IF EXIT% GOTO 790
770 IF INP(5)=ESC% GOTO 810	: REM ESCAPE ?
780 IF X%<>0 OR Y%<>0 GOTO 200
781 REM PRINT "EXIT"
782 EXIT%=-1
784 J%=I%
786 GOTO 710
790 IF I%<>J% GOTO 710
800 REM
810 PRINT ESC$;"A";CHR$(&H22)	: REM CLEAR SCREEN, CURSOR ON
820 GOTO 100
900 REM
910 IF RND<R THEN IX%=FNR1%
911 RETURN
912 IF RND<R THEN IY%=FNR1%
913 RETURN
920 IF RND<R THEN IX%=FNR2%(-1)
921 RETURN
922 IF RND<R THEN IX%=FNR2%( 0)
923 RETURN
924 IF RND<R THEN IY%=FNR2%(-1) 
925 RETURN
926 IF RND<R THEN IY%=FNR2%( 0) 
927 RETURN
930 IF RND<R THEN IX%=FNR3% 
931 RETURN
932 IF RND<R THEN IY%=FNR3% 
933 RETURN
990 REM
1000 END
