Monday 1 June 2020

BASIC Programming

I’ve been busy putting the finishing touches to a program I’ve been writing using the BASIC programming language. Are you of a certain age and remember trying to program in BASIC (Beginner’s All-Purpose Symbolic Instruction Code)?

I’ve found an app for iOS called cbmHandBasic.

That’s the ‘what it looks like in the App Store’ image. This allows you to do a bit of BASIC programming. 

But before you try out your own programming you wanna sample my terrible programming skills and play my interpretation of Hangman, don’t you?

Assuming you said yes to that question, here’s what you need to do. 

🔸Install cbmHandBasic on your iPhone or iPad 
🔸Copy the entire contents of my BASIC program which appears below onto your clipboard.
🔸Launch cbmHandBasic
🔸On a new line type Edit “hangman.bas” and hit the Return key
🔸A new screen should appear with something like  10 PRINT “Hello World”
🔸Just ignore this and tap the screen, so the cursor is on a new line
🔸 Tap the screen a second time and the options ‘Select | Select All | Paste’ should appear
🔸Tap on ‘Paste’ and the contents of the clipboard should appear 
🔸Tap on ‘Save’ at the top of the screen and you will go back to the original screen 
🔸Now on a new line type Load “hangman.bas” and hit the Return key
🔸Finally type Run, hit the Return key and the program should run

Don’t get too excited it’s far from perfect and there’s no graphics in the program. The word you have to try and guess is chosen at random from a selection of 52 words I’ve built into the program. There’s no check made as to what your previous word was so there is a possibility that you could get the same word twice in a row. 

If you’re feeling really adventurous you could add more words, which if you know BASIC you’ll easily see where they should go within the program. The only restriction being that you can only use letters a-z, no numbers, punctuation or spaces. It doesn’t matter if you use upper or lower case as the program converts all into upper case. 

If you do add more words it is most important to make sure the last DATA line reads: DATA “end”. An error will occur if this is not the last line. 

If carrying out the above procedure to get the program any subsequent times you wish to play Hangman you just need to type Load “hangman.bas” and hit the Return key followed by Run and hitting the Return key. 

Have fun! 😊

Here’s the program 

10 REM HANGMAN

30 CLS

50 PRINT"HANGMAN by Jeff Wright"

70 PRINT

90 GOSUB 1300:REM CALCULATE NUMBER OF WORDS

110 INPUT "What is your name";NAME$

130 IF NAME$="" THEN LET NAME$="Anonymous"

150 IF LEFT$(NAME$,1)=>"a" AND LEFT$(NAME$,1)=<"z" THEN GOSUB 1000

170 CLS:PRINT"HANGMAN by Jeff Wright":PRINT

190 PRINT"Hello ";NAME$;"!"

250 RESTORE

270 DIM W$(N)

290 FOR L=1 TO N

310 READ W$(L) 

330 GOSUB 1200:REM CAPITALISE WORDS

370 NEXT L

390 LET G=INT(RND(1)*N)+1

400 PRINT

410 PRINT"Let Us Play HANGMAN"

420 PRINT"You have 10 Lives"

425 PRINT

430 PRINT "Guess the word, it has ";LEN(W$(G));" letters"

450 LET SOFAR$=""

470 Q=LEN(W$(G)):PRINT"So far guessed: ";

490 FOR F=1 TO Q

510 LET SOFAR$=SOFAR$+"-"

530 NEXT F

550 PRINTSOFAR$

560 LET LIVES=10

570 PRINT

590 PRINT"Make a guess: >";

610 GET K$:GOSUB 1500:REM CAPITALISE GUESS

630 IF K$="" THEN GOTO 610

650 PRINTK$

660 LET FOUND=0

665 LET SF$=SOFAR$:LET SOFAR$=""

670 FOR F=1 TO LEN(W$(G))

690 IF K$=MID$(W$(G),F,1) THEN LET FOUND=1

710 IF K$=MID$(W$(G),F,1) THEN LET SOFAR$=SOFAR$+K$ 

723 IF K$<>MID$(W$(G),F,1) THEN LET SOFAR$=SOFAR$+MID$(SF$,F,1)

