Игра "Виселица"

курсовая работа

7. Листинг программы

Private letter As String, word As String

Private Flag As Boolean, k As Integer

Private i As Integer, j As Integer

Private n As Integer, Counter As Integer

Private h As Integer

Dim words() As String

Private Sub Cmdexit_Click()

End

End Sub

Private Sub ExitMenu_Click()

End

End Sub

Private Sub Form_Load()

Shape1.Visible = False

For i = 1 To 7

Txt(i).Visible = False

Next i

cmdVvod.Enabled = False

Randomize

a = Int(Rnd * 2)

Path = App.Path & "words.txt"

Open Path For Input As #1

Do While Not EOF(1)

Line Input #1, s

n = n + 1

Loop

Close #1

ReDim words(n - 1)

n = 0

Open Path For Input As #1

Do While Not EOF(1)

Line Input #1, words(n)

n = n + 1

Loop

Close #1

End Sub

Private Sub Cmdstart_Click()

Counter = 0

Randomize

For i = 0 To 10

Lin(i).Visible = False

Next i

Shape1.Visible = False

shpBody.Visible = False

txtb.Enabled = True

cmdVvod.Enabled = False

k = Int(Rnd * n)

word = words(k)

Txt(0).Text = Left(word, 1)

Txt(0).ForeColor = vbBlack

For i = 1 To Len(word) - 1

Txt(i).ForeColor = vbWhite

Txt(i).Text = Mid(word, i + 1, 1)

Txt(i).Visible = False

Next i

Txt(0).Visible = True

End Sub

Private Sub cmdVvod_Click()

letter = txtb.Text

Flag = False

For i = 0 To Len(word) - 1

If Txt(i).Text = letter Then

Txt(i).ForeColor = vbBlack

Txt(i).Visible = True

Flag = True

End If

Next i

txtb.Text = ""

If Flag = False Then

Select Case Counter

Case Is = 0

Lin(0).Visible = True

Lin(1).Visible = True

Lin(2).Visible = True

Counter = Counter + 1

Case Is = 1

Lin(3).Visible = True

Counter = Counter + 1

Case Is = 2

Lin(4).Visible = True

Lin(5).Visible = True

Lin(8).Visible = True

Lin(9).Visible = True

Lin(10).Visible = True

Lin(6).Visible = True

Lin(7).Visible = True

shpBody.Visible = True

Shape1.Visible = True

Counter = Counter + 1

Case Is = 3

Lin(8).Visible = False

Lin(9).Visible = False

Lin(10).Visible = False

MsgBox "Вы проиграли!"

txtb.Enabled = False

cmdVvod.Enabled = False

End Select

txtb.Text = ""

End If

End Sub

Private Sub MenuHelp_Click()

HelpForm.Show

End Sub

Private Sub txtb_Change()

If txtb.Text = "" Then

cmdVvod.Enabled = False

Else cmdVvod.Enabled = True

End If

j = 0

For i = 0 To Len(word) - 1

If Txt(i).ForeColor = vbBlack Then

j = j + 1

If j = Len(word) Then

MsgBox "Вы выиграли !"

Exit For

End If

End If

Next i

End Sub

Делись добром ;)