473,322 Members | 1,241 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Hangman Game

-----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

Nov 20 '05 #1
4 4585
e
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.
"Steven Smith" <St**********@emailaccount.com> wrote in message
news:41****************************@phx.gbl...
-----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

Nov 20 '05 #2
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. :-)
Nov 20 '05 #3
"Fergus Cooney" <fi******@tesco.net> wrote in
news:#1**************@TK2MSFTNGP12.phx.gbl:
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
Nov 20 '05 #4
Cor
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
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: tigrfire | last post by:
So I'm trying to write a hangman game and the output is coming out a little strange. Here's my code thus far: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> ...
18
ilikepython
by: ilikepython | last post by:
Hi I'm new to Python(3 to 4 days) and I'm working on a hangman game and have been having some problems that really annoy me. Here is part of my script: c = input('Would you like to play hangman?...
4
by: princessfrost | last post by:
Hi! I was wondering if someone could please help me with a hangman program that I have to do. I have some ideas, but really don't know what to do or where to start. My program needs to be:...
3
by: kaka_hunter | last post by:
#include <iostream> #include <fstream> using namespace std; const int max_tries=7; int earnings=0; int wordnum; void getword () { ifstream fin;
2
by: tesa | last post by:
I am not able to figure out how to make this work. I am trying to create a hangman game. I am in a basic javascripting class. I am to only use very basic code as you can see. I am able to use any...
0
by: Madmartigan | last post by:
Hi I'm a newbie to C# and have been instructed to create a Hangman game in SharpDevelop. I don't want the answer to the full code, just some help along the way. I have included my code thus...
5
by: av3rage | last post by:
I have never done any programming in my life but I have decided to go into engineering and in doing so we have to take this intro to programming course and I am pretty clueless. I am starting to get...
8
by: tidiz | last post by:
Hi, I'm trying to make a hangman game that should look like this: Welcome to Hangman ______ Your guess: c Success! __cc__ Your guess: b
1
by: AlexSc | last post by:
Hi to All, I am doing on a hangman project, Where this is a very simple one, where player would guess the word and if it is correct the letter would be from "-" to the correct letter once all...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.