8 Replies - 225 Views - Last Post: 09 January 2018 - 09:45 AM Rate Topic: -----

Poll: Load words from Array Hangman Game (0 member(s) have cast votes)

Does this unit deserves help from fellow human beings?

  1. Yes (0 votes [0.00%])

    Percentage of vote: 0.00%

  2. No (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote

#1 DarknessSoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-January 18

Load words from Array Hangman Game

Posted 09 January 2018 - 08:13 AM

Hi, I beg you to help me. I can't... just can't figure out what to do...how to do...I try for months but I am just talentless.
I need to load words to my hangman game from an array. I just beg you to help me with that. Please...
If anyone can help me, pleasem here is the inital code from a tutorial that I need to put loading from the array into...thanks
Public Class Form1
    Dim Secret_Word As String
    Const FLAG As Char = "!"
    Dim NumGuesses As Integer = 0    'How Many Guesses we have taken.  You loose at 9
    Dim wordGuess As String
    Dim tempWord As String  ' Temporary word to display  Will include dashes when not guessed
    Dim endGame As Boolean
    Dim NumWrong As Integer

    Sub DisableButtons()

        Button1.Enabled = False
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
        Button5.Enabled = False
        Button6.Enabled = False
        Button7.Enabled = False
        Button8.Enabled = False
        Button9.Enabled = False
        Button10.Enabled = False
        Button11.Enabled = False
        Button12.Enabled = False
        Button13.Enabled = False
        Button14.Enabled = False
        Button15.Enabled = False
        Button16.Enabled = False
        Button17.Enabled = False
        Button18.Enabled = False
        Button19.Enabled = False
        Button20.Enabled = False
        Button21.Enabled = False
        Button22.Enabled = False
        Button23.Enabled = False
        Button24.Enabled = False
        Button25.Enabled = False
        Button26.Enabled = False

    End Sub

    Sub EnableButtons()
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        Button5.Enabled = True
        Button6.Enabled = True
        Button7.Enabled = True
        Button8.Enabled = True
        Button9.Enabled = True
        Button10.Enabled = True
        Button11.Enabled = True
        Button12.Enabled = True
        Button13.Enabled = True
        Button14.Enabled = True
        Button15.Enabled = True
        Button16.Enabled = True
        Button17.Enabled = True
        Button18.Enabled = True
        Button19.Enabled = True
        Button20.Enabled = True
        Button21.Enabled = True
        Button22.Enabled = True
        Button23.Enabled = True
        Button24.Enabled = True
        Button25.Enabled = True
        Button26.Enabled = True

    End Sub

    Sub LoadLabelDisplay()
        lblTempWord.Text = ""
        Dim LengthOfSecretWord As Integer
        LengthOfSecretWord = Secret_Word.Length - 1
        Dim LetterPosition As Integer
        For LetterPosition = 0 To LengthOfSecretWord
            lblTempWord.Text = lblTempWord.Text & "-"
        Next
    End Sub

    Sub GuessLetter(LetterGuess As String)
        Dim strGuessedSoFar As String = lblTempWord.Text
        Dim LengthOfSecretWord As Integer
        LengthOfSecretWord = Secret_Word.Length - 1
        tempWord = ""
        Dim letterPosition As Integer
        For letterPosition = 0 To LengthOfSecretWord

            If Secret_Word.Substring(letterPosition, 1) = LetterGuess Then
                tempWord = tempWord & LetterGuess
            Else
                tempWord = tempWord & lblTempWord.Text.Substring(letterPosition, 1)
            End If

        Next
        lblTempWord.Text = tempWord

        If lblTempWord.Text = Secret_Word Then 'YOU WIN
            DisableButtons()
            btnStart.Enabled = True
            MsgBox("YOU WIN")
        End If

        If lblTempWord.Text = strGuessedSoFar Then
            NumWrong = NumWrong + 1
        End If


        DisplayHangman(NumWrong)
    End Sub
    Sub DisplayHangman(NumWrong As Integer)
        'SELECT CASE

        If NumWrong = 0 Then
            Me.PictureBox1.Image = My.Resources._0
        End If

        If NumWrong = 1 Then
            Me.PictureBox1.Image = My.Resources._1
        End If

        If NumWrong = 2 Then
            Me.PictureBox1.Image = My.Resources._2
        End If

        If NumWrong = 3 Then
            Me.PictureBox1.Image = My.Resources._3
        End If

        If NumWrong = 4 Then
            Me.PictureBox1.Image = My.Resources._4
        End If

        If NumWrong = 5 Then
            Me.PictureBox1.Image = My.Resources._5
        End If

        If NumWrong = 6 Then
            Me.PictureBox1.Image = My.Resources._6
        End If

        If NumWrong = 7 Then
            Me.PictureBox1.Image = My.Resources._7
            MsgBox("YOU LOST")
            DisableButtons()
            btnStart.Enabled = True
        End If
    End Sub

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        'Disable Buttons
        DisableButtons()
        'Clear the display
        lblTempWord.Text = ""
    End Sub

    Private Sub btnStart_Click(sender As System.Object, e As System.EventArgs) Handles btnStart.Click

        EnableButtons()
        btnStart.Enabled = False
        'Load up the temp word label with dashes
        Secret_Word = "VELOCITY"
        LoadLabelDisplay()
        NumWrong = 0
        DisplayHangman(NumWrong)
    End Sub


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Button1.Enabled = False
        GuessLetter(Button1.Text)
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Button2.Enabled = False
        GuessLetter(Button2.Text)
    End Sub

    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        Button3.Enabled = False
        GuessLetter(Button3.Text)
    End Sub

    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
        Button4.Enabled = False
        GuessLetter(Button4.Text)
    End Sub

    Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
        Button5.Enabled = False
        GuessLetter(Button5.Text)
    End Sub

    Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
        Button6.Enabled = False
        GuessLetter(Button6.Text)
    End Sub

    Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
        Button7.Enabled = False
        GuessLetter(Button7.Text)
    End Sub

    Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
        Button8.Enabled = False
        GuessLetter(Button8.Text)
    End Sub

    Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles Button9.Click
        Button9.Enabled = False
        GuessLetter(Button9.Text)
    End Sub

    Private Sub Button10_Click(sender As System.Object, e As System.EventArgs) Handles Button10.Click
        Button10.Enabled = False
        GuessLetter(Button10.Text)
    End Sub

    Private Sub Button11_Click(sender As System.Object, e As System.EventArgs) Handles Button11.Click
        Button11.Enabled = False
        GuessLetter(Button11.Text)
    End Sub

    Private Sub Button12_Click(sender As System.Object, e As System.EventArgs) Handles Button12.Click
        Button12.Enabled = False
        GuessLetter(Button12.Text)
    End Sub

    Private Sub Button13_Click(sender As System.Object, e As System.EventArgs) Handles Button13.Click
        Button13.Enabled = False
        GuessLetter(Button13.Text)
    End Sub

    Private Sub Button14_Click(sender As System.Object, e As System.EventArgs) Handles Button14.Click
        Button14.Enabled = False
        GuessLetter(Button14.Text)
    End Sub

    Private Sub Button15_Click(sender As System.Object, e As System.EventArgs) Handles Button15.Click
        Button15.Enabled = False
        GuessLetter(Button15.Text)
    End Sub

    Private Sub Button16_Click(sender As System.Object, e As System.EventArgs) Handles Button16.Click
        Button16.Enabled = False
        GuessLetter(Button16.Text)
    End Sub

    Private Sub Button17_Click(sender As System.Object, e As System.EventArgs) Handles Button17.Click
        Button17.Enabled = False
        GuessLetter(Button17.Text)
    End Sub

    Private Sub Button18_Click(sender As System.Object, e As System.EventArgs) Handles Button18.Click
        Button18.Enabled = False
        GuessLetter(Button18.Text)
    End Sub

    Private Sub Button19_Click(sender As System.Object, e As System.EventArgs) Handles Button19.Click
        Button19.Enabled = False
        GuessLetter(Button19.Text)
    End Sub

    Private Sub Button20_Click(sender As System.Object, e As System.EventArgs) Handles Button20.Click
        Button20.Enabled = False
        GuessLetter(Button20.Text)
    End Sub

    Private Sub Button21_Click(sender As System.Object, e As System.EventArgs) Handles Button21.Click
        Button21.Enabled = False
        GuessLetter(Button21.Text)
    End Sub

    Private Sub Button22_Click(sender As System.Object, e As System.EventArgs) Handles Button22.Click
        Button22.Enabled = False
        GuessLetter(Button22.Text)
    End Sub

    Private Sub Button23_Click(sender As System.Object, e As System.EventArgs) Handles Button23.Click
        Button23.Enabled = False
        GuessLetter(Button23.Text)
    End Sub

    Private Sub Button24_Click(sender As System.Object, e As System.EventArgs) Handles Button24.Click
        Button24.Enabled = False
        GuessLetter(Button24.Text)
    End Sub

    Private Sub Button25_Click(sender As System.Object, e As System.EventArgs) Handles Button25.Click
        Button25.Enabled = False
        GuessLetter(Button25.Text)
    End Sub

    Private Sub Button26_Click(sender As System.Object, e As System.EventArgs) Handles Button26.Click
        Button26.Enabled = False
        GuessLetter(Button26.Text)
    End Sub
End Class 


Is This A Good Question/Topic? 0
  • +

Replies To: Load words from Array Hangman Game

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 14033
  • View blog
  • Posts: 56,136
  • Joined: 12-June 08

Re: Load words from Array Hangman Game

Posted 09 January 2018 - 08:15 AM

What's up with that poll?

Quote

Does this unit deserves help from fellow human beings?


Ick.. those button/variable names stink.

Where, in all of that, are you attempting to do something with strings and an array?
Was This Post Helpful? 1
  • +
  • -

#3 DarknessSoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-January 18

Re: Load words from Array Hangman Game

Posted 09 January 2018 - 08:26 AM

View Postmodi123_1, on 09 January 2018 - 08:15 AM, said:

What's up with that poll?

Quote

Does this unit deserves help from fellow human beings?


Ick.. those button/variable names stink.

Where, in all of that, are you attempting to do something with strings and an array?


Those buttons yes are named badly, they are an alphabet kind of. Button 1 for A, button 26 for Z.
My bad, I uploaded the wrong code...There is no array for words... what a shame...gonna just go hide somewhere and hurt myself see you next time sorry(((
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 14033
  • View blog
  • Posts: 56,136
  • Joined: 12-June 08

Re: Load words from Array Hangman Game

Posted 09 January 2018 - 08:30 AM

Quote

My bad, I uploaded the wrong code...There is no array for words.

So.. post it here? Shouldn't be that big of a deal.

Quote

gonna just go hide somewhere and hurt myself see you next time sorry(((

Sack up and stop being a drama queen. Feigning running away and self harm is not appropriate.
Was This Post Helpful? 1
  • +
  • -

#5 DarknessSoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-January 18

Re: Load words from Array Hangman Game

Posted 09 January 2018 - 08:32 AM

Okay thanks you are very kind. I will post it in a few hours and I don't access to it as I am not writing from my own pc now, thank you very much

This post has been edited by andrewsw: 09 January 2018 - 09:30 AM
Reason for edit:: removed unnecessary quote, just use the REPLY button

Was This Post Helpful? 0
  • +
  • -

#6 DarknessSoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-January 18

Re: Load words from Array Hangman Game

Posted 09 January 2018 - 09:28 AM

Hi thanks I found the code on my pc it is from tutorial as well

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
        Dim strwoord As String
        Dim objrandom As New Random
        Dim intteller As Integer
        Dim arrwoorden(3) As String
        Dim intwrongguess As Integer = 0
        Dim intRandom As Integer
        Dim blnpresent As Boolean
        Dim chrguesbo As Char
        Const cstrletters As String = "abcdefghijklmnopqrstuvwxyz"
        lblWord.Text = String.Empty
        PictureBox1.Visible = False
        lstLetters.Items.Clear()
        intRandom = objrandom.Next(1, 4)
        arrwoorden(1) = "printer"
        arrwoorden(2) = "phone"
        arrwoorden(3) = "teleportation"
        strwoord = arrwoorden(intRandom)

        Select Case intRandom
            Case Is = 1
               
                Me.lblWord.Text = "------"
            Case Is = 2
                
                Me.lblWord.Text = "-----"
            Case Is = 3
                
                Me.lblWord.Text = "-------------"
        End Select

        strwoord.ToCharArray()
        Do
            chrguesbo = InputBox("Give a letter from a-z").ToLower
            If InStr(cstrletters, chrguesbo) = 0 Then
                MessageBox.Show("you can only use letters")
            Else
                If lstLetters.Items.Contains(chrguesbo) = False Then
                    blnpresent = False
                    lstLetters.Items.Add(chrguesbo)
                    For intteller = 0 To Integer.Parse(arrwoorden(intRandom).Length - 1) Step 1
                        If strwoord(intteller) = chrguesbo Then
                            Me.lblWord.Text = lblWord.Text.Remove(intteller, 1)
                            Me.lblWord.Text = lblWord.Text.Insert(intteller, chrguesbo)
                            blnpresent = True
                        End If

                    Next
                    If blnpresent = False Then
                        PictureBox1.Visible = True
                        PictureBox1.Image = lisHangman.Images(intwrongguess)
                        intwrongguess += 1
                    End If
                Else
                    MessageBox.Show("Letter has already been used before")

                End If
            End If
        Loop Until lblWord.Text = arrwoorden(intRandom) Or intwrongguess = 6
        If intwrongguess = 6 Then
            MessageBox.Show("You lost the game. To play again press the button. The correct word was " & arrwoorden(intRandom).ToString, "Lost")
        Else
            If lblWord.Text = arrwoorden(intRandom) Then
                MessageBox.Show("You won the game", "Won")
            End If
        End If


    End Sub
End Class


This post has been edited by andrewsw: 09 January 2018 - 09:30 AM
Reason for edit:: removed unnecessary quote, just use the REPLY button

Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 14033
  • View blog
  • Posts: 56,136
  • Joined: 12-June 08

Re: Load words from Array Hangman Game

Posted 09 January 2018 - 09:30 AM

Mkay.. I see an array.. I see a random variable getting the value at an index.

What's the issue?
Was This Post Helpful? 1
  • +
  • -

#8 DarknessSoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-January 18

Re: Load words from Array Hangman Game

Posted 09 January 2018 - 09:40 AM

View Postmodi123_1, on 09 January 2018 - 09:30 AM, said:

Mkay.. I see an array.. I see a random variable getting the value at an index.

What's the issue?

I just... can't figure out how to make it load words into the array... Is that an easy thing to do?
I think I need to use some streamreader but I don't know how to use it, and where to put, to make it work
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 14033
  • View blog
  • Posts: 56,136
  • Joined: 12-June 08

Re: Load words from Array Hangman Game

Posted 09 January 2018 - 09:45 AM

Oh.. you mean read words from a text file into a collection? Yes.. stream reader would do you well. There is the 'read line' which you should most likely pay attention to.

https://msdn.microso...(v=vs.110).aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1