6STRIKES: Text mode word guessing game
Posted: Sun Jan 11, 2015 2:54 am
This is something I did today just to get used to some of smart Basic commands. It's an old school word guessing game sort of like hangman. Text mode only, no graphics, like an old Qbasic game. I'm not a game maker, but had fun making this. Works on my iPad Mini.
- Dav
EDIT: Try Dutchmans version also, it is improved.
- Dav
EDIT: Try Dutchmans version also, it is improved.
Code: Select all
'==================================================
'6STRIKES.TXT - A Text Mode Word Guessing Game
' By Dav, for Smart BASIC, JAN/2015
'==================================================
'
'ABOUT: This is an old school text mode game from
' my Qbasic coding days. I wanted to see
' how well it could be ported to Smart BASIC.
' I also wanted to get familiar with some
' of smart BASIC's commands. So this little
' game sort of got my feet wet there.
'
'PLAY: The game is like Hangman - try to guess
' the words by clicking on the letters.
' Pick them all, solve the word.
' If you pick a wrong letter, it's a strike.
' Get 6 strikes and the game is over.
' You could add GRAPHICS & MUSIC and make a
' real game out of it if you wanted. Enjoy.
'
'NOTE: I've only tested this on my iPad Mini.
'
' You can add more words to the data state-
' ments at the bottom, but be sure to change
' the 'totalwords' variable to match them.
'=================================================
init:
set orientation top
set output font color 1,1,1
set output back color 0,128/255,128/255
set output font size "56"
set buttons font name "Verdana"
set buttons font size 56
'=== load words
totalwords=15 '<< Total number of words in DATA
dim word$(totalwords+1)
for g=1 to totalwords
read word$(g)
next g
'==============================================
intro:
text clear
set output font color 0,0,0 'Turn screen/text black
set output back color 0,0,0
print
print
print " 6 STRIKES!"
print " By Dav"
print
print " Guess the word(s)"
print " Before Striking out!"
print
print
print " High Score today:"; highscore
print
'=== fade in screen/text from black
for f = 0 to 128
c=f/255
set output back color 0,c,c
set output font color c,c,c
pause .005
next f
'=== continue fading in text...
for f=129 to 255
c= f/255
set output font color c,c,c
pause .005
next f
'=== Put a PLAY button to start game
button "play" title " Play " at 280,700
do
set output font color 0,1,(rnd(128)+120)/255
until button_pressed("play")
button "play" delete
wordnum=1 'Start at word # 1
'=============================================
newword:
text clear 'Clear text
set output font color 1,1,1 'Set text color
call drawkeys(1) 'Redraw all letter
strike=0 'Reset strike counter
'=== Build a guess$ word to use (ie: --- ----)
'=== It's Based on word$() length
r$=""
for e = 0 to len(word$(wordnum))-1
n$ = mid$(word$(wordnum),e,1)
if n$ <> " " then
r$ = r$ & "-"
else
r$ = r$ & " "
end if
next e
guess$=r$
'=============================================
mainloop:
text clear
print " Word:"; wordnum; " Score =";score
print
print
print " "; guess$
gosub drawstrikes
'=============================================
getaletter:
for i = 65 to 90
if button_pressed(chr$(i)) then
button chr$(i) delete
'=== Replace (-) in guess$ with letter
g2$=""
for e = 0 to len(word$(wordnum))-1
nib$ = mid$(word$(wordnum),e,1)
if nib$ = chr$(i) then
g2$ = g2$ & chr$(i)
found=1
else
g2$ = g2$ & mid$(guess$, e, 1)
end if
next e
guess$=g2$
'=== If all letters guessed...
if guess$=word$(wordnum) then
gosub gotit
wordnum=wordnum+ 1
if wordnum>totalwords then goto wongame
goto newword
end if
if found<>1 then strike=strike+1
if strike=6 then goto lose
found=0
goto mainloop
end if
next i
if button_pressed("quit") then goto theend
goto getaletter
'=============================================
gotit:
text clear
score =score+ len(word$(wordnum))
print " Word:"; wordnum; " Score =";score
print
print " You got it!"
print
print " ";word$(wordnum)
print
print " Next word...."
gosub flashfont
return
'=============================================
lose:
text clear
print
print
print " YOU STRUCK OUT!"
print
print " The word was..."
print
print " "; word$(wordnum)
print
gosub flashfont
'=============================================
theend:
if score> highscore then highscore = score
text clear
call drawkeys(0)
goto intro
'=============================================
wongame:
call drawkeys(0)
set output back color 0,25/255,125/255
text clear
for i= 1 to 100
print
next i
print " CONGRATULATIONS!"
for u = 1 to 8
print ! pause .15
next u
for g= 1 to 20
set output font color rnd(255)/255,1, rnd(255)/255
pause .1
next g
print " YOU WON!!!"
for u = 1 to 8
print ! pause .15
next u
for g= 1 to 20
set output font color rnd(255)/255,1, rnd(255)/255
pause .1
next g
goto theend
'=====================================================
' FUNCTIONS / GOSUBS / DATA STATEMENTS ........
'=====================================================
drawstrikes: 'Draw the boxes with the X's
u$=chr$(175)
print ! print " ___ ___ ___ ___ ___ ___"
if strike = 0 then print " | | | | | | | | | | | |"
if strike = 1 then print " |X| | | | | | | | | | |"
if strike = 2 then print " |X| |X| | | | | | | | |"
if strike = 3 then print " |X| |X| |X| | | | | | |"
if strike = 4 then print " |X| |X| |X| |X| | | | |"
if strike = 5 then print " |X| |X| |X| |X| |X| | |"
if strike = 6 then print " |X| |X| |X| |X| |X| |X|"
for k = 1 to 6
print " "; u$&u$&u$;
next k
return
'====================================================
flashfont: 'Flashes the fonts on the screen
for m=0 to 500
set output font color 0,1,(rnd(128)+120)/255
pause .005
next m
return
'====================================================
def drawkeys(way)
'Draws or Deletes Buttons, based on 'way'
set buttons font name "Verdana"
set buttons font size 56
l=65 'Do all Letters A to Z (Ascii..)
for y = 0 to 300 step 100
for t = 30 to 700 step 100
if l < 91 then
if way =1 then
button chr$(l) title chr$(l) at t, 570+y
else
button chr$(l) delete
end if
end if
l=l+1
next t
next y
if way = 1 then
button "quit" title "QUIT" at 530,870
else
button "quit" delete
end if
end def
'===================================================
data "SMART BASIC","VANILA BEAN","PROGRAMMING"
data "DECEMBER", "HAMBURGER", "OLYMPICS"
data "COMPUTER", "RHYTHM", "GORILLA"
data "SCIENTIFIC","VOLCANO", "HISTORY"
data "LANGUAGE", "WINDOWS", "MACINTOSH"