| | |
Simple Hangman Game
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2008
Posts: 16
Reputation:
Solved Threads: 0
Gday i already asked for help in the vb.net forum,im new so im guessing i was in the wrong forum as i didnt receive much help.ive posted all the original text from the thread below.
G day ,im a parent from Australia.
My child is 7 turning 8 and i would like to create a simple hangman game in visual basic that he can use.
id please like to know the logistics of making the game.
This is how id like it to work,ive investigated different games....
i would like it to have a text box where you enter a single letter into it at any time and then obviously if its wrong, the wrong letter disappears, no longer being able to click.
Would someone please be able to think of the simplest possible way for me to do this,its important for me to not have it done by someone else and to make this game for my son myself.
I would like to be able to change/add the words in the game in the code,so that my son wont get bored
this is my first problem and i have heard this is a very friendly board,if you can assist me then thank you very much!
id just like to clarify that id like to solely use VB to make the program.i think ill just go into the code and change/add new words when my son gets bored etc.
Id like for the game to be really simple ;with the words being randomly selected ,each letter of the random word being part of an array,and having the images of the hangman appear when a guessed letter matches one of the letters in the array.
im guessing part of the code would be something like this..
Help with Code Tags
(Toggle Plain Text)
If text1 = text2
Then Image.Show
If text1 = text2 Then Image.Show
i have also written some pseudo code to start it off
Help with Code Tags
(Toggle Plain Text)
i have got a visual basic book from a library and it has all the basics on everything ,but im still stumped as how to start things off in terms of actually writing the code.What things in the book should i focus on in this type of game???
as you can see from my pseudo code,each letter from the word will be split up into an array.
i know most of you are experts at visual basic etc. but im just a novice please assist me with what ive done so far,thank you!
G day ,im a parent from Australia.
My child is 7 turning 8 and i would like to create a simple hangman game in visual basic that he can use.
id please like to know the logistics of making the game.
This is how id like it to work,ive investigated different games....
i would like it to have a text box where you enter a single letter into it at any time and then obviously if its wrong, the wrong letter disappears, no longer being able to click.
Would someone please be able to think of the simplest possible way for me to do this,its important for me to not have it done by someone else and to make this game for my son myself.
I would like to be able to change/add the words in the game in the code,so that my son wont get bored
this is my first problem and i have heard this is a very friendly board,if you can assist me then thank you very much!
id just like to clarify that id like to solely use VB to make the program.i think ill just go into the code and change/add new words when my son gets bored etc.
Id like for the game to be really simple ;with the words being randomly selected ,each letter of the random word being part of an array,and having the images of the hangman appear when a guessed letter matches one of the letters in the array.
im guessing part of the code would be something like this..
Help with Code Tags
(Toggle Plain Text)
If text1 = text2
Then Image.Show
If text1 = text2 Then Image.Show
i have also written some pseudo code to start it off
Help with Code Tags
(Toggle Plain Text)
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
fullword = "jungle"; word = ("j","u","n","g","l","e"); player = ("-","-","-","-","-","-"); while (win = false) { print "So far, you have.. " + player; print "What is your next guess? "; input guess; for (i = 0; i < 6; i++) { if (guess = word[i]) { player[i] = guess; } } checker = player[0] + player[1] + player[2] + player[3] + player[4] + player[5]; if (checker = word[6]) { win = true; } } print "You win!"; fullword = "jungle"; word = ("j","u","n","g","l","e"); player = ("-","-","-","-","-","-"); while (win = false) { print "So far, you have.. " + player; print "What is your next guess? "; input guess; for (i = 0; i < 6; i++) { if (guess = word[i]) { player[i] = guess; } } checker = player[0] + player[1] + player[2] + player[3] + player[4] + player[5]; if (checker = word[6]) { win = true; } } print "You win!";
as you can see from my pseudo code,each letter from the word will be split up into an array.
i know most of you are experts at visual basic etc. but im just a novice please assist me with what ive done so far,thank you!
•
•
Join Date: Mar 2006
Posts: 8
Reputation:
Solved Threads: 1
im guessing part of the code would be something like this..
Help with Code Tags
(Toggle Plain Text)
If text1 = text2
Then Image.Show
If text1 = text2 Then Image.Show
i have also written some pseudo code to start it off
Help with Code Tags
(Toggle Plain Text)
i have got a visual basic book from a library and it has all the basics on everything ,but im still stumped as how to start things off in terms of actually writing the code.What things in the book should i focus on in this type of game???
as you can see from my pseudo code,each letter from the word will be split up into an array.
i know most of you are experts at visual basic etc. but im just a novice please assist me with what ive done so far,thank you![/QUOTE]
Help with Code Tags
(Toggle Plain Text)
If text1 = text2
Then Image.Show
If text1 = text2 Then Image.Show
i have also written some pseudo code to start it off
Help with Code Tags
(Toggle Plain Text)
fullword = "jungle";
word = ("j","u","n","g","l","e");
player = ("-","-","-","-","-","-");
while (win = false) {
print "So far, you have.. " + player;
print "What is your next guess? ";
input guess;
for (i = 0; i < 6; i++) {
if (guess = word[i]) {
player[i] = guess;
}
' just add the folliwing
else
{
textbox.text=""
textbox.disable=true
} }
checker = player[0] + player[1] + player[2] + player[3] + player[4] + player[5];
if (checker = word[6]) {
win = true;
}
}
print "You win!";
fullword = "jungle"; word = ("j","u","n","g","l","e"); player = ("-","-","-","-","-","-"); while (win = false) { print "So far, you have.. " + player; print "What is your next guess? "; input guess; for (i = 0; i < 6; i++) { if (guess = word[i]) { player[i] = guess; } } checker = player[0] + player[1] + player[2] + player[3] + player[4] + player[5]; if (checker = word[6]) { win = true; } } print "You win!";as you can see from my pseudo code,each letter from the word will be split up into an array.
i know most of you are experts at visual basic etc. but im just a novice please assist me with what ive done so far,thank you![/QUOTE]
•
•
Join Date: Mar 2006
Posts: 8
Reputation:
Solved Threads: 1
[QUOTE=qinise4;664813]im guessing part of the code would be something like this..
Help with Code Tags
(Toggle Plain Text)
If text1 = text2
Then Image.Show
If text1 = text2 Then Image.Show
i have also written some pseudo code to start it off
Help with Code Tags
(Toggle Plain Text)
[code]
fullword = "jungle";
word = ("j","u","n","g","l","e");
player = ("-","-","-","-","-","-");
while (win = false) {
print "So far, you have.. " + player;
print "What is your next guess? ";
input guess;
for (i = 0; i < 6; i++) {
if (guess = word[i]) {
player[i] = guess;
}
' just add the folliwing
else
{
textbox.text=""
textbox.disable=true
break;
} }
checker = player[0] + player[1] + player[2] + player[3] + player[4] + player[5];
if (checker = word[6]) {
win = true;
}
}
print "You win!";
Your code should be like
counter = 0
While (win = false)
print "So far, you have.. " + player;
print "What is your next guess? ";
input guess;
if counter < word.length {
if (guess = word[counter]) {
player[counter] = guess;
}
else
{
textbox.text=""
textbox.disable=true
break;
win=true
}
}
else
{
break;
}
counter = counter + 1
}
If counter = word.length
{
print "you win"
}
Help with Code Tags
(Toggle Plain Text)
If text1 = text2
Then Image.Show
If text1 = text2 Then Image.Show
i have also written some pseudo code to start it off
Help with Code Tags
(Toggle Plain Text)
[code]
fullword = "jungle";
word = ("j","u","n","g","l","e");
player = ("-","-","-","-","-","-");
while (win = false) {
print "So far, you have.. " + player;
print "What is your next guess? ";
input guess;
for (i = 0; i < 6; i++) {
if (guess = word[i]) {
player[i] = guess;
}
' just add the folliwing
else
{
textbox.text=""
textbox.disable=true
break;
} }
checker = player[0] + player[1] + player[2] + player[3] + player[4] + player[5];
if (checker = word[6]) {
win = true;
}
}
print "You win!";
Your code should be like
counter = 0
While (win = false)
print "So far, you have.. " + player;
print "What is your next guess? ";
input guess;
if counter < word.length {
if (guess = word[counter]) {
player[counter] = guess;
}
else
{
textbox.text=""
textbox.disable=true
break;
win=true
}
}
else
{
break;
}
counter = counter + 1
}
If counter = word.length
{
print "you win"
}
•
•
Join Date: Nov 2007
Posts: 140
Reputation:
Solved Threads: 15
Sorry, left my eyes in bed yesterday... I just re-read through and saw you did say psuedo code... duh @ me 
For information, this is the right forum for VB6.
I'll have a read through it tomorrow and see if I can come up with something for you. It's just after 1am here now and I've had a few drinks, so chances are I'd fail miserably if I tried coding now!
Sorry for my earlier dozy post...

