VB.Net Hangman游戏多轮

时间:2015-06-03 15:39:25

标签: vb.net

我需要一些帮助。

我目前正在VB.Net中创建一个Hangman游戏。

我在从6个单词的文本文件中加载随机单词的阶段,您可以单击按钮进行猜测。如果您认为字母错误,框架会显示等,如果它们正确,则字母会通过标签显示在单词中。

下一点,我坚持认为,需要多轮。我需要在那里进行3次这种刽子手游戏,所以,如果你猜对了这个词,你得到10分,如果你失败,你得到0,然后游戏重置你的积分,你可以再次玩在第2回合中,然后在第3回合中,在第3轮结束后,加载高分形式。

2 个答案:

答案 0 :(得分:0)

您可以创建一个变量来保存模块中的当前轮次,在每轮开始时增加它,并在轮次结束时检查当前轮次并制作if if逻辑。

Dim myRound as Integer = 0

在构造函数的PlayForm中。

myRound += 1

一轮完成后。

if myRound >= 3 Then
    'open the score page
Else
    'start the next round
End if

答案 1 :(得分:0)

'In General Declarations:
Dim ButtonList As New List(Of Button)  'or Of Control if you have other types of controls
Dim HgmList As New List(Of PowerPacks.Shape)
Dim AnswerList As New List(Of Label)    

'In PlayForm_Load:
With ButtonList
    .Clear()
    .Add(Me.BtnA)
    .Add(Me.BtnB)
    .Add(Me.BtnC)
    'You get the idea
    'Add all your buttons you want to re-enable to the list
End With
With HgmList
    .Clear()
    .Add(Me.SideFrameLine)
    .Add(Me.TopFrameLine)
    .Add(Me.CornerFrameLine)
    'etc.
End With
With AnswerList
    .Add(Me.FirstLetterLbl)
    'etc. Just like the other two.
End With

'At the end of your `If Correct = False Then` Block:
Else  'Check for win after each correct guess
    Dim Winner As Boolean = True
    Dim CheckLetter As Label
    For Each CheckLetter in AnswerList
        If Not CheckLetter.Visible Then
            Winner = False
            Exit For
        End If
    Next
    If Winner Then
        NextRound(10)
    End If
End If

'Somewhere inside your form code:
Private Sub NextRound(RoundScore As Integer)
    UserScore += RoundScore
    If TurnNumber = 3 Then 'Game Over
        MsgBox("Game Over" & vbNewLine & "Score: " & UserScore)
    Else 'This is the part you asked about: resetting the form
        TurnNumber += 1
        PlayForm_Load(Nothing, Nothing)
        Dim ResetControl As Control
        Dim ResetShape As PowerPacks.Shape
        For Each ResetControl In ButtonList
            ResetControl.Enabled = True
        Next
        For Each ResetShape In HgmList
            ResetControl.Visible = False
        Next
    End If
End Sub

我只将.Clear()添加到列表构建器中,因为您已经有了代码来在PlayForm_Load中获取新单词。如果你移动它(比如一个名为NewWord的新Sub),你不需要.Clear,你可以调用你的新子而不是PlayForm_Load。