ПРИЛОЖЕНИЕ D
ПРИМЕРЫ ПРОГРАММ
Это приложение содержит некоторые примеры программ, де-
монстрирующих возможности ZX SPECTRUM.
Первая из этих программ требует ввести дату и день недели, который
соответствует этой дате.
10 REM convert date to dav
20 DIM D$(7,6): REM davs of week
30 FOR N«1 TO 7: READ D$: NEXT N
40 DIM M(12): REM lenght of months
50 FOR N*1 TO 12: READ M(N): NEXT N
100 REM input date
110 INPUT "Dav ?";DAY
120 INPUT "Month ?";MONTH
130 INPUT "Year (20 th centurv only) ?";YEAR
140 IF YEARTHEN PRINT "20 th centurv starts at 1901":
GO TO 100
150 IF YEAR2000 THEN PRINT " 20 th centurv at 2000
GO TO 100
160 IF MONTH THEN GO TO 210
170 IF MONTHI2 THEN GO TO 210
180 IF YEAR/4-INT (YEAR/4)=0 THEN LET M(2)=29:
REM leap vear
190 IF DAYM(MONTH) THEN PRINT "This month has only";
M(MONTH);" days.": GO TO 500
200 IF DAYO THEN GO TO 300
210 PRINT "Stuff and nonsense. Give me a real date."
220 GO TO 500
300 REM convert date to number of days since start of century
310 LET Y-YEAR-1901
320 LET B-365*Y+INT (Y/4): REM number of days to start of year
330 FOR N-l TO MONTH-1: REM add on previous month
340 LET B-B+M(N): NEXT N
350 LET B-B+DAY
400 REM convert to day of week
410 LET B-B-74NT <B/7)+l
420 PRINT DAY;" / ";MONTH;" / ";YEAR
430 FOR N-6 TO 3 STEP -1: REM remove trailing spaces
440 IF D$(B,N) - " THEN GO TO 460
450 NEXT N
460 LET E$-D$(BTON)
470 PRINT " is a ";E$;" day "
500 LET M<2)»28: REM restore februarv
510 INPUT " again ?";A$
520 IF А$-ипи THEN GO TO 540
530 IF A$"n" THEN GO TO 100
1000 REM days of week
1010 DATA 44monVfues","wednes"
1020 DATA "thure'Y'fri'Y'satur'Y'sun"
1100 REM lengths of months
1110 DATA 31,28,31,30,31,30
1120 DAT 31,31,30,31,30.31
Эта программа устанавливает соответствие между ярдом, футом и дюй-
мом'
10 INPUT " yards ? ^yd," feet ? ":ft." inches ? in
40 GO SUB 2000: REM print the values
50 PRINT'"-4*;
70 GO SUB 1000: REM the adjustment
80 GO SUB 2000: REM print the adjusted values
90 PRINT
100 GO TO 10
1000 REM subroutine to adjust yd, ft. in to the normal farm
for yards, feet and inches
1010 LET ine36*yd+l2*ft+in: REM now everything is in inches
1030 LET SeSGN in: LET in=ABS in: REM we work with in positive,
holding its sign in s
1060 LET ft=INT(in/12): LET in-<in-12*fO*S: REM now in is ok
1080 LET vd-INT <ft/3)*S: LET ft-ft*S-3#yd: RETURN
2000 REM subroutine to print vd, ft and in
2010 PRINT yd;" yd 44;ft;" ft ";in;" in";: RETURN
Эта программа моделирует выбрасывание монеты для игры в «китайку»:
5 RANDOMIZE
10 FOR М«1 ТО 6: REM for 6 throws
20 LET 00: REM initialize coin total to 0
30 FOR N=1 TO 3: REM for 3 coins
40 LET OC+2+INT (2*RND)
50 NEXT N
60 PRINT 44 ";
70 FOR N-l TO 2: REM 1st for the thrown hexagram,
2nd for the changes
80 PRINT"—w;
90 IF 07 THEN PRINT "-";
100 IF C«8 THEN PRINT 44 ";
110 IF C-6 THEN PRINT 44x";: LET C=7
120 IF C-9 THEN PRINT 440";: LET 08
130 PRINT 44— "
140 NEXT N
150 PRINT
160 INPUT A$
170 NEXT M: NEW
Для запуска программы введите её в компьютер, запустите на выпол-
нение, а затем нажмите клавишу ENTER пять раз для получения двух гекса-
грамм. Посмотрите китайскую «книгу изменений». Текст будет описывать
ситуацию и последовательность соответствующих этому действий, а Вы дол-
жны оценить глубину параллелей между ней и Вашей собственной жизнью
Нажмите клавишу ENTER шестой раз и программа будет обнуляться -
это избавит Вас от легкомысленного использования результатов.
Многие пользователи найдут тексты всегда более вероятными, нежели
они сами могут это предполагать.
Следующая программа - игра «ящеры». Вы задумываете название неко-
торого животного, а компьютер пытается его отгадать, задавая Вам вопросы,
на которые Вы должны отвечать «да» или «нет». Если компьютер не был зна-
ком ранее с таким животным, то он попросит Вас задать ему наводящие воп-
росы, которые помогут ему найти правильный ответ или он попросит Вас
предложить ему задать название нового животного:
5 REM pangolins
10 LET N0=100: REM number of questions and animals
15 DIM Q*(NQ,50): DIM A(NQ,2): DIM R$(l)
20 LETOF-8
30 FORN-1 TOQF/2-1
40 READ Q$(N): READ A(N,1): READ A(N,2)
50 NEXT N
60 FOR N«N TO QF-1
70 READ Q$(N): NEXT N
100 REM start playing
110 PRINT "Think of ал an imal.V Press anv kev to continue"
120 PAUSE 0 " "
130 LET C«1: REM start with 1st question
140 IF A(C,1)=0 THEN GO TO 300
150 LET P$«Q$(C): GO SUB 910
160 PRINT "7 ": GO SUB 1000
170 LET IN-1: IF R$-"Y" THEN GO TO 210
180 IF R$-"y" THEN GO TO 210
190 LET IN-2: IF R$«Mn" THEN GO TO 210
200 IF RJ^N" THEN GO TO 150
210 LET C-A<C,IN): GO TO 140
300 REM animal
310 PRINT "are you thinking of"
320 LET P$«Q$<C): GO SUB 900: PRINT " ? "
330 GO SUB Г000
340 IF Rf^Y" THEN GO TO 400
350 IF Rf-'V THEN GO TO 400
360 IF RS-"N" THEN GO TO 500
370 IF R$-"n" THEN GO TO 500
380 PRINT "answer me properly when ГпГ,"talking to you.":
GO TO 300
400 REM quessed it
410 PRINT "I thouqht as much.": GO TO 800
500 REM new animal
510 IF QFNQ-1 THEN PRINT "I'm sure your animal is very",
"interesting, but I don't have", "room For it just now.":
GO TO 800
520 LET 0$ <GF)-Q$ (C): REM move old animal
530 PRINT " what is it,then ? ": INPUT Q$(GF+1)
540 PRINT "tell me a question which dist- ."inquishes between"
550 LET PS-QS(OF): GO SUB 900: PRINT " and -
560 LET PH>$(QF+1): GO SUB 900: PRINT " "
570 INPUT S$:LErB-LENS$
58Q IF S$(B)"ЩГ THEN LET B-B-l
590 LET 0$ (C)-S$ (TO B): REM insert questiort
600 PRINT "What is the answer for"
610 LET P$-Q$CQF+1): GO SUB 900: PRINT " ? "
620 GO SUB 1000
630 LET IN-1: LET IO-2: REM answers for new and old animals
640 IF R$~"YH THEN GO TO 700
650 IF R$«V THEN GO TO 700
660 LET IN-2: LET IO-l
670 IF R$e"N" THEN GO TO 700
680 IF R$«"iT THEN GO TO 700
690 PRINT "Thet's no good": GO TO 600
700 REM update answers
710 LET A(CJN)«QF+1: LET A(C,IO)»QF
720 LET QF-QF+2: REM next free animal space
730 PRINT "That fooled me."
800 REM again? _ 1ЛЛЛ
810 PRINT "Do you want another go ?": GO SUB 1000
820 IF R$»"Y" THEN GO TO 100
830 IF R$«"v" THEN GO TO 100
840 STOP "
900 REM print without trailing spaces
905 PRINT"";
910 FOR N«50 TO 1 STEP-1
920 IF P$(N)" " THEN GO TO 940
930 NEXT N
940 PRINT P$( TON);: RETURN
1000 REM get replv
1010 INPUT R$: IF R$«" " THEN RETURN
1020 LET R$*R$(1): RETURN
2000 REM initial animals
2010 DATA "Does it live in the sea",4,2
2020 DATA "Is it scalv",3,5
2030 DATA "Does it eat ants",6,7
2040 DATA "a whale","a blancmange" "a pangolin","an ant"
Следующая программа рисует на экране «union flag »
5 REM Union flag
10 LET R-2: LET W«7: LET B-l
20 BORDER 0: PAPER 8: INK W: CLS
30 REM black in bottom of screen
40 INVERSE 1
50 FOR N=40 TO 0 STEP -8
60 PLOT PAPER 0;7,N: DRAW PAPER 0;241,0
70 NEXT N: INVERSE 0
100 REM draw in white parts
105 REM st. Georgr
110 FOR N=0 TO 7
120 PLOT 104+N,175: DRAW 0,-35
130 PLOT 151-N,175: DRAW 0,-35
140 PLOT 15l-N,48: DRAW 0,35
150 PLOT 104+N,48: DRAW 0,35
160 NEXT N
200 FOR N=0 TO 11
210 PLOT 0,139-N: DRAW 111,0
220 PLOT 255,139-N: DRAW-111,0
230 PLOT 255,84+N: DRAW-111,0
240 PLOT 0,84+N: DRAW 111,0
250 NEXT N
300 REM St. Andrew
310 FOR N"0 TO 35
320 PLOT 1+2*N,175-N: DRAW 32,0
330 PLOT 224-2*N,175-N: DRAW 16,0
340 PLOT 254-2*N,48+N: DRAW -32,0
350 PLOT 17+2*N,48+N: DRAW 16,0
360 NEXT N
370 FOR N=0 ТО 19
380 PLOT 185+2*N,140+N: DRAW 32,0
390 PLOT 200+2*N,83-N: DRAW 16,0
400 PLOT 39-2*N,83-N: DRAW 32,0
410 PLOT 54-2*N,140+N: DRAW-16,0
420 NEXT N
425 REM fill in extra bits
430 FOR N=0 TO 15
440 PLOT 255,160+N: DRAW 2*N-30,0
450 PLOT 0,63-N: DRAW 31-2*N,0
460 NEXT N
470 FOR N=0 TO 7
480 PLOT 0,160+N: DRAW!4-2*N,0
485 PLOT 255,63-N: DRAW 2*N-15,0
490 NEXT N
500 REM red stripes
510 INVERSE 1
520 REM st. George
530 FOR N=96 TO 120 STEP 8
540 PLOT PAPER R;7,N: DRAW PAPER R;241,0
550 NEXT N
560 FOR N-l 12 TO 136 STEP 8
570 PLOT PAPER R;N,168: DRAW PAPER R;0,-113
580 NEXT N
600 REM st. Patrick
610 PLOT PAPER R; 170,140: DRAW PAPER R;70,35
620 PLOT PAPER R; 179,140: DRAW PAPER R;70,35
630 PLOT PAPER R; 199,83: DRAW PAPER R;56,-28
640 PLOT PAPER R;184,83: DRAW PAPER R;70,-35
650 PLOT PAPER R;86,83: DRAW PAPER R;-70,-35
660 PLOT PAPER R;72,83: DRAW PAPER R;-70,-35
670 PLOT PAPER R;56,140: DRAW PAPER R;-56,28
680 PLOT PAPER R,71,140: DRAW PAPER R;-70,35
690 INVERSE 0: PAPER 0: INK 7
Если Вы не англичанин, то можете изобразить свой флаг.
Следующая программа - это игра в слова. Первый игрок вводит слово, а
второй его отгадывает.
5 REM hagman
10 REM set up screen
20 INK 0: PAPER 7: CLS
30 LET X-240: GO SUB 1000: REM draw men
40 PLOT 238,128: DRAW 4,0: REM mouth
100 REM set up word
110 INPUT W$: REM word to guess
120 LET BeLEN W$: LET "
130 FOR N«2 TO B: LET V$=V$+" 44
140 NEXT N: REM V$ * word guessed so far
150 LET С=0: LET I>0: REM guess & mistake counts
160 FORN-OTOB-1
170 PRINT AT 20,N;"-";
180 NEXT N: REM write "-"s instead of letters
200 INPUT "Guess a letter ";G$
210 IF G$-"n THEN GO 10 200
220 LET G$*G$(1): REM 1st letter onlv
230 PRINT AT 0,C;G$
240 LET OC+1: LET U$»V$
250 FOR N-l TO B: REM update guessed word
260 IF W$(n)-G$ THEN LET V$(n)«G$
270 NEXT N
280 PRINT AT 19,0;V$
>90 IF V$®W$ THEN GO TO 500: REM word guessed
Ю0 IF V$U$ THEN GO TO 200: REM guessed was right
400 REM draw next part of gallows
410 IF D=8 THEN GO TO 600: REM hanged
420 LETEMD+l
430 READ X0,Y0,X,Y
440 PLOT X0,Y0: DRAW X,Y
450 GO TO 200
500 REM free man
510 OVER 1: REM rub out man
520 LET X-240: GO SUB 1000
530 PLOT 238,128: DRAW 4,0: REM mouth
540 OVER 0: REM redraw man
550 LET X~146: GO-SUB 1000
560 PLOT 143,129: DRAW 6,0,Pl/2: REM smile
570 GOTO 800
600 REM hang man
610 OVER 1: REM rub out floor
620 PLOT 255,65: DRAW -48,0
630 DRAW 0,-48: REM open trapdoor
640 PLOT 238,128: DRAW 4,0: REM rub out mouth
650 REM move limbs
655 REM arms
660 PLOT 255,117: DRAW -15.-15: DRAW -15,15
670 OVERO
680 PLOT 236,81: DRAW 4,21: DRAW 4,-21
690 OVER I: REM legs
700 PLOT 255,66: DRAW -15,15: DRAW -15,-15
710 OVERO
720 PLOT 236,60: DRAW 4,21: DRAW 4,-21
730 PLOT 237,127: DRAW 6,0,-Pl/2: REM frown
740 PRINT AT 19,0;W$
800 INPUT " again? ":A$
810 IF A$=.....rHEN GO TO 850
820 LET A$=A$( 1)
830 FF AS^' n" THEN STOP
840 IF A$(1)*"N" THEN STOP
850 RESTORE : GO TO 5
1000 REM draw man at column x
1010 REM head
1020CIRCLE X, 132,8
1030 PLOT X+4,134: PLOT X-4,134: PLOT X.131
1040 REM bodv
1050 PLOT X,l23: DRAW 0,-20
1055 PLOT X,101: DRAW 0,-19
1060 REM legs
1070 PLOT X-15,66: DRAW 15,15: DRAW 15,-15
1080 REM arms
1090 PLOT X-15,117: DRAW 15,-15: DRAW 15,15
1100 RETURN
2000 DATA 120,65,135,0,184,65,0,91
2010 DATA 168,65,16,16,184,81,16,-16
2020 DATA 184,156,68,0,184,140,16,16
2030 DATA 204,156,-20,-20,240,156,0,-16
2020 DATA 184,156,68,0,184,140,16,16
2030 DATA 204,156,-20,-20,240,156,0,-16