For information, this is the right forum for VB6.
I'll have a read through it tomorrow and see if I can come up with something for you. It's just after 1am here now and I've had a few drinks, so chances are I'd fail miserably if I tried coding now!

Sorry for my earlier dozy post...
•
•
Join Date: Nov 2007
Posts: 140
Reputation:
Solved Threads: 15
Hm, can't edit my last post... I presume it was a while ago at least.
Apologies if this is a bit rough around the edges, but as I said before, I am a little rough around the edges myself at the moment *hic*
I've got the concept working, I'll have another look tomorrow evening, but it should get you started.
I've created a form which contains the following:
2x labels: Label1 and lblGuesses
3x text boxes: txtWord, txtGuessWord and txtLetterGuess
2x command buttons: Command1 and Command2
My source:
Basically, the idea is you enter a word into txtGuessWord (while the player is not looking - there could be alternative methods of getting a new word in... this is just a concept for now) and click Command1.
This will populate the txtWord field with hyphens ("-").
Enter a letter in txtLetterGuess and press Command2, it will check the array (arrWord) which contains the full word, and if it exists, it will update txtWord and another array containing the revealed word so far (arrLetters).
If the letter does not exist, it will mark it in lblGuesses (I used a font with strike-through for this label to show it does not exist - you may choose to do this differently)
Label1 will update to ask for the next letter until all letters have been revealed when it says "winner!".
Hope that helps a bit, I will look into it in more detail tomorrow when I get chance and should be in a position to post some updated code.
Apologies if this is a bit rough around the edges, but as I said before, I am a little rough around the edges myself at the moment *hic*

