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.

Author
Message
Happy Snacker
14
Years of Service
User Offline
Joined: 21st Nov 2011
Location:
Posted: 21st Nov 2011 23:26
I need some help. I am trying to add a way for my program to accept upper or lower case letters and I am also trying to figure out how to get the system to detect if a letter has previously been guessed. Here is a copy of the code that I have written so far. Any helpwould be greatly apprecaited.

My Code:

startofprogram:

cls
dim wordlist(12) as string
num as integer
gitem as string
li as integer
found as string
Error as integer
guess as string
usedletters as integer
letterguess as integer
undim itemletters()
dim itemletters(5) as string

wordlist(0) = "ant"
wordlist(1) = "bat"
wordlist(2) = "car"
wordlist(3) = "dog"
wordlist(4) = "eggs"
wordlist(5) = "food"
wordlist(6) = "good"
wordlist(7) = "help"
wordlist(8) = "inks"
wordlist(9) = "jacks"
wordlist(10) = "kiwis"
wordlist(11) = "limes"
wordlist(12) = "maker"
randomize timer()
title()
gallows()
num = rnd(12)
gitem = wordlist(num)
print gitem
li = len(gitem)
if li = 3
threeSpace()
else
if li = 4
threeSpace()
fourSpace()
else
threeSpace()
fourSpace()
fiveSpace()
endif
endif


for c = 1 to li
itemletters(c) = mid$(gitem,c)
next c



input "Guess a letter or press qq to quit: ", guess

while guess<> "qq"
found = "no"
if guess = itemletters(1)
text 115,380, guess
usedletters = usedletters + 1
found = "yes"
endif
if guess = itemletters(2)
text 170,380, guess
usedletters = usedletters + 1
found = "yes"
endif
if guess = itemletters(3)
text 215,380, guess
usedletters = usedletters + 1
found = "yes"
endif
if guess = itemletters(4)
text 265,380, guess
usedletters = usedletters + 1
found = "yes"
endif
if guess = itemletters(5)
text 305, 380, guess
usedletters = usedletters + 1
found = "yes"
endif

if usedletters = li
sleep 200
CLS
Winner()
sleep 1000
goto startofprogram
endif



if found = "no" and Error = 0
head()
Error = Error +1
else
if found = "no" and Error = 1
body()
Error = Error +1
else
if found = "no" and Error = 2
rleg()
Error = Error +1
else
if found = "no" and Error = 3
lleg()
Error = Error +1
else
if found = "no" and Error = 4
rarm()
Error = Error +1
else
if found = "no" and Error = 5
larm()
Error = Error +1
endif
endif
endif
endif
endif
endif

if Error = 6
sleep 200
cls
Lose()
sleep 1000
goto startofprogram
endif

input "Guess a letter or press QQ to quit: ", guess
endwhile


end
function title()
set text font "Chiller"
set text size 45
ink rgb(255,0,0),0
text 200,45, "Welcome to Hangman!!!"
ink rgb (0,0,255),0
text 201,46, "Welcome to Hangman!!!"
set text size 25
ink rgb(0,255,0),0
endfunction


function Winner()
set text font "Chiller"
set text size 45
ink rgb(255,0,0),0
text 200,45, "You win!!! You win!!!"
ink rgb (0,0,255),0
text 201,46, "You win!!! You win!!!"
endfunction

function Lose()
set text font "Chiller"
set text size 45
ink rgb(255,0,0),0
text 200,45, "You Lose!!!"
ink rgb (0,0,255),0
text 201,46, "You Lose!!!"
endfunction

function gallows()
line 200,100,200,320
line 200,100,300,100
line 300,100,300,150
endfunction

function head()
circle 300,160,10
endfunction

function body()
line 300,172,300,210
endfunction

function rleg()
line 300,210,290,250
endfunction

function lleg()
line 300,210,310,250
endfunction

function rarm()
line 300,172,310,210
endfunction

function larm()
line 300,172,290,210
endfunction

function threeSpace()
line 100,400,130,400
line 150,400,180,400
line 200,400,230,400
endfunction

function fourSpace()
line 250,400,280,400
endfunction

function fiveSpace()
line 300,400,330,400
endfunction

function LetterWrong(sLetter$)
bOutput as boolean = 1
for c = 1 to array count(itemletters(0))
if itemletters(c) = sLetter$
bOutput = 0
exit
endif
next c
endfunction bOutput
function HandleError(errors)
inc errors
select errors
case 1
head()
endcase
case 2
body()
endcase
case 3
rleg()
endcase
case 4
lleg()
endcase
case 5
rarm()
endcase
case 6
larm()
endcase
endselect
endfunction errors

wait key
end
RiiDii
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 22nd Nov 2011 08:05 Edited at: 22nd Nov 2011 08:09
Hi. First, others may find your post difficult to read through the code since it is all out in the open. You may want to edit your post and enclose the code like this:

Use [code] and [/code] to create a code box like this:

[code[/b]]
Print "Hello World"
Wait Key
End
[/code[b]
]



Quote: "I am trying to add a way for my program to accept upper or lower case letters"

Use Lower$() to convert text to all lower case.
Use Upper$() to convert text to all upper case.

Quote: "I am also trying to figure out how to get the system to detect if a letter has previously been guessed."


Try an array with 26 elements like this:
Dim Guesses(25)

Then when a letter is guessed, change the relative array element to 1. For example, if "m" is guessed, the 13th letter in the alphabet, then check to see if Guesses(12) = 1. If not, then the letter "m" has not been guessed and can be used. Remember to set Guesses(12) to 1 after the "m" has been used.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 22nd Nov 2011 17:29 Edited at: 22nd Nov 2011 17:48
It's much easier to put all the letters previously guessed in one string and just search the string with a FOR/NEXT loop to check for the letter they currently want.



The quick way of course is with IanM's Matrix1 Utilities Plugins so there's no need to even create a FOR/NEXT loop to search for a character in a string.



The above uses IanM's FIND CHAR() command. If you don't have IanM's Matrix1 Utilities Plugins then stop programming with your hands tied behind your back and download it asap!

Direct Download: https://forumfiles.thegamecreators.com/download/2257747

Info: http://forum.thegamecreators.com/?m=forum_view&t=85209&b=18

Also you can use a FOR/NEXT loop using the LEN() command to put as many lines on the screen that's needed rather than having a function for each number of characters in the string.

Login to post a reply

Server time is: 2026-07-10 03:59:34
Your offset time is: 2026-07-10 03:59:34