Results 1 to 4 of 4

Thread: Buzzing in!!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    3
    I am making a Jeopardy game for my VB class and was needing some basic code. I need to allow for multiple players to be able to buzz in to answer the question. I figure it could be by pressing one of three keys. Any suggestion?

    Bob

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Okay... I will refer to these functions in my code:

    PlaySnd - a function that plays a sound
    HndBuzz - the function that handles the buzz (what happens when a player buzzes)

    Okey! Lets see the code, it's commented so you can learn from it:

    Code:
    Const Player1=vbKeyA 'Player 1's buzz-in key
    Const Player2=vbKeyB 'Player 2's buzz-in key
    Const Player3=vbKeyC 'Player 3's buzz-in key
    
    Dim PlayerBuzz as Long
    
    Private Sub Form_KeyDown(vb declarations, just here to tell you which sub it's in)
       PlayerBuzz=keycode 'puts the keystoke into the variable so we can read it in another sub
    
    End Sub
    
    Sub SeeIfBuzz() 'user-sub: call it when you want to check if there's a buzz-in.
    
       If PlayerBuzz <> 0 Then
          If PlayerBuzz = Player1 Then
             HndBuzz 1 'call the handling funct. for buzzing for player 1
          ElseIf PlayerBuzz = Player2 Then
             HndBuzz 2 'call the funct. for p 2
          ElseIf PlayerBuzz = Player3 Then
             HndBuzz 3 'once again, call funct for p 3
       End If
    
    End Sub
    
    (here's an example of how to use this code:)
    
    Private Sub Timer1_Timer()
       SeeIfBuzz
       '... other game code here...
    End Sub
    I can post more if you want, this is just to handle the buzz. I made it easy to change key configs, you just change the keys of player1, player2, and player3 consts accordingly.

    Just some humor here, ya know what would be funny? Setting the keys to CTRL, ALT and DELETE.

    -just a bit of my humor, DONT do that.

    I'm only an email away - Sastraxi
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    New Member
    Join Date
    Jun 2003
    Posts
    4
    knock, knock,... i just found this thread and im having same difficulties, can you please elaborate more so it would be easy for me to understand this code, thanks soo much!

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Wow... what an old thread. You're lucky I'm still around

    Anyway, I wouldn't recommend this approach anymore; use the GetAsyncKeyState API instead. Here's some updated code
    VB Code:
    1. Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
    2.  
    3. Private Const VK_CONTROL = &H11
    4. Private Const VK_SPACE = &H20
    5. Private Const VK_NUMPAD0 = &H60
    6.  
    7. Const Player1 = VK_CONTROL 'Player 1's buzz-in key
    8. Const Player2 = VK_SPACE 'Player 2's buzz-in key
    9. Const Player3 = VK_NUMPAD0 'Player 3's buzz-in key
    10.  
    11. Private bStop As Boolean 'Set this to True when the question has been answered
    12.  
    13. Private Sub QuestionAnswerPeriod()
    14. 'call this when you have asked a question
    15.  
    16.     bStop = False
    17.     Do While Not bStop
    18.         DoEvents
    19.         If GetAsyncKeyState(Player1) And 1 Then
    20.             ... what you want to do to ask them (for player #1)
    21.         ElseIf GetAsyncKeyState(Player2) And 1 Then
    22.             ... what you want to do to ask them (for player #2)
    23.         ElseIf GetAsyncKeyState(Player3) And 1 Then
    24.             ... what you want to do to ask them (for player #3)
    25.         End If
    26.     Loop
    27.  
    28. End Sub
    Hope it helps...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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