1 REMark linegame (c) Prof. Timo Salmi, University of Vaasa, Finland
2 REMark Wed 1986 Dec 10 12:00:00
3 REMark version 1.0
4 :
100 CLEAR:kokoaika=DATE:mp=36:bon=1
110 DIM ohj$(8),tpvm$(6):ohj$="LINEGAME":tpvm$="101286"
120 p_nimio:RANDOMISE:paras%=0
140 REPeat runko
160 DIM mj$(mp),ala$(mp),yla$(mp)
170 n%=27
180 DIM kx%(n%)
190 DIM ky%(n%)
200 DIM sade%(n%)
210 DIM arvo%(n%)
220 DIM osuma%(n%)
230 DIM vari%(6)
240 vari%(1)=6:vari%(2)=2:vari%(3)=4:vari%(4)=3
250 vari%(5)=1:vari%(6)=5:origo_x%=1:origo_y%=1
260 max_kierros%=3
290 p_perusikkunat:levg3%=166
300 p_sovita_vakioikkuna
310 p_arvot_vakioikkuna
320 p_kierrosikkuna
330 p_pisteikkuna
340 p_huippu_pisteikkuna
350 p_tangenttikkuna
360 p_kyselyikkuna
390 SCALE 100,-origo_x%,-origo_y%:p_akselit
410 p_odota_alku
420 p_arvonta:p_odota_loppu
430 p_piirra_ympyrat
460 pisteet%=0
470 kierros%=0
480 REPeat loop
490 kierros%=kierros%+1
500 IF kierros%>max_kierros% THEN EXIT loop
510 AT#3,0,8:PRINT#3,kierros%
520 a=f_kysyluku(("a? "),("-10000"),(" 10000"))
530 k=f_kysyluku(("k? "),("-10000"),(" 10000"))
540 kulma=INT(180*ATAN(k)/PI+.5):AT#5,0,8:CLS#5,4
550 CURSOR#5,140-12*LEN(kulma),0:PRINT#5,kulma;""
560 lisapisteet%=0
570 FOR i=1 TO n%
580 IF osuma%(i)=0 THEN
590 ero=f_etaisyys((kx%(i)),(ky%(i)),(a),(k))
600 IF ero<=sade%(i) THEN
610 p_beep2:osuma%(i)=1
620 lisapisteet%=lisapisteet%+arvo%(i)
630 pisteet%=pisteet%+arvo%(i)
640 p_ympyra(kx%(i)),(ky%(i)),(sade%(i)),(arvo%(i)),(1)
650 END IF
660 END IF
670 END FOR i
680 p_suora(a),(k)
690 AT#4,0,9-LEN(pisteet%):INK#4,6:PRINT#4,pisteet%
700 IF pisteet%>950 THEN EXIT loop
710 IF (kierros%=3 AND pisteet%>=43) OR (kierros%>3 AND lisapisteet%>=10+2*kierros%) THEN
720 FOR i=1 TO n%:osuma%(i)=0:END FOR i
730 p_bonus_ilmoitus
740 max_kierros%=max_kierros%+1
750 p_odota_alku:p_arvonta:p_odota_loppu
760 CLS:p_akselit:p_piirra_ympyrat
770 CLS#6:CSIZE#6,2,0
780 END IF
790 END REPeat loop
810 IF pisteet%>paras% THEN
820 IF paras%>0 THEN FLASH#4,1
830 AT#4,0,9-LEN(pisteet%):INK#4,6
840 PRINT#4,pisteet%:FLASH#4,0
850 paras%=pisteet%
860 END IF
880 IF f_vielako:NEXT runko:ELSE :EXIT runko:END IF
900 END REPeat runko
930 FOR i=3 TO 7:CLOSE#i:END FOR i
940 STOP
960 DEFine PROCedure p_akselit
970 LOCal i:INK 5
980 LINE -origo_x%,0 TO 102-origo_x%,0
990 LINE 0,-origo_y% TO 0,102-origo_y%
1000 FOR i=-100 TO 100 STEP 10
1010 LINE i,0 TO i,2+(i MOD 50=0)
1020 LINE 0,i TO 2+(i MOD 50=0),i
1030 END FOR i
1040 END DEFine p_akselit
1060 DEFine PROCedure p_arvonta
1070 LOCal i,j,vali,iapu
1080 FOR i=1 TO n%
1090 kx%(i)=RND(7-origo_x% TO 93-origo_x%)
1100 ky%(i)=RND(7-origo_y% TO 93-origo_y%):iapu=i
1110 SELect ON iapu
1120 = 1 TO  7:arvo%(i)=1
1130 = 8 TO 13:arvo%(i)=2
1140 =14 TO 18:arvo%(i)=3
1150 =19 TO 22:arvo%(i)=4
1160 =23 TO 25:arvo%(i)=5
1170 =REMAINDER :arvo%(i)=6
1180 END SELect
1190 sade%(i)=8-arvo%(i)
1200 IF sade%(i)<=0 THEN sade%(i)=2
1220 IF f_lahella((kx%(i)),(sade%(i))) THEN GO TO 1090
1230 IF f_lahella((ky%(i)),(sade%(i))) THEN GO TO 1090
1250 IF i=1 THEN GO TO 1310
1260 FOR j=1 TO i-1
1270 vali=(kx%(i)-kx%(j))^2+(ky%(i)-ky%(j))^2
1280 vali=SQRT(vali)
1290 IF vali<sade%(i)+sade%(j)+2 THEN GO TO 1090
1300 END FOR j
1310 END FOR i
1320 END DEFine p_arvonta
1340 DEFine PROCedure p_ympyra(ksx%,ksy%,sad%,arv%,fll%)
1350 FILL fll%
1360 INK vari%(arv%)
1370 CIRCLE ksx%,ksy%,sad%:FILL 0
1380 END DEFine p_ympyra
1400 DEFine PROCedure p_piirra_ympyrat
1410 LOCal i
1420 FOR i=1 TO n%
1430 p_ympyra(kx%(i)),(ky%(i)),(sade%(i)),(arvo%(i)),(0)
1440 END FOR i
1450 END DEFine p_piirra_ympyrat
1470 DEFine PROCedure p_suora(a,k)
1480 LOCal x1,x2,y1,y2
1490 IF ABS(k)<=1 THEN
1500 x1=-origo_x%:y1=a+k*x1
1510 x2=100-origo_x%:y2=a+k*x2
1520 ELSE
1530 y1=-origo_y%:x1=(y1-a)/k
1540 y2=100-origo_y%:x2=(y2-a)/k
1550 END IF
1560 INK 7:LINE x1,y1 TO x2,y2
1570 END DEFine p_suora
1590 DEFine PROCedure p_odota_alku
1600 INK 5:AT 10,5:FLASH 1
1610 PRINT"PLEASE WAIT...":FLASH 0
1620 END DEFine p_odota_alku
1640 DEFine PROCedure p_odota_loppu
1660 AT 10,5:PRINT FILL$(" ",14)
1670 END DEFine p_odota_loppu
1690 DEFine PROCedure p_bonus_ilmoitus
1700 LOCal cl%:cl%=6
1710 CLS#cl%:INK#cl%,6:CSIZE#cl%,3,1:FLASH#cl%,1
1720 CURSOR#cl%,40,10:PRINT#cl%,"BONUS":FLASH#cl%,0
1730 INK#cl%,5:CURSOR#cl%,48,40:PRINT#cl%,"LINE"
1740 END DEFine p_bonus_ilmoitus
1760 DEFine FuNction f_lahella(piste%,raja%)
1770 IF piste%>-raja%-4 AND piste%<raja%+4 THEN
1780 RETurn 1:ELSE :RETurn 0:END IF
1790 END DEFine f_lahella
1810 DEFine FuNction f_etaisyys(x0%,y0%,a,k)
1820 RETurn ABS(y0%-a-k*x0%)/SQRT(1+k^2)
1830 END DEFine f_etaisyys
1850 DEFine PROCedure p_perusikkunat
1860 WINDOW#1,levg%,215,alkug%,15:BORDER#1,2,1
1870 WINDOW#1,295,215,alkug%+162,15
1880 WINDOW#0,levg%, 25,alkug%,231
1890 PAPER#1,0:BORDER#1,2,1:CSIZE#1,2,0:CLS#1
1900 PAPER#0,0:CSIZE#0,2,0
1910 END DEFine p_perusikkunat
1930 DEFine PROCedure p_sovita_vakioikkuna
1940 OPEN#3,con_:WINDOW#3,levg3%,14,alkug%,15
1950 BORDER#3,2,1:INK#3,5:CSIZE#3,2,0:CLS#3
1960 PRINT#3,"FIT y=a+kx"
1970 END DEFine p_sovita_vakioikkuna
1990 DEFine PROCedure p_arvot_vakioikkuna
2000 LOCal i
2010 WINDOW#3,levg3%,24,alkug%,27
2020 PAPER#3,0:BORDER#3,2,1:CLS#3
2030 INK#3,5:PRINT#3,"SCORE VALUES:"
2040 FOR i=1 TO 6
2050 INK#3,vari%(i)
2060 PRINT#3,i!;
2070 END FOR i
2080 END DEFine p_arvot_vakioikkuna
2100 DEFine PROCedure p_kierrosikkuna
2110 WINDOW#3,levg3%,24,alkug%,49
2120 CSIZE#3,3,1:BORDER#3,2,1:INK#3,5:CLS#3
2130 PRINT#3,"LINE :";
2140 END DEFine p_kierrosikkuna
2160 DEFine PROCedure p_pisteikkuna
2170 OPEN#4,con_:WINDOW#4,levg3%,24,alkug%,71
2180 PAPER#4,0:CSIZE#4,3,1:BORDER#4,2,1:INK#4,5:CLS#4
2190 PRINT#4,"SCORE: ";
2200 END DEFine p_pisteikkuna
2220 DEFine PROCedure p_huippu_pisteikkuna
2230 OPEN#7,con_:WINDOW#7,levg3%,24,alkug%,93
2240 PAPER#7,0:CSIZE#7,3,1:BORDER#7,2,1:INK#7,5:CLS#7
2250 PRINT#7,"TOP  :";:INK#7,2
2260 AT#7,0,9-LEN(paras%):PRINT#7,paras%
2270 END DEFine p_huippu_pisteikkuna
2290 DEFine PROCedure p_tangenttikkuna
2300 OPEN#5,con_:WINDOW#5,levg3%,14,alkug%,115
2310 PAPER#5,0:CSIZE#5,2,0:BORDER#5,2,1:INK#5,5:CLS#5
2320 PRINT#5,"atan(k)":OVER#5,1:CURSOR#5,80,0
2330 PRINT#5,":":OVER#5,0
2340 END DEFine p_tangenttikkuna
2360 DEFine PROCedure p_kyselyikkuna
2370 OPEN#6,con_:WINDOW#6,levg3%,74,alkug%,142
2380 PAPER#6,0:CSIZE#6,2,0:BORDER#6,2,1:INK#6,5:CLS#6
2390 END DEFine p_kyselyikkuna
2410 DEFine FuNction f_mem
2420 RETurn PEEK_L(163856)-PEEK_L(163852)
2430 END DEFine f_mem
2450 DEFine PROCedure p_beep1
2460 IF bon THEN BEEP 4000,70
2470 END DEFine p_beep1
2490 DEFine PROCedure p_beep2
2500 IF bon THEN BEEP 500,12
2510 END DEFine p_beep2
2530 DEFine PROCedure p_tausta
2540 MODE 8:levg%=456:alkug%=INT((512-levg%)/2)
2550 WINDOW 512,256,0,0:PAPER 2,1,3:CLS
2560 OPEN#3,con_:WINDOW#3,levg%,26,alkug%,230
2570 PAPER#3,0:CLS#3:BORDER#3,2,1:CSIZE#3,3,1
2580 END DEFine p_tausta
2600 DEFine PROCedure p_otsake_teksti(ik%)
2610 LOCal il1%,il2%,il%,i:il%=3
2620 CURSOR#3,5,0:INK#3,ik%:PRINT#3,ohj$
2630 il2%=levg%-(4+4*il%)*LEN(tpvm$)-9
2640 il1%=(il2%+(4+4*il%)*LEN(ohj$)-35-40*il%)/2
2650 INK#3,ik%:CURSOR#3,il1%,0:RESTORE 2660
2660 DATA 84,105,109,111,32,83,97,108,109,105
2670 FOR i=1 TO 10:READ il%:PRINT#3,CHR$(il%);:END FOR i
2680 INK#3,ik%:CURSOR#3,il2%,0:PRINT#3,tpvm$
2690 END DEFine p_otsake_teksti
2710 DEFine PROCedure p_nimio
2720 LOCal i:p_tausta
2730 FOR i=1 TO 2
2740 p_otsake_teksti(1)
2750 OVER#3,1:SCROLL#3,1:PAN#3,1.5
2760 END FOR i
2770 p_otsake_teksti(6):CLOSE#3
2780 END DEFine p_nimio
2800 DEFine FuNction f_digval(mj$)
2810 LOCal sl$(13),il,nrl,pl%,ml%:nrl=0:pl%=0
2820 ok=0:sl$="1234567890-+.":ml%=LEN(mj$)
2830 IF ml%=0 THEN RETurn 0
2840 FOR il=1 TO ml%
2850 IF mj$(il)INSTR sl$=0 THEN RETurn 0
2860 END FOR il
2870 FOR il=1 TO 10
2880 IF sl$(il)INSTR mj$>0:nrl=1:END IF :END FOR il
2890 IF nrl=0 THEN RETurn 0
2900 FOR il=1 TO ml%
2910 IF mj$(il)=".":pl%=pl%+1:END IF :END FOR il
2920 IF pl%>1:RETurn 0:END IF :pl%=0
2930 FOR il=1 TO ml%
2940 IF mj$(il)="-" OR mj$(il)="+" THEN pl%=il
2950 END FOR il
2960 IF pl%>1:RETurn 0:END IF :ok=1:RETurn mj$
2970 END DEFine f_digval
2990 DEFine FuNction f_kysyluku(mj$,ala$,yla$)
3000 LOCal kysy,lukul,ok,cl%,vl$(mp):cl%=6
3010 REPeat kysy
3020 INK#cl%,5:PRINT#cl%,mj$;
3030 clb%=KEYROW(0):INPUT#cl%,vl$
3040 lukul=f_digval((vl$))
3050 IF NOT ok:p_beep1:NEXT kysy:END IF
3060 IF lukul<ala$ OR lukul>yla$ THEN
3070 INK#cl%,2:p_beep1
3080 PRINT#cl%,"MIN"!ala$:PRINT#cl%,"MAX"!yla$
3090 NEXT kysy
3100 END IF
3110 RETurn lukul
3120 END REPeat kysy
3130 END DEFine f_kysyluku
3150 DEFine FuNction f_vielako
3160 LOCal key%,cl%,loop:cl%=6
3170 PAPER#cl%,0:CLS#cl%:INK#cl%,5:CSIZE#cl%,3,1
3180 CURSOR#cl%,8,10:PRINT#cl%,"GAME OVER"
3190 CSIZE#cl%,2,0
3200 CURSOR#cl%,20,40:PRINT#cl%,"AGAIN: F3"
3210 CURSOR#cl%,20,50:PRINT#cl%,"QUIT: ESC";
3220 clb=KEYROW(0)
3230 REPeat loop
3240 key%=CODE(INKEY$(-1))
3250 IF key%=240 THEN EXIT loop
3260 IF key%= 27 THEN EXIT loop
3270 END REPeat loop
3280 RETurn key%=240
3290 END DEFine f_vielako
3310 DEFine PROCedure reset(i)
3320 LOCal il:MODE i
3330 FOR il=1,2:OPEN#il,con_:END FOR il
3340 WINDOW 512,256,0,0:PAPER 0:CLS
3350 WINDOW#0,448,40-(i=4),32,216+(i=4)
3360 WINDOW#2,448,200,32,16:PAPER#2,1:INK#2,7
3370 WINDOW 448+8*(i=4),200+2*(i=4),32-4*(i=4),16-(i=4)
3380 PAPER 2*(i=8):BORDER (i=4),4*(i=4)
3390 FOR il=0,1,2:CSIZE#il,(i=4)+2*(i=8),0:END FOR il
3400 PAPER#0,0:INK#0,7-3*(i=0):INK 7:CLS
3410 SCALE 100,0,0:FILL 0
3420 END DEFine reset
3440 STOP
3450 vsave 1:STOP
3460 vsave 2:STOP
3470 vsave 3:STOP
3480 vsave 4:STOP
3490 vsave 5:STOP
3500 vsave 6:STOP
3510 DEFine PROCedure vsave(dr)
3520 LOCal avl$(42),bvl$(42),dvl$(6,5):avl$="linegame"
3530 bvl$=DATE$:bvl$=bvl$(1 TO 4)
3540 IF bvl$<>1992 THEN
3550 PRINT#0,DAY$!DATE$!"Not saved, set SDATE"
3560 BEEP 4000,12:STOP:END IF
3570 ver1%=1:ver2%=-1
3580 dvl$(1)="mdv1_":dvl$(2)="mdv2_"
3590 dvl$(3)="fdk1_":dvl$(4)="fdk2_"
3600 dvl$(5)="ram1_":dvl$(6)="ram2_"
3610 bvl$=dvl$(dr)&avl$
3620 DELETE bvl$:OPEN_NEW#3,bvl$:ver%=ver2%+1
3630 PRINT#3,"1 REMark ";avl$!"(c) Timo Salmi"
3640 PRINT#3,"2 REMark ";DAY$!DATE$
3650 PRINT#3,"3 REMark version"!ver1%;".";ver%
3660 PRINT#3,"4 :"
3670 LIST#3,100 TO 32110
3680 PRINT#3,"32120  ver1%=";ver1%;":ver2%=";ver%
3690 LIST#3,32130 TO:CLOSE#3
3700 PRINT#0,"Saved"!bvl$!"version"!ver1%;".";ver%
3710 END DEFine vsave
