F0rum God +
Geregistreerd op: 12 December 2007
Berichten: 24.954
|
probeer dit eens.
er zitten wel een aantal errors in, maar het geeft je een begin.
Private allPuzzles(1, 0) As String
Private allClues(0, 1) As String
Private LastPuzzle As Short
Dim btnTestNumButtons(26) As Button
Dim lbldisplayletters(0) As Label
Dim hangmanWord As String
Dim correctcounter As Integer = 0
Dim hangmanstage As String = "START"
Dim incorrect = False
Private Sub btnTestNumButtons_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Click
If sender.name = "" Then
For iIndex = 0 To hangmanWord.Length - 1
If hangmanWord.Substring(iIndex, 1) = sender.Text Then
lbldisplayletters(iIndex).Text = sender.Text
correctcounter += 1
incorrect = True
End If
Next iIndex
If incorrect = False Then
drawHangman()
End If
incorrect = False
sender.Enabled = False
sender.visible = False
If correctcounter = hangmanWord.Length Then
lblresult.Text = "YOU WIN"
lblGamesWon.Text = CInt(lblGamesWon.Text) + 1
lblGamesPlayed.Text = CInt(lblGamesPlayed.Text) + 1
disableconrols()
End If
End If
End Sub
Private Sub LoadGameData()
Dim puzzleno As Integer = 0
Dim outstream As New StreamReader(My.Application.Info.DirectoryPath & "\HMPuzz.dat")
Dim lineText As String
Dim puzzle() As String
Do Until outstream.EndOfStream
ReDim Preserve allPuzzles(1, puzzleno)
lineText = outstream.ReadLine()
If lineText <> Nothing Then
puzzle = lineText.Split(",")
allPuzzles(0, puzzleno) = puzzle(0)
allPuzzles(1, puzzleno) = puzzle(1)
puzzleno += 1
End If
Loop
outstream = New StreamReader(My.Application.Info.DirectoryPath & "\LastPuzz.dat")
Do Until outstream.EndOfStream
LastPuzzle = CShort(outstream.ReadLine())
Loop
outstream.Close()
Dim intFileNbr As Short
intFileNbr = FreeFile()
FileOpen(intFileNbr, (My.Application.Info.DirectoryPath & "\LastPuzz.dat"), OpenMode.Output)
If puzzleno - 1 < LastPuzzle Then
WriteLine(intFileNbr, 1)
FileClose(intFileNbr)
Else
WriteLine(intFileNbr, LastPuzzle + 1)
FileClose(intFileNbr)
End If
End Sub
Private Sub CreateButtonArray()
Dim shtIndex As Integer
Dim position As Integer = 30
Dim position2 As Integer = 30
For shtIndex = 0 To 25
btnTestNumButtons(shtIndex) = New System.Windows.Forms.Button()
With btnTestNumButtons(shtIndex)
.Text() = Chr(shtIndex + 65).ToString
.Size() = New Size(40, 40)
.FlatStyle() = FlatStyle.Popup
.BackColor() = System.Drawing.Color.Red
AddHandler .Click, AddressOf Me.btnTestNumButtons_Click
If shtIndex < 13 Then
.Location = New System.Drawing.Point(position, 200)
position += 44
Else
.Location = New System.Drawing.Point(position2, 245)
position2 += 44
End If
End With
Next
Me.Controls.AddRange(btnTestNumButtons)
End Sub
Private Sub newGame()
Invalidate()
LoadGameData()
lblresult.Text = ""
lblGamesPlayed.Visible = True
lblGamesWon.Visible = True
rb_played.Visible = True
rb_gameswon.Visible = True
CreateButtonArray()
hangmanWord = allPuzzles(0, LastPuzzle - 1)
CreateLabelArray(hangmanWord.Length)
End Sub
Private Sub CreateLabelArray(ByVal length As Integer)
Dim position As Integer = 30
Dim position2 As Integer = 30
ReDim lbldisplayletters(length - 1)
For i = 0 To length - 1
lbldisplayletters(i) = New System.Windows.Forms.Label()
With lbldisplayletters(i)
If hangmanWord.Substring(i, 1) = " " Then
correctcounter += 1
.Visible = False
Else
.Visible = True
End If
.Text() = ""
.TextAlign = ContentAlignment.MiddleCenter
.Size() = New Size(40, 40)
.FlatStyle() = FlatStyle.Popup
.BackColor() = System.Drawing.Color.White
If i < 13 Then
.Location = New System.Drawing.Point(position, 50)
position += 44
Else
.Location = New System.Drawing.Point(position2, 95)
position2 += 44
End If
End With
Next
Me.Controls.AddRange(lbldisplayletters)
End Sub
Private Sub frmHangman_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
newGame()
End Sub
Private Sub drawHangman()
Dim hangman As Graphics = pict_hangman.CreateGraphics()
Dim pen As New Pen(Color.Black)
Select Case hangmanstage
Case "START"
pict_hangman.Refresh()
hangman.DrawLine(pen, 50, 200, 150, 200)
hangman.DrawLine(pen, 140, 20, 140, 200)
hangman.DrawLine(pen, 80, 20, 140, 20)
hangman.DrawLine(pen, 80, 20, 80, 40)
hangman.DrawLine(pen, 120, 20, 140, 40)
hangmanstage = "DRAW HEAD"
Case "DRAW HEAD"
hangman.DrawEllipse(pen, 70, 40, 20, 20)
hangmanstage = "DRAW BODY"
Case "DRAW BODY"
hangman.DrawLine(pen, 80, 60, 80, 110)
hangmanstage = "DRAW RIGHT HAND"
Case "DRAW RIGHT HAND"
hangman.DrawLine(pen, 80, 65, 100, 85)
hangmanstage = "DRAW LEFT HAND"
Case "DRAW LEFT HAND"
hangman.DrawLine(pen, 80, 65, 60, 85)
hangmanstage = "DRAW RIGHT LEG"
Case "DRAW RIGHT LEG"
hangman.DrawLine(pen, 80, 110, 100, 130)
hangmanstage = "DRAW LEFT LEG"
Case "DRAW LEFT LEG"
hangman.DrawLine(pen, 80, 110, 60, 130)
hangmanstage = "START"
lblresult.Text = "YOU LOOSE"
rb_played.Text = CInt(rb_played.Text) + 1
disableconrols()
End Select
End Sub
Private Sub cmdNewGame_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdNewGame.Click
Dim ctl As Control
For Each ctl In Me.Controls
ctl.Enabled = True
If ctl.GetType().Name = "Label" Then
If Not ctl.Name = "lblplayed" And Not ctl.Name = "lblwon" And Not ctl.Name = "lblGamesPlayed" And Not ctl.Name = "lblGamesWon" Then
ctl.Text = ""
ctl.Visible = False
End If
End If
Next
newGame()
End Sub
Private Sub disableconrols()
Dim ctl As Control
For Each ctl In Me.Controls
ctl.Enabled = False
Next
cmdNewGame.Enabled = True
End Sub
Private Sub Button_exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_exit.Click
Me.Close()
End Sub
__________________
The GOD OF FAIL is here!
The FAIL God now officially has 429 worshippers.
Start worshipping me today and get a personal FAIL poem for free!
|