Hangman Game

  • Thread starter Thread starter Steven Smith
  • Start date Start date
S

Steven Smith

-----Original Message-----
Hi guys

Heh where do I start this time :)

first of all thanks for your responses

I've managed to implement the sugestions from Fergus,
Herfried & jeremy, however doing this has highlighted
another problem in the following For...Next loop.

since the letter count for the game is now dynamic the
index range which is searched to determine if the chosen
letter appears in the secret word also has to be dynamic

i.e for intIndex = 0 to 4

was fine for a consistent 5 letter word but now obviously
this is no use now.

Sooooo what I thought I would do is pull the string
length from mstrWord.length and assign the value to an
integer as follow's:

intLength = mstrword.length
for intIndex = 0 to intlength

however when the game begins and a letter is chosen the
following line kicks back with the error 'Index and
length must refer to a location within the string':

strCharacter = mstrWord.Substring(intIndex, 1)

this out of range error doesn't make sense to me as the
loop should check the index range of 0 to the value of
intLength.




///
'search for the selected letter in the secret word
For intIndex = 0 To 4
'assign current character to the strCharacter
variable
strCharacter = mstrWord.Substring(intIndex, 1)
'determine whether or not the current
character matches the selected letter
If strCharacter = objLetterLabel.Text Then
'replace appropriate dash/es in the
strPartialWord variable
Mid(strPartialWord, intIndex + 1) =
objLetterLabel.Text
'indicate that a replacement was made
blnReplaced = True
End If
Next intIndex
///


now my head hurts, but I'm determined to make this
work... :)

Regards Steve
 
make intLength = mstrword.length - 1 instead of mstrword.length.

For example,

"happy" has 5 letters, so it's length is 5.
"happy" has letters at index 0, 1, 2, 3, 4.

It's last available index is it's length - 1.
 
Hi Steven,

It's a <<really good idea>> (but one unfortunately disregarded by all but
the best programmers*) to work through routines <on paper> where <you> are the
computer - making little marks to show where you are in arrays and strings;
and what values your variables have; what objects are linked to what other
objects; and so on.

This is about the best way to learn how things work. And to get your
methods clear in your head.

And guess what. It's not as easy as staring at a screen.

But seeing yourself create structures on paper and in your brain will
develop your understanding far faster than letting the computer do things at
its own speed - so fast that untold things are happening.

That's my opinion anyway. What do I know? I only designed a new sorting
algorithm on paper, without a computer within 20 miles of me. [boast, boast!
:-)] But it wouldn't have happened if I'd had a computer to distract me.

Now, let's wait for all the other opinions on this. :-D

Regards,
Fergus

* "best programmers" - trying to appeal to your pride and ambition. :-)
 
It's a <<really good idea>> (but one unfortunately disregarded by
all but
the best programmers*) to work through routines <on paper> where <you>
are the computer - making little marks to show where you are in arrays
and strings; and what values your variables have; what objects are
linked to what other objects; and so on.

Hi Fergus,

I agree completely. I use this technique when developing algorithms as it
not only helps to debug it, but I often discover ways to optimize the
algorithm in the process.

Chris
 
Hi Steven (although on this thread to Fergus)

The first time I started with computers was at the "first agency for IT in
Holland".

The boss of that agency learned me:

If you can not figured out how to do it by hand (he did mean on paper).
Don't try to do it with a computer.

I never have seen practicaly that someone could prove that that was not
true.
(You can of course use the computer to help you like a calculator or a
texteditor)
But I have always a piece of paper beside me to make a tables or so.

Cor
 
Back
Top