A Stake That Runs Out
A game you can't lose isn't a game. Give the safe a fixed number of tries: count each guess, and when they run out before the crack, the safe locks. Now the loop ends two ways — win or lose — and the guess count is the clock. Your finished Safe Cracker.
A loop you can run forever isn't a game — there are no stakes. The fix is a limit: a fixed number of tries, counting down with every guess. Crack the safe before they run out and you win; spend the last one and the safe locks for good. Two endings, and a reason to guess well.
10 S=INT(RND(1)*100)+1
20 BG=6:T=7
30 POKE 53281,BG:GOSUB 500
40 INPUT "YOUR GUESS";G
50 T=T-1
60 IF G=S THEN POKE 53281,5:GOSUB 500:PRINT "CRACKED IT!":END
70 IF T=0 THEN POKE 53281,2:GOSUB 500:PRINT "LOCKED! THE CODE WAS";S:END
80 IF G<S THEN BG=14:H$="THE CODE IS HIGHER"
90 IF G>S THEN BG=2:H$="THE CODE IS LOWER"
100 POKE 53281,BG:GOSUB 500
110 PRINT H$
120 GOTO 40
500 PRINT CHR$(147)
510 PRINT "********************"
520 PRINT "* S A F E *"
530 PRINT "* CRACKER *"
540 PRINT "********************"
550 PRINT "GUESSES LEFT:";T
560 PRINT
570 RETURN
The stake is a counter. Line 20 sets T = 7 — seven tries. Line 50, T = T-1, spends one on
every guess. The win check is unchanged, but now there's a second way out: line 70, IF T = 0 THEN ... locks the safe when the count hits zero before the code is found — a red screen, the
code revealed, and an END. The safe routine prints GUESSES LEFT: T so the player watches their
stake shrink with each go.
Now the loop ends two ways — CRACKED IT! on a match, LOCKED! on an empty counter — and the
guess count is the clock. Seven tries is the number that makes 1–100 fair: a player using the
hints well just makes it, a player guessing blindly just fails. That balance is the whole design —
losing should feel like your own fault, never the safe's.
That's Safe Cracker. A hidden code, a clue that points the way, a loop that narrows in, colour that carries the mood, and a stake that can run out. You've built the loop-with-a-goal — a loop that ends in a win or a loss — and that shape is under every game you build from here.
Try this
- Tune the difficulty. Six tries makes a tense safe; ten makes a gentle one. Change
Tin line 20 and feel how the stake shifts the whole game. - Play again. Add a
GOTOat the end that loops back to a fresh secret and a full counter, so one crack rolls into the next — the replay you built into Bleeper.
What's next
You've built a game that ends in a win or a loss. Next in Volume 1 comes Rover — the joystick takes the controls, and the game runs in real time as you drive a craft around the screen and bump into things.