• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Easy Question

i have a simple game in which there are numerous command buttons that change backcolors every second. what i want, is to deduct a point from the score if the player misses clicking on a button when it is a certain color.

i want the point to be deducted as soon as the button color changes.

any ideas on the best way to accomplish this?
0
EverythingVB
Asked:
EverythingVB
  • 2
1 Solution
 
navneet77Commented:
i am not sure what is the structure of the whole game but at the point where you are changing the color can you not check if it is certain color and has not been clicked than deduct point.

like

dim hasclicked as boolean

private sub vutton_onclick()
hasclick = true
end sub


private sub changecolor()

if button.backcolor = vbred then
points = points - deduct
button.backcolor = vbblue
elseif ...
...
end if
end sub
0
 
navneet77Commented:
sorry may be should be

private sub changecolor()

if button.backcolor = vbred then
  if not hasclick then
points = points - deduct
  end if
button.backcolor = vbblue
elseif ...
...
end if

  hasclick = false

end sub
0
 
spauljosephCommented:
Use this.

Private Sub cmdBtn_Click(Index as Integer)
    If cmdBtn(Index).BackColor=RGB(100,100,100) Then 'Add your color value here
        curPoints = curPoints - 1
    End If
End Sub
0
 
NaylinCommented:
First things first, if your command buttons aren't in a control array, you need them to be for this to work.

Next insert this into your declarations at the top of your form code:

     Private GotIt As Boolean
     
Then this in your timer event that changes the colors of your buttons:

     If Not GotIt Then
         points = points - NumPointsToSubtract
     Else
         GotIt = False
     End If

And for your click event for your buttons:

     Private Sub Command1_Click(Index As Integer)
     If Command1(Index).BackColor = vbRed Then
         GotIt = True
     End If
     End Sub

Should work as long as you aren't using colors that range the whole spectrum. If you are using more than the VB basic colors, it is just a matter of checking for the RGB values instead of the vbcolor.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now