# VBForums CodeBank > Codebank - Game Programming >  [VB2008] Click O Thon

## DaneX

Click O Thon
The Form: 


Be sure to Disable The Start button and the CLICK!!!! button...



```

Public Class Form1

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Timer1.Interval = "170" Then
            ProgressBar1.Value -= 2
        End If
        If Timer1.Interval = "50" Then
            ProgressBar1.Value -= 2
        End If
        If Timer1.Interval = "20" Then
            ProgressBar1.Value -= 3
        End If

    End Sub

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

        Timer1.Start()
        Timer2.Start()
        Button3.Enabled = True
        Button4.Enabled = False
        Button5.Enabled = False
        Button6.Enabled = False
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ProgressBar1.Increment(1)
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Stop()
            Label1.Text = "YOU FAIL!!!"
        End If
        If ProgressBar1.Value = "5" Then
            Timer1.Enabled = False
            Button3.Enabled = False
            Label1.Text = "YOU WIN!!!"
            Timer2.Stop()
        End If
        If ProgressBar1.Value = "4" Then
            Timer1.Enabled = False
            Button3.Enabled = False
            Label1.Text = "YOU WIN!!!"
            Timer2.Stop()
        End If
        If ProgressBar1.Value = "3" Then
            Timer1.Enabled = False
            Button3.Enabled = False
            Label1.Text = "YOU WIN!!!"
            Timer2.Stop()
        End If
        If ProgressBar1.Value = "2" Then
            Timer1.Enabled = False
            Button3.Enabled = False
            Label1.Text = "YOU WIN!!!"
            Timer2.Stop()
        End If
        If ProgressBar1.Value = "1" Then
            Timer1.Enabled = False
            Button3.Enabled = False
            Label1.Text = "YOU WIN!!!"
            Timer2.Stop()
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label2.Text = "60"
        ProgressBar1.Value = 35
        Label1.Text = ""
        Timer1.Stop()
        Button3.Enabled = False
        Button4.Enabled = True
        Button5.Enabled = True
        Button6.Enabled = True
        Button1.Enabled = True
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Timer1.Interval = "170"
        Button4.Enabled = False
        Button6.Enabled = True
        Button6.Enabled = True
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Timer1.Interval = "50"
        Button4.Enabled = True
        Button5.Enabled = False
        Button6.Enabled = True
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Timer1.Interval = "20"
        Button4.Enabled = True
        Button5.Enabled = True
        Button6.Enabled = False
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Label3.Text = Label2.Text - 1
    End Sub
End Class 



```

Credits To DaneX

----------


## Micro Dude

Thanks, I edited at 

```
YOU FAIL!!!
```

----------


## DaneX

You are welcome! enjoy =P

----------


## Kanati

You should tighten up that code and get rid of unnecessary conditionals.

You will also note that I used a different conditional for the button clicks (SELECT CASE) and combined event handlers for those three buttons.  In doing so you eliminate a bit of code, and you can use the "sender" to determine which button was pressed.

This was written on the fly in the forum editor so I could conceivably have a syntax error or something in it as it stands...  but it should be solid.



```
Public Class Form1
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Timer1.Interval = 20 then
            ProgressBar1.Value -= 3
        Else
            Progressbar1.Value -= 2
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
        Timer2.Start()
        Button3.Enabled = True
        Button4.Enabled = False
        Button5.Enabled = False
        Button6.Enabled = False
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ProgressBar1.Increment(1)
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Stop()
            Label1.Text = "YOU FAIL!!!"
        ElseIf ProgressBar1.Value <= 5 Then
            Timer1.Enabled = False
            Button3.Enabled = False
            Label1.Text = "YOU WIN!!!"
            Timer2.Stop()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label2.Text = "60"
        ProgressBar1.Value = 35
        Label1.Text = ""
        Timer1.Stop()
        Button3.Enabled = False
        Button4.Enabled = True
        Button5.Enabled = True
        Button6.Enabled = True
        Button1.Enabled = True
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click, Button5.Click, Button6.Click
        Select Case sender.text
            Case "Easy"
                Timer1.Interval = "170"
                Button4.Enabled = False
                Button6.Enabled = True
                Button6.Enabled = True
            Case "Medium"
                Timer1.Interval = "50"
                Button4.Enabled = True
                Button5.Enabled = False
                Button6.Enabled = True
            Case "Harcore!!!!"
                Timer1.Interval = "20"
                Button4.Enabled = True
                Button5.Enabled = True
                Button6.Enabled = False
        End Select
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Label3.Text = Label2.Text - 1
    End Sub
End Class
```

----------

