Home > Net >  VB.net questions about custom class to receive keyboard events
VB.net questions about custom class to receive keyboard events

Time:12-02

I recently are implementing a pac-man game, hope to be able to let the players by manipulating the keyboard to move pac-man,
Then I wrote runGame method, at the same time defines the following cycle:

'judge whether game
While Not g.i sGameOver
'control ghost move
GhostController. GetMove (right opy (), CType ((Date. Now - stamp). TotalMilliseconds, Long) + DELAY)
'control players move
PacManController. GetMove (right opy (), CType ((Date. Now - stamp). TotalMilliseconds, Long) + DELAY)

'the current thread hanging
Try
Threading. Thread.sleep (DELAY)
Catch the ex As Exception
Console. WriteLine (ex. ToString)
End the Try
'updating the game
G.a dvanceGame (pacManController getMove, ghostController getMove)
Redrawn 'field on your form
Gv. DrawAll ()
Gv. Refresh ()

End While

The movement of the players I think through the events to pacManController, then updating the game, however, only contact form before class how to response to events, and because of this code is written in the form of class, so only the current cycle, form to respond to keyboard events,
In this case, is there any better solution? Would like in Java, for example, is added in the pacManController keyboard event listener, and then by adding a new thread to update players move??
Thanks for your bosses!