I've got the concept working, I'll have another look tomorrow evening, but it should get you started.
I've created a form which contains the following:
2x labels: Label1 and lblGuesses
3x text boxes: txtWord, txtGuessWord and txtLetterGuess
2x command buttons: Command1 and Command2
My source:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Option Explicit Private strWord As String Private strGuessLetter As String Private arrWord As Variant Private arrLetters As Variant Private intTotalLetters As Integer Private Sub Command1_Click() Dim i As Integer strWord = txtGuessWord.Text txtGuessWord.Text = "-" intTotalLetters = Len(strWord) ReDim arrWord(intTotalLetters) As String ReDim arrLetters(intTotalLetters) As String For i = 1 To intTotalLetters arrWord(i) = Mid(strWord, i, 1) arrLetters(i) = "-" txtWord.Text = txtWord.Text & arrLetters(i) & " " Next End Sub Private Sub Command2_Click() Dim i As Integer, o As Integer Dim blnGuess As Boolean strGuessLetter = txtLetterGuess.Text txtLetterGuess.Text = vbNullString For i = 1 To intTotalLetters If arrWord(i) = strGuessLetter Then arrLetters(i) = strGuessLetter txtWord.Text = vbNullString For o = 1 To intTotalLetters txtWord.Text = txtWord.Text & arrLetters(o) & " " Next blnGuess = True Else If blnGuess Then 'nothing Else 'letter is not in list blnGuess = False End If End If Next If blnGuess = False Then lblGuesses.Caption = lblGuesses.Caption & " " & strGuessLetter End If If InStr(1, txtWord.Text, "-") = 0 Then Label1.Caption = "winner!" Else Label1.Caption = "enter your next letter" End If End Sub
Basically, the idea is you enter a word into txtGuessWord (while the player is not looking - there could be alternative methods of getting a new word in... this is just a concept for now) and click Command1.
This will populate the txtWord field with hyphens ("-").
Enter a letter in txtLetterGuess and press Command2, it will check the array (arrWord) which contains the full word, and if it exists, it will update txtWord and another array containing the revealed word so far (arrLetters).
If the letter does not exist, it will mark it in lblGuesses (I used a font with strike-through for this label to show it does not exist - you may choose to do this differently)
Label1 will update to ask for the next letter until all letters have been revealed when it says "winner!".
Hope that helps a bit, I will look into it in more detail tomorrow when I get chance and should be in a position to post some updated code.
•
•
Join Date: Nov 2007
Posts: 140
Reputation:
Solved Threads: 15
This actually got me thinking... and gave me something to try out.
To be honest, it will come in extremely useful for my son to play on when he gets a little older
I've completed it with a bit of a hangman aswell.
Again, perhaps not the cleanest code, I would have used a control array for the shapes but for the head being a circle, but the rest being lines so it wouldn't work hence the select statement.
I've attached the project on here rather than posting more code (as I've added the hangman on and relabelled some of the control objects).
If it is what you are looking for and it solves your problem, please mark the thread as solved to boost my ego/make my head bigger
Any problems, give me a shout.
Jon
To be honest, it will come in extremely useful for my son to play on when he gets a little older