730 NEXT F

750 IF FOUND=1 THEN PRINT "Well done ";NAME$;", you have guessed a correct letter!"

755 IF FOUND=1 THEN GOSUB 1600

760 IF FOUND=0 THEN PRINT "Sorry ";NAME$;", incorrect letter, you have lost a life!"

765 IF FOUND=0 THEN LET LIVES=LIVES-1:GOSUB 1630

770 PRINT"You have";LIVES;"lives remaining"

773 PRINT"So far guessed: ";SOFAR$

780 IF LIVES=0 THEN PRINT:PRINT"Sorry ";NAME$;" you have lost all your lives"

790 IF LIVES=0 THEN PRINT"The correct word was: ";W$(G)

800 IF W$(G)=SOFAR$ THEN PRINT:PRINT"Congratulations ";NAMES$;" word correctly guessed!"

850 IF W$(G)<>SOFAR$ AND LIVES>0 THEN GOTO 570

860 PRINT:PRINT"Would you like to play again (Y/N)?";

870 GET K$:GOSUB 1500:REM CAPITALISE GUESS

880 IF K$="" THEN GOTO 870

890 IF K$="Y" THEN GOSUB 1800

892 IF K$="Y" THEN GOTO 390

900 CLS:PRINT"Thank you for playing HANGMAN by Jeff Wright"

910 PRINT"Goodbye"

920 END

1000 REM SORT NAME

1020 LET K=ASC(LEFT$(NAME$,1))

1030 LET NAME$=CHR$(K-32) + RIGHT$(NAME$,LEN(NAME$)-1)

1040 RETURN

1200 REM CAPITALISE WORDS

1210 FOR M=1 TO LEN(W$(L))

1213 LET T$=""

1215 LET K=ASC(MID$(W$(L),M,1))

1220 IF K>96 AND K<123 THEN LET T$ = LEFT$(W$(L),M-1)

1230 IF K>96 AND K<123 THEN LET T$=T$+CHR$(K-32)

1240 IF K>96 AND K<123 THEN LET T$=T$+RIGHT$(W$(L),LEN(W$(L))-M)

1250 IF K>96 AND K<123 THEN LET W$(L)=T$

1260 NEXT M

1270 RETURN

1300 REM CALCULATE NUMBER OF WORDS

1310 LET N=0

1320 READ T$

1330 IF T$<>"end" THEN LET N=N+1

1340 IF T$<>"end" THEN GO TO 1320

1350 RETURN

1500 REM CAPITALISE GUESS

1505 IF K$="" THEN RETURN

1510 LET K=ASC(K$)

1520 IF K>96 AND K<123 THEN LET K$=CHR$(K-32)

1530 IF K$<"A" OR K$>"Z" THEN LET K$=""

1540 RETURN

1600 REM CORRECT SOUND

1610 ALERT 1

1620 RETURN

1630 REM WRONG SOUND

1640 ALERT 5

1650 RETURN

1800 REM RESTART

1810 CLS

1820 PRINT"HANGMAN by Jeff Wright"

1830 RETURN

2000 DATA "Responsibility","Originate","Supernova","Treadmill","Wasteland"

2010 DATA "Locomotive","Fundamental","Dragonfly","Nincompoop","Outrageous"

2020 DATA "Posture","Publication","Rocketry","Monetary","Sandpaper"

2030 DATA "respiratory","scaffolding","seasonal","solution","consequence"

2040 DATA "uncharacteristic","upholsterer","voluntary","wavelength","worrisome"

2050 DATA "zigzag","aversion","backstroke","cabbage","dictaphone"

2060 DATA "esplanade","flapjack","garrison","historical","impassioned"

2070 DATA "juggernaut","kindergarten","lowland","mechanism","newfangled"

2080 DATA "orphanage","packaging","quotient","reception","seasonable"

2090 DATA "townspeople","unification","venturesome","windscreen","xylophone"

2100 DATA "youthful","zodiac"

5000 DATA "end"

5010 REM Hangman 

No comments:

Post a Comment