Simple Hangman Game

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 16
Reputation: Lil' Tripsturr is an unknown quantity at this point 
Solved Threads: 0
Lil' Tripsturr Lil' Tripsturr is offline Offline
Newbie Poster

Simple Hangman Game

 
0
  #1
Aug 7th, 2008
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)
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. fullword = "jungle";
  3. word = ("j","u","n","g","l","e");
  4. player = ("-","-","-","-","-","-");
  5.  
  6. while (win = false) {
  7. print "So far, you have.. " + player;
  8. print "What is your next guess? ";
  9. input guess;
  10.  
  11. for (i = 0; i < 6; i++) {
  12. if (guess = word[i]) {
  13. player[i] = guess;
  14. }
  15. }
  16.  
  17. checker = player[0] + player[1] + player[2] + player[3] + player[4] + player[5];
  18. if (checker = word[6]) {
  19. win = true;
  20. }
  21. }
  22.  
  23. print "You win!";
  24.  
  25. 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!";
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!
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 8
Reputation: qinise4 is an unknown quantity at this point 
Solved Threads: 1
qinise4 qinise4 is offline Offline
Newbie Poster

Re: Simple Hangman Game

 
0
  #2
Aug 7th, 2008
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)
 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!";
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]
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 8
Reputation: qinise4 is an unknown quantity at this point 
Solved Threads: 1
qinise4 qinise4 is offline Offline
Newbie Poster

Re: Simple Hangman Game

 
0
  #3
Aug 7th, 2008
[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"
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 140
Reputation: jonifen is an unknown quantity at this point 
Solved Threads: 15
jonifen jonifen is offline Offline
Junior Poster

Re: Simple Hangman Game

 
0
  #4
Aug 8th, 2008
That doesn't look like Classic VB (4/5/6) to me...
Is it .NET?
Last edited by jonifen; Aug 8th, 2008 at 6:22 pm. Reason: Edit
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 16
Reputation: Lil' Tripsturr is an unknown quantity at this point 
Solved Threads: 0
Lil' Tripsturr Lil' Tripsturr is offline Offline
Newbie Poster

Re: Simple Hangman Game

 
0
  #5
Aug 9th, 2008
^^^i dont know ,all i know is that i need help with making a Hangman game for my 7 year old kid and its in microsoft visual basic 6.0 ,can someone please help me, i asked for help a week ago and still have recieved none!!
no1 has guided me to the correct forums or anything !!
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 140
Reputation: jonifen is an unknown quantity at this point 
Solved Threads: 15
jonifen jonifen is offline Offline
Junior Poster

Re: Simple Hangman Game

 
0
  #6
Aug 9th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 140
Reputation: jonifen is an unknown quantity at this point 
Solved Threads: 15
jonifen jonifen is offline Offline
Junior Poster

Re: Simple Hangman Game

 
0
  #7
Aug 9th, 2008
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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Private strWord As String
  4. Private strGuessLetter As String
  5. Private arrWord As Variant
  6. Private arrLetters As Variant
  7. Private intTotalLetters As Integer
  8.  
  9. Private Sub Command1_Click()
  10. Dim i As Integer
  11.  
  12. strWord = txtGuessWord.Text
  13. txtGuessWord.Text = "-"
  14.  
  15. intTotalLetters = Len(strWord)
  16.  
  17. ReDim arrWord(intTotalLetters) As String
  18. ReDim arrLetters(intTotalLetters) As String
  19.  
  20. For i = 1 To intTotalLetters
  21. arrWord(i) = Mid(strWord, i, 1)
  22. arrLetters(i) = "-"
  23. txtWord.Text = txtWord.Text & arrLetters(i) & " "
  24. Next
  25.  
  26.  
  27.  
  28. End Sub
  29.  
  30. Private Sub Command2_Click()
  31. Dim i As Integer, o As Integer
  32. Dim blnGuess As Boolean
  33.  
  34. strGuessLetter = txtLetterGuess.Text
  35. txtLetterGuess.Text = vbNullString
  36.  
  37. For i = 1 To intTotalLetters
  38. If arrWord(i) = strGuessLetter Then
  39. arrLetters(i) = strGuessLetter
  40. txtWord.Text = vbNullString
  41. For o = 1 To intTotalLetters
  42. txtWord.Text = txtWord.Text & arrLetters(o) & " "
  43. Next
  44. blnGuess = True
  45. Else
  46. If blnGuess Then
  47. 'nothing
  48. Else
  49. 'letter is not in list
  50. blnGuess = False
  51. End If
  52. End If
  53. Next
  54. If blnGuess = False Then
  55. lblGuesses.Caption = lblGuesses.Caption & " " & strGuessLetter
  56. End If
  57.  
  58. If InStr(1, txtWord.Text, "-") = 0 Then
  59. Label1.Caption = "winner!"
  60. Else
  61. Label1.Caption = "enter your next letter"
  62. End If
  63. 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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 16
Reputation: Lil' Tripsturr is an unknown quantity at this point 
Solved Threads: 0
Lil' Tripsturr Lil' Tripsturr is offline Offline
Newbie Poster

Re: Simple Hangman Game

 
0
  #8
Aug 12th, 2008
^^thank u so far im trying it myself now,ill post later
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 140
Reputation: jonifen is an unknown quantity at this point 
Solved Threads: 15
jonifen jonifen is offline Offline
Junior Poster

Re: Simple Hangman Game

 
0
  #9
Aug 13th, 2008
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
Attached Files
File Type: zip Hangman.zip (2.8 KB, 47 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 16
Reputation: Lil' Tripsturr is an unknown quantity at this point 
Solved Threads: 0
Lil' Tripsturr Lil' Tripsturr is offline Offline
Newbie Poster

Re: Simple Hangman Game

 
0
  #10
Aug 15th, 2008
^^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...
Last edited by Lil' Tripsturr; Aug 15th, 2008 at 11:15 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC