10 REM PROGRAM TO SIMULATE A FRUIT MACHINE
20 REM TITLE IS GAMBLE.BAS AND PROVIDES  A
22 REM DEMONSTRATION OF THE RND RANDOM NUMBER GENERATOR FUNCTION.
30 GOSUB 4000 \REM FORM FEED
40 PRINT "PLAY THE FRUIT MACHINE WITH D.E.C. RT11/BASIC"
50 PRINT \PRINT "DO YOU KNOW HOW TO PLAY";
60 GOSUB 4100 \IF Z$="Y" THEN 500 \IF Z$="" THEN 500 
70 PRINT \PRINT "THIS FRUIT MACHINE HAS FOUR WHEELS OF FORTUNE,"
80 PRINT "EACH WHEEL HAS NINE FRUITS PLUS LUCKY STAR."
90 PRINT "YOU WILL COMMENCE PLAY WITH THE LOOSE CHANGE"
100 PRINT "IN YOUR POCKET (ASSESSED BY THE COMPUTER)."
110 PRINT "WHEN THE COMPUTER TYPES '?' IT IS EXPECTING A"
120 PRINT "'YES' OR 'NO' ANSWER- THE FIRST LETTER 'Y' OR 'N' WILL"
130 PRINT "SUFFICE.  THE FRUIT MACHINE HAS A RANDOM 'HOLD'"
140 PRINT "FACILITY AND A RANDOM 'GAMBLE' FACILITY WHICH WHEN "
150 PRINT "AVAILABLE YOU MAY HOLD ANY OR ALL OF"
160 PRINT "THE WHEELS AND/OR GAMBLE A WINNING LINE"
170 PRINT "TO DOUBLE YOUR WINNINGS A MAXIMUM OF THREE TIMES."
190 PRINT "THE MACHINE WILL RETIRE YOU WHEN IT THINKS YOU"
200 PRINT "HAVE WON ENOUGH MONEY IN WHICH CASE YOU HAVE BEATEN THE"
210 PRINT "MACHINE.   YOU LOSE WHEN YOU HAVE NO MONEY LEFT TO PLAY"
220 PRINT "WITH.   YOU MAY RETIRE FROM THE GAME AT ANY TIME AND COLLECT"
230 PRINT "YOUR WINNINGS.  A SPIN OF THE WHEEL COSTS YOU 5 CENTS."
240 PRINT "TYPE 'T' FOR A PRINT OF CASH IN HAND."
300 DATA " ****** "," CHERRY ","  PLUM  "," APPLE  ","STRAWBY "
301 DATA " PEACH  "," ORANGE "," LEMON  "," BANANA "," GRAPE  "
302 DATA 18
310 DATA 1,1,0,0,50,2,2,0,0,30
320 DATA 3,3,0,0,20,4,4,0,0,20
330 DATA 5,5,0,0,20,6,6,0,0,20
340 DATA 7,7,0,0,20,8,8,0,0,20
350 DATA 9,9,0,0,15,10,10,0,0,15
360 DATA 1,0,0,0,10,0,1,0,0,10
370 DATA 0,0,1,0,10,0,0,0,1,10
380 DATA 2,0,0,0,5,0,2,0,0,5
390 DATA 0,0,2,0,5,0,0,0,2,5
500 DIM R(4),S(4),F$(10),W(20,5),H(4)
510 FOR I=1 TO 10\READ F$(I)\NEXT I
520 READ L\FOR I=1 TO L\FOR J=1 TO 5\READ W(I,J)
530 NEXT J\NEXT I
540 PRINT "DO YOU WANT A PRINT OUT OF THE WINNING LINES";
550 GOSUB 4100 \IF Z$="N" THEN 850 \IF Z$="" THEN 850 
560 PRINT \PRINT "WINNING LINES ARE--"
570 PRINT "FOUR STARS '******' PAYS $100.00"
580 PRINT "FOUR IDENTICAL FRUITS PAY $25.00"
590 PRINT "THREE STARS IN ANY POSITION PAY $10.00"
600 PRINT "THREE IDENTICAL FRUITS IN ANY POSITION PAY $1.00"
700 PRINT "TWO PAIRS OF FRUITS IN ANY POSITION PAY $1.00"
800 FOR I=1 TO L\FOR J=1 TO 4
810 IF W(I,J)=0 THEN 830 
820 PRINT F$(W(I,J));\GO TO 835 
830 PRINT "        ";
835 NEXT J
840 PRINT "  PAYS "W(I,5);" CENTS."\NEXT I
850 PRINT \PRINT \FOR I=1 TO 4\H(I)=0\NEXT I
860 RANDOMIZE\M=FNR(Z)*10
870 PRINT "YOU HAVE "M;"CENTS TO PLAY WITH. "
880 PRINT "GOOD LUCK."\PRINT 
890 N=0\C=0
900 PRINT "TYPE 'H' FOR HELP IF YOU DO NOT UNDERSTAND."\PRINT 
910 GO TO 1008 
1000 M=M+C\C=0\IF M>0 THEN 1008 
1001 PRINT \PRINT "YOU HAVE NO MONEY LEFT TO PLAY WITH."
1002 PRINT "I HOPE YOU HAVE LEARNED YOUR LESSON."
1003 GOSUB 4400 
1008 PRINT "PLAY";\GOSUB 4100 \IF Z$<>"T" THEN 1010 
1009 PRINT \PRINT "YOUR TOTAL IS $"M/100;\GO TO 1008 
1010 IF Z$<>"H" THEN 1050 
1020 PRINT "IF YOU WISH TO RISK 5C ON THE NEXT SPIN OF"
1030 PRINT "THE WHEELS TYPE 'Y' OR JUST <CR>, IF YOU WISH TO RETIRE"
1040 PRINT "TYPE 'N'."\GO TO 1008 
1050 IF Z$<>"N" THEN 1120 
1060 IF N<30 THEN 1110 
1070 GOSUB 4000 
1080 PRINT "YOU'VE HAD A GOOD RUN FOR YOUR MONEY,"
1090 PRINT "AND TAKE $"M/100;" AWAY WITH YOU."
1100 PRINT "THANKS FOR THE GAME."\GO TO 4400 
1110 PRINT "YOU RETIRE-- VERY SENSIBLE TOO."\GO TO 1090 
1120 PRINT "        ";\M=M-5
1125 FOR I=1 TO 4\IF H(I)>0 THEN 1140 
1130 R(I)=FNR(Z)
1140 PRINT F$(R(I));\NEXT I
1150 IF R(1)+R(2)+R(3)+R(4)<>4 THEN 1170 
1160 PRINT "PAYS $100.00   JACKPOT!!!."\M=M+10000\GO TO 4300 
1170 IF R(1)<>R(2) THEN 1200 \IF R(2)<>R(3) THEN 1200 
1180 IF R(3)<>R(4) THEN 1200 
1190 PRINT "PAYS $25.00   JACKPOT!!!"\M=M+2500\GO TO 1000 
1200 FOR I=1 TO 4\S(I)=R(I)\NEXT I
1300 FOR I=1 TO 4\FOR J=1 TO 3\IF S(J)<=S(J+1) THEN 1320 
1310 A=S(J)\S(J)=S(J+1)\S(J+1)=A
1320 NEXT J\NEXT I
1330 IF S(1)+S(2)+S(3)<>3 THEN 1341 
1340 PRINT "PAYS $10.00   JACKPOT!!!"\M=M+1000\GO TO 1000 
1341 IF S(2)<>S(3) THEN 1350 \IF S(1)<>S(2) THEN 1343 
1342 PRINT "PAYS $1.00 "\C=100\GO TO 1390 
1343 IF S(3)<>S(4) THEN 1350 \GO TO 1342 
1350 IF S(1)<>S(2) THEN 1670 \IF S(3)<>S(4) THEN 1670 
1380 PRINT "PAYS $1.00 "\C=100\GO TO 1390 
1390 IF FNR(Z)>3 THEN 1520 \REM NO GAMBLE
1400 FOR I=1 TO 3\PRINT "GAMBLE";\GOSUB 4100 
1410 IF Z$<>"H" THEN 1470 
1420 PRINT \PRINT "YOU MAY GAMBLE YOUR WINNINGS OF "C;" CENTS"
1422 PRINT "UP TO THREE TIMES.  EACH GAMBLE HAS A EVEN CHANCE OF"
1440 PRINT "DOUBLING YOUR WINNINGS.  IF YOU LOSE A GAMBLE YOU LOSE"
1445 PRINT "YOUR WINNINGS."
1450 PRINT "TYPE 'Y' IF YOU WISH TO GAMBLE."
1460 PRINT "GAMBLE";\GOSUB 4100 \GO TO 1410 
1470 IF Z$<>"Y" THEN 1520 
1480 IF FNR(Z)>5 THEN 1500 
1482 PRINT "                                        WIN"\C=C+C\NEXT I
1490 GO TO 1520 
1500 PRINT "                                        LOSE"\C=0
1520 IF C>30 THEN 1550 \IF FNR(Z)>4 THEN 1550 
1530 PRINT "HOLD";\INPUT Z$
1540 IF Z$<>"" THEN 1560 
1550 FOR I=1 TO 4\H(I)=0\NEXT I\GO TO 1000 
1560 IF LEN(Z$)<>4 THEN 1610 
1565 PRINT "        ";
1570 FOR I=1 TO 4\IF SEG$(Z$,I,I)<>"Y" THEN 1590 
1580 H(I)=1\PRINT " HOLD   ";\GO TO 1600 
1590 H(I)=0\PRINT "        ";
1600 NEXT I\PRINT "  O.K.";\GOSUB 4100 
1602 IF Z$<>"N" THEN 1000 \GO TO 1530 
1610 PRINT "TO ENTER HOLD CONDITION REQUIRED"
1620 PRINT "TYPE FOUR CHATACTERS- 1 PER WHEEL."
1630 PRINT "WHERE HOLD IS REQUIRED TYPE 'Y',"
1640 PRINT "WHERE NO HOLD IS REQUIRED TYPE SOMETHING ELSE."
1650 PRINT "FOR EXAMPLE, TO HOLD THE SECOND AND FOURTH WHEELS TYPE '*Y*Y'."
1651 PRINT "IF NO HOLD IS REQUIRED TYPE <CR>."
1660 GO TO 1530 
1670 A=0\B=1
1680 FOR I=1 TO L\B=1
1690 FOR J=1 TO 4\IF W(I,J)=0 THEN 1810 
1700 IF R(J)=W(I,J) THEN 1810 
1800 B=0
1810 NEXT J
1820 IF B=1 THEN 1860 
1840 NEXT I
1850 IF A<=0 THEN 1870 \REM NO WIN
1860 C=W(I,5)\PRINT "PAYS"C;"CENTS."\GO TO 1390 
1870 IF S(1)+S(2)+S(3)+S(4)<>20 THEN 1520 
1880 C=20\PRINT "SURPRISE WIN PAYS"C;"CENTS."\GO TO 1390 
4000 REM SUBR TO PRINT 6 LINE FEEDS
4010 FOR I=1 TO 6\PRINT \NEXT I\RETURN
4100 REM SUBR TO INPUT A YES OR NO ANSWER
4110 INPUT Z$\Z$=SEG$(Z$,1,1)\IF Z$="Y" THEN 4120 
4112 IF Z$="T" THEN 4120 \IF Z$="" THEN 4120 
4114 IF Z$="N" THEN 4120 \IF Z$="H" THEN 4120 
4116 PRINT "PLEASE ANSWER 'YES' OR 'NO' OR 'HELP'";\GO TO 4110 
4120 RETURN
4200 DEF FNR(Z)=INT(RND(1)*9+1)
4300 PRINT "CONGRATULATIONS.  YOU HAVE WON!   AND HAVE $"M/100;" TO TAKE AWAY."
4400 GOSUB 4000 \GO TO 5000 
5000 END
