hi everybody
I have a project to write the code for the hangman game and i got stuck now :sad: :cry:

The game should allow the user to choose if he/she wants to view the man as stick figure or a picture
in the stick figure i should write the code which draw circle or lines for the stick man body

In addition the program should validate user's input for example it should display an error msg if the user input ? or % or &..etc

I will pase the full version of my code with the form design and I would be grateful if someone can help me :cry:

Imports System.IO
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Drawing
Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim mst As MasterForm = New MasterForm
    Dim hmp As hangManPic = New hangManPic
    Dim objColl As StringCollection
    Dim objColl2 As StringCollection
    Dim objRand As Random = New Random
    Dim word As String
    Dim int As Integer
    Dim cnt As Integer = 0
    Dim graf As Graphics
    Dim blackPen As New Pen(Color.Black, 3)

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtWord As System.Windows.Forms.TextBox
    Friend WithEvents txtGuess As System.Windows.Forms.TextBox
    Friend WithEvents btnAddNewWord As System.Windows.Forms.Button
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents btnTips As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents btnNewGame As System.Windows.Forms.Button
    Friend WithEvents lblOutput As System.Windows.Forms.Label
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents rdbStickMan As System.Windows.Forms.RadioButton
    Friend WithEvents rdbPicture As System.Windows.Forms.RadioButton
    Friend WithEvents lblBodyParts As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.txtWord = New System.Windows.Forms.TextBox
        Me.btnAddNewWord = New System.Windows.Forms.Button
        Me.txtGuess = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.btnTips = New System.Windows.Forms.Button
        Me.btnExit = New System.Windows.Forms.Button
        Me.btnNewGame = New System.Windows.Forms.Button
        Me.lblOutput = New System.Windows.Forms.Label
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.rdbStickMan = New System.Windows.Forms.RadioButton
        Me.rdbPicture = New System.Windows.Forms.RadioButton
        Me.lblBodyParts = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(40, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "The Word:"
        '
        'txtWord
        '
        Me.txtWord.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txtWord.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtWord.ForeColor = System.Drawing.Color.ForestGreen
        Me.txtWord.Location = New System.Drawing.Point(40, 32)
        Me.txtWord.Name = "txtWord"
        Me.txtWord.ReadOnly = True
        Me.txtWord.Size = New System.Drawing.Size(232, 26)
        Me.txtWord.TabIndex = 2
        Me.txtWord.Text = ""
        '
        'btnAddNewWord
        '
        Me.btnAddNewWord.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnAddNewWord.Location = New System.Drawing.Point(528, 232)
        Me.btnAddNewWord.Name = "btnAddNewWord"
        Me.btnAddNewWord.Size = New System.Drawing.Size(96, 24)
        Me.btnAddNewWord.TabIndex = 3
        Me.btnAddNewWord.Text = "Edit the list"
        '
        'txtGuess
        '
        Me.txtGuess.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtGuess.Location = New System.Drawing.Point(144, 384)
        Me.txtGuess.MaxLength = 1
        Me.txtGuess.Name = "txtGuess"
        Me.txtGuess.Size = New System.Drawing.Size(24, 26)
        Me.txtGuess.TabIndex = 1
        Me.txtGuess.Text = ""
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(40, 384)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96, 23)
        Me.Label2.TabIndex = 5
        Me.Label2.Text = "Guess a Letter:"
        '
        'btnTips
        '
        Me.btnTips.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnTips.Location = New System.Drawing.Point(528, 176)
        Me.btnTips.Name = "btnTips"
        Me.btnTips.Size = New System.Drawing.Size(96, 23)
        Me.btnTips.TabIndex = 6
        Me.btnTips.Text = "Tips"
        '
        'btnExit
        '
        Me.btnExit.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnExit.Location = New System.Drawing.Point(528, 296)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(96, 23)
        Me.btnExit.TabIndex = 7
        Me.btnExit.Text = "Exit"
        '
        'btnNewGame
        '
        Me.btnNewGame.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnNewGame.Location = New System.Drawing.Point(528, 120)
        Me.btnNewGame.Name = "btnNewGame"
        Me.btnNewGame.Size = New System.Drawing.Size(96, 23)
        Me.btnNewGame.TabIndex = 8
        Me.btnNewGame.Text = "New Game"
        '
        'lblOutput
        '
        Me.lblOutput.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblOutput.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblOutput.ForeColor = System.Drawing.Color.Firebrick
        Me.lblOutput.Location = New System.Drawing.Point(216, 368)
        Me.lblOutput.Name = "lblOutput"
        Me.lblOutput.Size = New System.Drawing.Size(408, 32)
        Me.lblOutput.TabIndex = 9
        '
        'Panel1
        '
        Me.Panel1.Location = New System.Drawing.Point(40, 101)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(232, 248)
        Me.Panel1.TabIndex = 10
        '
        'PictureBox1
        '
        Me.PictureBox1.Location = New System.Drawing.Point(304, 110)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(208, 240)
        Me.PictureBox1.TabIndex = 11
        Me.PictureBox1.TabStop = False
        '
        'rdbStickMan
        '
        Me.rdbStickMan.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.rdbStickMan.Location = New System.Drawing.Point(104, 72)
        Me.rdbStickMan.Name = "rdbStickMan"
        Me.rdbStickMan.TabIndex = 12
        Me.rdbStickMan.Text = "Stick Man"
        '
        'rdbPicture
        '
        Me.rdbPicture.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.rdbPicture.Location = New System.Drawing.Point(360, 73)
        Me.rdbPicture.Name = "rdbPicture"
        Me.rdbPicture.TabIndex = 13
        Me.rdbPicture.Text = "Picture"
        '
        'lblBodyParts
        '
        Me.lblBodyParts.Location = New System.Drawing.Point(528, 8)
        Me.lblBodyParts.Name = "lblBodyParts"
        Me.lblBodyParts.Size = New System.Drawing.Size(100, 104)
        Me.lblBodyParts.TabIndex = 14
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(640, 422)
        Me.Controls.Add(Me.lblBodyParts)
        Me.Controls.Add(Me.rdbPicture)
        Me.Controls.Add(Me.rdbStickMan)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.lblOutput)
        Me.Controls.Add(Me.btnNewGame)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.btnTips)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.txtGuess)
        Me.Controls.Add(Me.btnAddNewWord)
        Me.Controls.Add(Me.txtWord)
        Me.Controls.Add(Me.Label1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim objRe As StreamReader = New StreamReader("..\newWords.txt")
        Dim line As String = ""
        objColl = New StringCollection
        'Dim word As String

        Dim i As Integer

        'line = objRe.ReadLine()

        txtWord.Focus()

        Do
            line = objRe.ReadLine()
            If Not line = "" Then
                objColl.Add(line)
            End If
            'txtWord.Text = txtWord.Text & line & ControlChars.NewLine

        Loop Until line Is Nothing

        objRe.Close()

        int = objRand.Next(0, objColl.Count)
        word = objColl.Item(int)
        'MessageBox.Show(word)
        objColl2 = New StringCollection
        For i = 0 To word.Length - 1
            objColl2.Add("-  ")
            txtWord.Text &= objColl2.Item(i)

            If word.Chars(i) = " " Then
                objColl2.Item(i) = " "
            End If

        Next

        'For i = 0 To objColl2.Count - 1
        '    txtWord.Text &= objColl2.Item(i)
        'Next


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNewWord.Click
        mst.ShowDialog(Me)

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Close()
    End Sub

    Private Sub txtGuess_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGuess.TextChanged
        Dim i As Integer
        Dim bl As Boolean = False


        'If txtGuess.Text Then

        'End If

        lblOutput.Text &= txtGuess.Text & " "
        txtWord.Clear()
        For i = 0 To word.Length - 1
            If txtGuess.Text = word.Chars(i) Then
                objColl2.Item(i) = txtGuess.Text
                bl = True
            End If

        Next

        For i = 0 To objColl2.Count - 1
            txtWord.Text &= objColl2.Item(i)

            If txtWord.Text = word Then
                lblOutput.Text = "You win"
            End If
        Next
        txtGuess.SelectAll()


        'Dim strArray As String() = New String() {"head", "nick", "body", "rHand", "lHand", "rLeg", "lLeg", "rope"}
        'Dim j As Integer
        'Dim bodyPart As String
        'Dim b1 As Boolean = False

        'For j = 0 To 7
        '    If bl = False Then
        '        bodyPart = CStr(strArray.GetValue(j))
        '        lblBodyParts.Text = bodyPart & vbCrLf

        '    End If
        '    j += 1
        'Next

        If bl = False Then
            cnt += 1
            'DrawLineOnForm(graf, blackPen)
            Panel1.Refresh()
            If cnt = 8 Then
                lblOutput.Text = "You lose"
            End If
        End If

        'Dim ee As PaintEventArgs
        'Panel1.Show(DrawLineOnForm(ee))


    End Sub
    'Private Sub DrawLineOnForm(ByVal e As PaintEventArgs)
    '    Dim point1 As New Point(140, 200)
    '    Dim point2 As New Point(500, 100)
    '    'graph.DrawLine(penColor, 68, 10, 30, 40)
    '    e.Graphics.DrawLine(blackPen, point1, point2)
    'End Sub

    Private Sub btnNewGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewGame.Click
        cnt = 0
        Dim i As Integer
        txtWord.Focus()
        lblOutput.Text = ""
        txtGuess.Clear()
        txtWord.Clear()
        int = objRand.Next(0, objColl.Count)
        word = objColl.Item(int)
        'MessageBox.Show(word)
        objColl2 = New StringCollection
        For i = 0 To word.Length - 1
            objColl2.Add("?")
        Next

        For i = 0 To objColl2.Count - 1
            txtWord.Text &= objColl2.Item(i)
        Next
    End Sub
End Class

this is the main form code

Edited 3 Years Ago by pyTony: fixed formating

just copy and paste the code and test it
coz i know it looks very scary when i pasted it here :mrgreen:


and here is the masterForm code
which will allow the user to add new words or edit the list :D


Imports System.IO
Public Class MasterForm
Inherits System.Windows.Forms.Form
Dim objRe As StreamReader
Dim objWr As StreamWriter

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnAddNewWord As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents objOpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents txtNewWord As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.txtNewWord = New System.Windows.Forms.TextBox
Me.btnAddNewWord = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.objOpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.SuspendLayout()
'
'txtNewWord
'
Me.txtNewWord.Location = New System.Drawing.Point(72, 64)
Me.txtNewWord.Multiline = True
Me.txtNewWord.Name = "txtNewWord"
Me.txtNewWord.Size = New System.Drawing.Size(144, 144)
Me.txtNewWord.TabIndex = 0
Me.txtNewWord.Text = ""
'
'btnAddNewWord
'
Me.btnAddNewWord.Location = New System.Drawing.Point(88, 216)
Me.btnAddNewWord.Name = "btnAddNewWord"
Me.btnAddNewWord.Size = New System.Drawing.Size(112, 23)
Me.btnAddNewWord.TabIndex = 1
Me.btnAddNewWord.Text = "Add New Word"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(96, 32)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 2
Me.Label1.Text = "Enter a new word:"
'
'objOpenFileDialog1
'
Me.objOpenFileDialog1.CheckFileExists = False
Me.objOpenFileDialog1.FileName = "newWords.txt"
'
'MasterForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnAddNewWord)
Me.Controls.Add(Me.txtNewWord)
Me.Name = "MasterForm"
Me.Text = "MasterForm"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub btnAddNewWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNewWord.Click
objWr = New StreamWriter("..\newWords.txt")
objWr.WriteLine(txtNewWord.Text)
objWr.Flush()
objWr.Close()
End Sub


Private Sub MasterForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If File.Exists("..\newWords.txt") = True Then
objRe = New StreamReader("..\newWords.txt")
txtNewWord.Text = objRe.ReadToEnd
objRe.Close()
Else
objWr = New StreamWriter("..\newWords.txt")
objWr.Close()
End If

End Sub
End Class

This article has been dead for over six months. Start a new discussion instead.