AppleSoft BASIC MadLibs

From Stack Overflow
Jump to: navigation, search
10 DIM STENCIL$(1024) :REM THE MADLIB STENCIL
20 DIM LINE$(80)      :REM AN INPUT LINE
20 DIM ENTRIES$(255)  :REM CR-SEPARATED USER ENTRIES
30 DIM ET$(2)         :REM ENTRY TYPE FOR GOSUB
40 STENCIL$=""
50 ENTRIES$=""
60 COUNTER=1

100 GOSUB 1600
110 ? "SELECT:"
120 ? "1) SONG LYRICS"
130 ? "2) DRAGON"
140 ? "3) WALMART"
150 INPUT "SELECTION? ";WHICH
160 IF WHICH < 1 OR WHICH > 3 THEN GOTO 100

200 ONERR GOTO 260 :REM READ RETURNS ERROR AT END
210 NUM=0
220 READ LINE$
230 IF LEN(LINE$) = 1 THEN NUM=ASC(LINE$)-48: GOTO 220
240 IF LEN(LINE$) > 0 AND NUM=WHICH THEN STENCIL$=STENCIL$+LINE$+CHR$(13)
250 GOTO 220
260 ONERR GOTO 1001

300 ENTRIES$=""
310 GOSUB 1600
320 FOR X=1 TO LEN(STENCIL$)
330 IF MID$(STENCIL$,X,1)="%" THEN X=X+1:ET$=MID$(STENCIL$,X,1):GOSUB 1800
340 NEXT X
350 IF LEN(ENTRIES$)>0 THEN ENTRIES$=ENTRIES$+CHR$(13)
360 REM ? ENTRIES$

500 GOSUB 1600
510 FOR X=1 TO LEN(STENCIL$)
520 ET$=""
530 IF MID$(STENCIL$,X,1)="%" THEN X=X+1:ET$=MID$(STENCIL$,X,1):GOSUB 1700
540 IF LEN(ET$)=0 THEN PRINT MID$(STENCIL$,X,1);
550 NEXT X

1000 END
1001 NORMAL:?:?"ERROR ";PEEK(222):END

1600 TEXT:HOME:INVERSE
1610 ? "****************************************";
1620 ? "*************** MAD LIBS ***************";
1630 ? "****************************************";
1640 NORMAL
1650 ?
1660 RETURN

1700 REM PRINT AND REMOVE ONE WORD FROM THE ENTRIES LIST
1710 INVERSE
1720 IF LEN(ENTRIES$)=0 THEN NORMAL:RETURN
1730 A=ASC(LEFT$(ENTRIES$,1))
1740 IF LEN(ENTRIES$) <= 1 THEN ENTRIES$=""
1750 IF LEN(ENTRIES$) > 1 THEN ENTRIES$=RIGHT$(ENTRIES$,LEN(ENTRIES$)-1)
1760 IF A=13 THEN NORMAL:RETURN
1770 IF A>=32 AND A<=127 THEN PRINT CHR$(A);
1780 IF LEN(ENTRIES$)=0 THEN NORMAL:RETURN
1790 GOTO 1720

1800 REM GET ONE ENTRY FROM THE USER
1801 ? COUNTER;"> PLEASE ENTER A";
1810 IF ET$="V" THEN PRINT " VERB";
1820 IF ET$="A" THEN PRINT "N ADJECTIVE";
1830 IF ET$="N" THEN PRINT " NOUN";
1831 IF ET$="C" THEN PRINT " COLOR";
1832 IF ET$="D" THEN PRINT " DIRECTION";
1833 IF ET$="B" THEN PRINT " BODY PART";
1834 IF ET$="P" THEN PRINT " PLURAL NOUN";
1835 IF ET$="#" THEN PRINT " NUMBER";
1840 INPUT ": ";LINE$
1850 IF LEN(LINE$)=0 GOTO 1800
1860 IF LEN(ENTRIES$)>0 THEN ENTRIES$=ENTRIES$+CHR$(13)
1870 ENTRIES$=ENTRIES$+LINE$
1880 COUNTER=COUNTER+1
1890 RETURN

1900 DATA "1"
1901 DATA "NEVER GONNA %V YOU %D"
1902 DATA "NEVER GONNA %V YOUR %P"
1903 DATA "NEVER GONNA %V AROUND AND DESERT YOU"
1904 DATA "NEVER GONNA MAKE YOU %V"
1905 DATA "NEVER GONNA SAY %N"
1906 DATA "NEVER GONNA TELL A LIE AND %V YOU"
1907 DATA "2"
1908 DATA "THE %C DRAGON IS THE BEST DRAGON"
1909 DATA "OF ALL. IT HAS %A %B AND A"
1910 DATA "%B SHAPED LIKE A %N. IT LOVES TO EAT"
1911 DATA "%P ALTHOUGH IT WILL FEAST ON"
1912 DATA "NEARLY ANYTHING. IT IS %A AND %A."
1913 DATA "YOU MUST BE REAL %A AROUND IT, OR"
1914 DATA "YOU MAY END UP ITS MEAL!"
1915 DATA "3"
1916 DATA "COME %V TO WALMART WHERE YOU'LL"
1917 DATA "RECEIVE %A DISCOUNTS ON ALL OF YOUR"
1918 DATA "FAVORITE BRAND NAME %P. OUR %A
1919 DATA "ASSOCIATES ARE THERE TO %V YOU"
1920 DATA "%# HOURS A DAY. FIND %A PRICES"
1921 DATA "WALMART WHERE THE %P COME FIRST"
1922 DATA "4"
Personal tools