BASIC Code

Slots.BAS

Click on the game window below to enable keyboard entry.

Slots is a slot machine game that pays out the following:

This is another one of those gambling games that records losses and gains rather than giving the player a set budget to work with.

The Listing

PRINT TAB(11); "**********************************************************"
PRINT TAB(11); "**********************************************************"
PRINT TAB(11); "**                                                      **"
PRINT TAB(11); "**                       SLOTS                          **"
PRINT TAB(11); "**                                                      **"
PRINT TAB(11); "**     As seen in David Ahl's BASIC Computer Games      **"
PRINT TAB(11); "**     Converted and refactored by Michael Coorlim      **"
PRINT TAB(11); "**      Original by Fred Mirabelle and Bob Harper       **"
PRINT TAB(11); "**                                                      **"
PRINT TAB(11); "**********************************************************"
PRINT TAB(11); "**********************************************************"
PRINT:PRINT:PRINT

Once again I'm eliminating line numbers in favor of labels.

REM ## INITIALIZE
_INITAUDIO
BALANCE = 0
DIM FACES$(6)
FACES$(0) = CHR$(205)
FACES$(2) = CHR$(1)
FACES$(3) = CHR$(9)
FACES$(4) = CHR$(2)
FACES$(5) = CHR$(6)
FACES$(1) = CHR$(4)

In addition to making variable names more evocative, I'm using an array for the different symbols instead of an IF-THEN sequence. They were strings reading "bar", "cherry", "orange", and I'll be using ASCII symbols with CHR$ instead.

?"INSTRUCTIONS:"
?"Bet between $1 and $100. Hitting Enter pulls the slot machine's arm."
?
PLACE_BET:
input "Your Bet"; %BET
BET = INT (%BET)
if BET >100 or BET < 1 THEN
	?:?"Bets must be between $1 and $100."
  ?: GOTO PLACE_BET
END IF
B = 10 : REM Temp variable for number of beeps
GOSUB BEEPS
? 

This game actually did check to make sure the bet was in range, so all I had to do was change the variable from M to BET.

REM ## SPIN THE WHEEL
W1 = INT (6*RND(1))
W2 = INT (6*RND(1))
W3 = INT (6*RND(1))
?
? FACES$(W1),
B = 5
GOSUB BEEPS
? FACES$(W2),
GOSUB BEEPS
? FACES$(W3)

Created the BEEPS subroutine here, which I'll explain later.

REM ## DETERMINE WINNINGS

if W1 = W2 AND W2 = W3 AND W3 = 0 THEN
	IF W3 = 0 THEN
  	WINNINGS = 100*BET
		?:? "**JACKPOT**"
    GOTO WIN
  END IF
	WINNINGS = 10 * BET
  ?:? "**MATCH 3**"
  GOTO WIN
 END IF
IF (W1 = W2 AND W2 = 0) OR (W1 = W3 AND W1 = 0) OR (W2 = W3 and W2 = 0) THEN
  WINNINGS = 5 * BET
  ?:? "**DOUBLE BAR**"
  GOTO WIN
END IF
IF (W1 = W2) or (W1 = W3) or (W2 = W3) THEN
	WINNINGS = 2 * BET
  ?:? "**DOUBLES**"
  GOTO WIN
END IF
?:? "YOU LOSE"
BALANCE = BALANCE - BET
GOTO PRINT_BALANCE

These were originally a complex series of IF... THEN statements. I simplified them using AND to group them according to the possible outcomes.

BEEPS:
FOR T=1 TO B 
BEEP
NEXT T
RETURN

The original listing used CHR$(7) to generate a beep. The BASIC Anywhere Machine doesn't use that, instead it uses a BEEP keyword.

WIN:
	?"You win ";WINNINGS
  BALANCE = BALANCE + WINNINGS
  
PRINT_BALANCE:
? "Your standings are $";BALANCE
input "Pull again (Y/N)"; A$
if LEFT$(A$,1) = "Y" or LEFT$(A$,1) = "y" THEN GOTO PLACE_BET
?
if BALANCE<0 THEN ?"Please leave your money on the terminal."
if BALANCE=0 THEN ?"At least you broke even."
if BALANCE>0 THEN ?"Collect your winnings from the cashier."
200 DO: SLEEP 1: LOOP

#David Ahl