I've completed it with a bit of a hangman aswell.
Again, perhaps not the cleanest code, I would have used a control array for the shapes but for the head being a circle, but the rest being lines so it wouldn't work hence the select statement.
I've attached the project on here rather than posting more code (as I've added the hangman on and relabelled some of the control objects).
If it is what you are looking for and it solves your problem, please mark the thread as solved to boost my ego/make my head bigger

Any problems, give me a shout.
Jon
•
•
Join Date: Aug 2008
Posts: 16
Reputation:
Solved Threads: 0
^^gr8 job so far,but there are a few things that could be improved ,id do them myself but im a novice...
is it possible to not be able to type into the top text box,as i dont think its neccessary because it can be wiped etc.
i think it would be better if there was a button that can clear the text box.Maybe it should be a label instead so there is no interference from users.
ummm how would u change the code so that u can only enter in one letter at a time??
for instance if the word is "jungle" and my son enters in the letters "ja" it is seen as an incorrect guess and there are strikes throughout the letters "Ja" so naturally my son would think that the two letters are incorrect.
Also,if u enter in a word ,more letters can be added to that word in the "enter word" text box making unreal words that would be impossible to guess,this can confuse my son and may create many problems , i think...
Also only letters should be able to be entered other wise,numbers and symbols could be in the word and could potentially confuse my son and urs...
is it possible to not be able to type into the top text box,as i dont think its neccessary because it can be wiped etc.
i think it would be better if there was a button that can clear the text box.Maybe it should be a label instead so there is no interference from users.
ummm how would u change the code so that u can only enter in one letter at a time??
for instance if the word is "jungle" and my son enters in the letters "ja" it is seen as an incorrect guess and there are strikes throughout the letters "Ja" so naturally my son would think that the two letters are incorrect.
Also,if u enter in a word ,more letters can be added to that word in the "enter word" text box making unreal words that would be impossible to guess,this can confuse my son and may create many problems , i think...
Also only letters should be able to be entered other wise,numbers and symbols could be in the word and could potentially confuse my son and urs...
Last edited by Lil' Tripsturr; Aug 15th, 2008 at 11:15 pm.
![]() |
Similar Threads
- Projects for the Beginner (Python)
- hangman game in C++ (C++)
- Help with hangman tutorial. (C++)
- C++ Programming issue (C++)
- Having Some Trouble with Methods (Java)
- reading(printing to screen) program (Python)
- Code Confusion (C#)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: inserting Serial No in Report
- Next Thread: Data grid addition problem?
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





