Results 1 to 15 of 15

Thread: [VB.NET] Flappy Bird - By Jacob Roman

Threaded View

  1. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,408

    Re: [VB.NET] Flappy Bird - By Jacob Roman

    Something that I noticed in your code that's pretty basic is all your MenuItem clicks. You could shrink this:
    Code:
        Private Sub mnuMouthGap100_Click(sender As Object, e As EventArgs) Handles mnuMouthGap100.Click
            GAP_Y = 100
            mnuMouthGap100.Checked = True
            mnuMouthGap125.Checked = False
            mnuMouthGap150.Checked = False
            mnuMouthGap175.Checked = False
            mnuMouthGap200.Checked = False
            mnuMouthGap225.Checked = False
        End Sub
    
        Private Sub mnuMouthGap125_Click(sender As Object, e As EventArgs) Handles mnuMouthGap125.Click
            GAP_Y = 125
            mnuMouthGap100.Checked = False
            mnuMouthGap125.Checked = True
            mnuMouthGap150.Checked = False
            mnuMouthGap175.Checked = False
            mnuMouthGap200.Checked = False
            mnuMouthGap225.Checked = False
        End Sub
    
        Private Sub mnuMouthGap150_Click(sender As Object, e As EventArgs) Handles mnuMouthGap150.Click
            GAP_Y = 150
            mnuMouthGap100.Checked = False
            mnuMouthGap125.Checked = False
            mnuMouthGap150.Checked = True
            mnuMouthGap175.Checked = False
            mnuMouthGap200.Checked = False
            mnuMouthGap225.Checked = False
        End Sub
    
        Private Sub mnuMouthGap175_Click(sender As Object, e As EventArgs) Handles mnuMouthGap175.Click
            GAP_Y = 175
            mnuMouthGap100.Checked = False
            mnuMouthGap125.Checked = False
            mnuMouthGap150.Checked = False
            mnuMouthGap175.Checked = True
            mnuMouthGap200.Checked = False
            mnuMouthGap225.Checked = False
        End Sub
    
        Private Sub mnuMouthGap200_Click(sender As Object, e As EventArgs) Handles mnuMouthGap200.Click
            GAP_Y = 200
            mnuMouthGap100.Checked = False
            mnuMouthGap125.Checked = False
            mnuMouthGap150.Checked = False
            mnuMouthGap175.Checked = False
            mnuMouthGap200.Checked = True
            mnuMouthGap225.Checked = False
        End Sub
    
        Private Sub mnuMouthGap225_Click(sender As Object, e As EventArgs) Handles mnuMouthGap225.Click
            GAP_Y = 225
            mnuMouthGap100.Checked = False
            mnuMouthGap125.Checked = False
            mnuMouthGap150.Checked = False
            mnuMouthGap175.Checked = False
            mnuMouthGap200.Checked = False
            mnuMouthGap225.Checked = True
        End Sub
    Down to this:
    Code:
    Private Sub MouthToolStripSubMenuItem_Click(sender As Object, e As EventArgs) Handles mnuMouthGap100.Click, mnuMouthGap125.Click, mnuMouthGap150.Click, mnuMouthGap175.Click, mnuMouthGap200.Click, mnuMouthGap225.Click
    
        Dim menu_item As ToolStripMenuItem = DirectCast(sender, ToolStripMenuItem)
    
        For Each subItem As ToolStripMenuItem In MouthToolStripMenuItem.DropDownItems
            subItem.Checked = False
        Next
    
        menu_item.Checked = True
    
        GAP_Y = CInt(menu_item.Tag)
    End Sub
    Just set the tag property of each menu item to their represented GAP_Y number. So it's nothing really on performance, it's just on a matter of saving you typing. The same can be done for all of the dropdownitems that have a similar scenario.
    Last edited by dday9; Apr 1st, 2014 at 01:33 PM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width