Hangman program issues..

eric_r

Active member
Joined
Aug 30, 2006
Messages
29
Programming Experience
Beginner
Im fairly new to VB.NET and I am making the infamous Hangman program.

So far Ive managed to draw a random word from a text file and display it in a label on form load, but what I really want to do is convert all of the characters to an underscore so they can't see it.

I am debating on that, or just letting a reader count the characters in the word and assign a certain amount of underscores to the label instead of converting anything.

Like I said, I am NEW so tips or direction would be much appreciated. If I could get ahold of my professor I would.

Thanks!
 
Congratulations on solving the previous issue :) and thx for the added reputation :D

On topic:
What value is the property Size of your picBox?

You can also try this, it could be handy to stretch the image to the size of the picBox, but that only works with Backgroundimage property instead of Image property like this:

picBox.BackgroundImage = ilsHang.Images(currentImage)
picBox.BackgroundImageLayout = ImageLayout.Stretch 'or Zoom or whatever
 
thanks and you're welcome.


picBox size is 376, 368, the same size as the image i place inside of it...
 
I pulled this from MSDN

Property Value

The Size that defines the height and width, in pixels, of the images in the list. The default size is 16 by 16. The maximum size is 256 by 256.

So it shrinks it to 256x256.. when the image needs to be 376, 378. :(
 
In that case don't bother with the image list at all. You can embed all your images in your .exe by adding them to your project..

AddExistingItem

Then goto the properties window and set the build action as an embedded resource. You can then use them in your application via reflection.


VB.NET:
System.Reflection.Assembly.GetExecutingAssembly.
GetManifestResourceStream(gettype(your assembly), image name including extension)
 
Ive decided to go with what i know so I changed the image so the hangman itself is a smaller cropped out image and within a picture box that is laying on top of my other picture box.

it is called picAction and I have loaded 7 files into the imageList.

My goal is to figure out what image from the imagelist is loaded and add the next image until it reaches 6 (the 7th image) which would constitute death or failure or endgame.

what i had before would undoubtedly change the image but i was so messed up that i couldnt even tell what order it was going through.
 
You can access images in an imagelist by index. So set up you images in order. 0-6. You can just have a simple counter .i.e an integer that you can increment every time the player loses a life and display the correspondning image from the image list.
 
You can access images in an imagelist by index. So set up you images in order. 0-6. You can just have a simple counter .i.e an integer that you can increment every time the player loses a life and display the correspondning image from the image list.

I failed miserably at attempting this last time. Ill go back to the drawing board and see if I can come up with something better.
 
Frustrating as ever, its simple but its just not coming to me. :(

Ive tried Do Until Loops, If Then's.. ugh. Its obvoiusly the way I am setting it up.

I have gotten it to count the images in the image list, but I cant seem to get the code down to progressively set the image shown as 1 up from last count.
 
put the hangman project in a zip file (be sure to remove the bin folder and the obj folder from the zip file) and post it here, tomarrow evening i can take a look at it for ya and we'll go from there
 
No problem.

Sorry for a lot of commented-out experimental code, too. Ill upload that shortly so i can stop banging my head over this.
 
VB.NET:
Public Sub SubPoint1()
If ilsHang.Images.Count - 1 > currentImage Then
currentImage += 1
Else
currentImage = 0
End If

This part. The Integer currentImage is your reference to an image in the image list as well as being the number of wrong guesses. So when an incorrect letter is entered you can do this.....

VB.NET:
picaction.image = ilsHang.Images(currentImage)
CurrentImage+=1

Haven't tested it so hope it's ok.
 
It seems to sort of work.. except I get an unhandled exception on the line picaction.image = ilsHang.Images(currentImage) because it is "out of the range of valid values".

Not sure why that is happening..

edit: should be noted that it displays currentImage's value as 7 when it finally gets to that code. Why would it be 7?
 
Back
Top