Trying to modify letter falling game (Program Bug and Problems)

by Pat, Thursday, January 31, 2013, 21:40 (1579 days ago)

I am trying to challenge myself a bit, and am trying to modify the letter falling game from the book. I want it keep going until misses = 10, instead of it just going for a preset amount of letters. Any hints or helpful nudges in the right direction would be great. I have a tried an if statement for misses and nletters, I can get it to count the misses correctly which you have to add. I could also see setting the game to a high number of letters, or until misses = 10. I was thinking of adding another while loops or something, just can't figure out how to do it. It seems once it checks how many letters to use, it won't change.

http://www.basicbook.org/ChapterFiles/B256_Chapter11/fallinglettergame.kbs

Thanks

-PAt

Trying to modify letter falling game

by M Santos, Saturday, February 02, 2013, 18:41 (1577 days ago) @ Pat

Hi Pat, this may help you .


# fallinglettergame.kbs

speed = .15 # drop speed - lower to make faster
nletters = 1000 # letters to play

score = 0
misses = 0
color black

fastgraphics

clg
font "Tahoma", 20, 50
text 20, 80, "Falling Letter Game"
text 20, 140, "Press Any Key to Start"
refresh
# clear keyboard and wait for any key to be pressed
k = key
while key = 0
pause speed
end while

do
letter = int((rand * 26)) + asc("A")
x = 10 + rand * 225
for y = 0 to 250 step 20
clg
# show letter
font "Tahoma", 20, 50
text x, y, chr(letter)
# show score and points
font "Tahoma", 12, 50
value = (250 - y)
text 10, 270, "Value "+ value
text 100, 270, "Misses "+ misses
text 200, 270, "Score "+ score
refresh
k = key
if k <> 0 then
if k = letter then
score = score + value
else
score = score - value
end if
goto nextletter
end if
pause speed
next y
misses = misses + 1
nextletter:
until misses = 10

clg
font "Tahoma", 20, 50
text 20, 40, "Falling Letter Game"
text 20, 80, "Game Over"
text 20, 120, "Score: " + score
text 20, 160, "Misses: " + misses
refresh
end

Trying to modify letter falling game

by Pat, Wednesday, February 13, 2013, 19:52 (1566 days ago) @ M Santos

Thanks !! such an easy solution! Also added mistyped letters to misses, and let user pick speed. Thanks again.. I will keep playing with it, see what can make it even cooler!

# fallinglettergame.kbs

speed = .15 # drop speed - lower to make faster
nletters = 1000 # letters to play

score = 0
misses = 0
color black

fastgraphics

clg
font "Tahoma", 20, 50
text 20, 80, "Falling Letter Game"
input "Enter Speed: 20=Easy 30=Normal 45=Hard 55=Insane! 70=Impossible", speed11
text 20, 140, "Press Any Key to Start"
refresh
# clear keyboard and wait for any key to be pressed
k = key
while key = 0
pause speed
end while

do
letter = int((rand * 26)) + asc("A")
x = 10 + rand * 225
for y = 0 to 250 step speed11
clg
# show letter
font "Tahoma", 20, 50
text x, y, chr(letter)
# show score and points
font "Tahoma", 12, 50
value = (250 - y)
text 10, 270, "Value "+ value
text 100, 270, "Misses "+ misses
text 200, 270, "Score "+ score
refresh
k = key
if k <> 0 then
if k = letter then
score = score + value
else
score = score - value
misses = misses + 1
end if
goto nextletter
end if
pause speed
next y
misses = misses + 1
nextletter:
until misses = 10

clg
font "Tahoma", 20, 50
text 20, 40, "Falling Letter Game"
text 20, 80, "Game Over"
text 20, 120, "Score: " + score
text 20, 160, "Misses: " + misses
refresh
end

RSS Feed of thread
powered by my little forum