当用户完成游戏时,我希望能够在代码中添加一个选项,“再次播放”按钮出现,当点击游戏可以重新开始供用户玩。下面是我的代码现在的样子,我希望能够添加“重试”按钮,这样当用户完成游戏后,用户可以再次开始玩游戏。
Private Sub btnSubmit_Click(sender As Object, e As RoutedEventArgs) Handles btnSubmit.Click
Dim i As Integer
For i = 0 To 244
If txtbWords.Text = strArr(i) Then
score = score + txtbWords.Text.Length
strArr(i) = ""
End If
Next i
txtScore.Text = "Score: " & score
End Sub
Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
txtA.Visibility = Windows.UI.Xaml.Visibility.Collapsed
txtC.Visibility = Windows.UI.Xaml.Visibility.Collapsed
txtE.Visibility = Windows.UI.Xaml.Visibility.Collapsed
btnSubmit.Visibility = Windows.UI.Xaml.Visibility.Collapsed
txtbWords.Visibility = Windows.UI.Xaml.Visibility.Collapsed
End Sub
Private i As Integer = 0
Private j As Integer = 3
Public Sub Each_Tick(ByVal o As Object, ByVal sender As EventArgs)
i = i + 1
If i = 60 Then
myDispatcherTimer.Stop() 'Game ends here.
btnSubmit.Visibility = Windows.UI.Xaml.Visibility.Collapsed
End If
myTextBlock.Text = i
End Sub
Private Sub btnStart_Click(sender As Object, e As RoutedEventArgs) Handles btnStart.Click
txtA.Visibility = Windows.UI.Xaml.Visibility.Visible
txtC.Visibility = Windows.UI.Xaml.Visibility.Visible
txtE.Visibility = Windows.UI.Xaml.Visibility.Visible
txtK.Visibility = Windows.UI.Xaml.Visibility.Visible
btnSubmit.Visibility = Windows.UI.Xaml.Visibility.Visible
txtbWords.Visibility = Windows.UI.Xaml.Visibility.Visible
btnStart.Visibility = Windows.UI.Xaml.Visibility.Collapsed
myDispatcherTimer.Interval = New TimeSpan(0, 0, 0, 0, 1000)
' 100 Milliseconds
AddHandler myDispatcherTimer.Tick, AddressOf Me.Each_Tick
myDispatcherTimer.Start()
End Sub