Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Hangman Problems

Author
Message
mickb
16
Years of Service
User Offline
Joined: 15th Apr 2008
Location:
Posted: 15th Apr 2008 15:09
I'm fairly new to DBPro and am creating a hangman game. The game's running fine except there's no limit on how many letters you can enter on one guess. How do I limit how many characters can be entered for each guess? I only want one letter to be able to be entered for each guess.
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 15th Apr 2008 15:36
It depends on how you're reading the characters from the keyboard.

You could try:

which will return the letter of the key currently being pressed, and then do nothing until the user stops pressing the keyboard.

Hope this helps!

It is said there are 10 types of people in this world - those who understand binary, and those who have friends!
mickb
16
Years of Service
User Offline
Joined: 15th Apr 2008
Location:
Posted: 18th Apr 2008 20:09
This is my code I want it to just allow you to enter one letter per guess. And for the enter guess to stay in place instead of repeating after each guess.

startprogram:
lu = 0
ec = 0
Cls
rem Create the Word List Array

dim words$(12)
words$(0) = "tea"
words$(1) = "rat"
words$(2) = "que"
words$(3) = "wow"
words$(4) = "fork"
words$(5) = "last"
words$(6) = "mint"
words$(7) = "play"
words$(8) = "rent"
words$(9) = "scene"
words$(10) = "brain"
words$(11) = "horse"
words$(12) = "zebra"
rem Random Timer
randomize timer()
Rem Randomize the Array
num = rnd(12)
ww$ = words$(num)

lw = len (ww$)

print ww$
Rem Pull up Functions
title()
gallows()
rem word length 3 spaces
if lw = 3
threespace()
else
rem word length 4 spaces
if lw = 4
fourspace()
else
rem word length 5 spaces
fivespace()
endif
endif

dim letters$(lw)
rem For Loop to get program to pick right amount of spaces for words
for c = 1 to lw
letters$(c) = mid$(ww$,c)
next c


rem guess
input "Guess ";guess$



rem to exit program
while guess$ <> "qq"

found = 0

rem first letter right
for ctr = 1 to lw
if guess$ = letters$(ctr) and ctr = 1
text 160,350, guess$
lu = lu + 1
found = 1
else
rem second letter right
if guess$ = letters$(ctr) and ctr = 2
text 200,350, guess$
lu = lu + 1
found = 1
else
rem third letter right
if guess$ = letters$(ctr) and ctr = 3
text 235,350, guess$
lu = lu + 1
found = 1
else
rem fourth letter right
if guess$ = letters$(ctr) and ctr = 4
text 270,350, guess$
lu = lu + 1
found = 1
else
rem fifth letter right
if guess$ = letters$(ctr) and ctr = 5
text 305,350, guess$
lu = lu + 1
found = 1


endif
endif
endif
endif
endif
next ctr
rem counter for you win plus randomize spots and colors
if lu = lw
sleep 500
cls
for ctr = 1 to 30
ink rgb (rnd(255),rnd(255),rnd(255)),0
text rnd (500),rnd (400), "You Win"
sleep 100
next ctr
goto startprogram
endif



rem bring up head if guess is wrong
if found <> 1 and ec = 0
head()
ec = ec +1
else
rem bring up body if guess is wrong
if found <> 1 and ec = 1
body()
ec = ec + 1
else
rem bring up rarm if guess is wrong
if found <> 1 and ec = 2
rarm()
ec = ec + 1
else
rem bring up larm if guess is wrong
if found <> 1 and ec = 3
larm()
ec = ec + 1
else
rem bring up rarm if guess is wrong
if found <> 1 and ec = 4
rleg()
ec = ec + 1
else
rem bring up lleg if guess is wrong
if found <> 1 and ec = 5
lleg()
ec = ec + 1
rem you lose
if ec = 6
sleep 500
cls
for ctr = 1 to 30
ink rgb (rnd(255),rnd(255),rnd(255)),0
text rnd (500),rnd (400), "You Lose. Your word was "+ww$+"."
sleep 100
next ctr
goto startprogram
endif





endif
endif
endif
endif
endif
endif



rem input guess
input "Guess ";guess$

endwhile



end



rem Function Section
rem Title Function
function title()
set text font "chiller"
set text size 60
ink rgb(0,0,255),0
text 200,100, "Welcome to Hangman!"
ink rgb(200,0,0),0
text 201,102, "Welcome to Hangman!"
endfunction
rem Gallows Function
function gallows()
line 300,200,400,200
line 400,200,400,375
line 350,375,450,375
line 300,200,300,230
endfunction
rem Head Function
function head()
circle 300,245,15
endfunction
rem Body Function
function body()
line 300,260,300,310
endfunction
rem Right Leg Function
function rleg()
line 300,310,280,350
endfunction
Rem Left leg Function
function lleg()
line 310,350,300,310
endfunction
rem Right Arm Function
function rarm()
line 300,280,280,320
endfunction
rem Left Arm Function
function larm()
line 300,280,325,320
endfunction
rem Three Space Function
function threespace()
line 160,400,195,400
line 200,400,230,400
line 235,400,265,400
endfunction
rem Four Space Function
function fourspace()
line 160,400,195,400
line 200,400,230,400
line 235,400,265,400
line 270,400,300,400
endfunction
rem Five Space Function
function fivespace()
line 160,400,195,400
line 200,400,230,400
line 235,400,265,400
line 270,400,300,400
line 305,400,335,400
endfunction

Login to post a reply

Server time is: 2024-09-27 14:30:14
Your offset time is: 2024-09-27 14:30:14