|
-
Mar 14th, 2001, 02:36 PM
#1
Thread Starter
New Member
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
-
Mar 14th, 2001, 07:15 PM
#2
Good Ol' Platypus
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)
-
Jun 12th, 2003, 03:08 PM
#3
New Member
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!
-
Jun 12th, 2003, 05:09 PM
#4
Good Ol' Platypus
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:
Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
Private Const VK_CONTROL = &H11
Private Const VK_SPACE = &H20
Private Const VK_NUMPAD0 = &H60
Const Player1 = VK_CONTROL 'Player 1's buzz-in key
Const Player2 = VK_SPACE 'Player 2's buzz-in key
Const Player3 = VK_NUMPAD0 'Player 3's buzz-in key
Private bStop As Boolean 'Set this to True when the question has been answered
Private Sub QuestionAnswerPeriod()
'call this when you have asked a question
bStop = False
Do While Not bStop
DoEvents
If GetAsyncKeyState(Player1) And 1 Then
... what you want to do to ask them (for player #1)
ElseIf GetAsyncKeyState(Player2) And 1 Then
... what you want to do to ask them (for player #2)
ElseIf GetAsyncKeyState(Player3) And 1 Then
... what you want to do to ask them (for player #3)
End If
Loop
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|