Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Restart Code

$
0
0
Hi, im trying to make a very simple game, the first one to make it to zero wins, only 1,2,3 are only accepted.

The problem is after the number goes down to zero and declares a winner i dont know how to make it go to start again. "Retry" in short, and im trying to make the button be pressed using enter.

Here is my code
Public Class Form1

    Dim p1, p2 As Integer

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim x As Integer = Asc(e.KeyChar)
        Select Case x
            Case 33 To 48
                e.Handled = True
            Case 52 To 255
                e.Handled = True

        End Select

    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim x As Integer = Asc(e.KeyChar)
        Select Case x
            Case 33 To 48
                e.Handled = True
            Case 52 To 255
                e.Handled = True

        End Select

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Button1.Enabled = False
        p1 = TextBox1.Text


        If p1 <= Val(Label3.Text) Then
            Label3.Text = Val(Label3.Text) - p1

        End If
        Button2.Enabled = True
        If Label3.Text = 0 Then
            TextBox1.Clear()
            Button1.Enabled = False
            MsgBox("PlAYER 1 WINS")

            'Button2.Enabled = False




        End If
        TextBox1.Clear()
        TextBox2.Focus()







    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Button2.Enabled = False
        p2 = TextBox2.Text

        If p2 <= Val(Label3.Text) Then
            Label3.Text = Val(Label3.Text) - p2

        End If
        Button1.Enabled = True

        If Label3.Text = 0 Then
            TextBox2.Clear()
            Button1.Enabled = False
            MsgBox("PlAYER 2 WINS!")

            'Button2.Enabled = False



        End If
        TextBox2.Clear()
        TextBox1.Focus()








    End Sub
End Class





Thanks in advance.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>