![]() |
![]() |
![]() |
|
|||||||||
|
![]() | |||||||||||
|
![]() |
||||||||
|
МЕНЮ
|
БОЛЬШАЯ ЛЕНИНГРАДСКАЯ БИБЛИОТЕКА - РЕФЕРАТЫ - Greating game on visual basic with multiplayer systemGreating game on visual basic with multiplayer system2 AUTOMATIC SYSTEM GREATING GAME ON VISUAL BASIC WITH MULTIPLAYER SYSTEM Dushanbe, 2009 Main Interface Source Code Public lanchoice As Long 'address Public details As String 'names Public connected As Boolean 'if connected Private Sub Form_Load () Connect. Icon = LoadResPicture ("ictac", vbResIcon) 'form icon If usermode = "host" Then join. Enabled = False Else host. Enabled = False gamename. Visible = False Label5. Visible = False End If End Sub Private Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer) 'call on form cancel or exit by control box on form If connectionmade = False Then MainBoard. hostagame. Enabled = True MainBoard. joinagame. Enabled = True Call CloseDownDPlay multiplayermode = False End If MainBoard. Enabled = True End Sub Private Sub host_Click () On Error GoTo NO_Hosting ' error handler in case creating host fails If playersname = "" Or gamename = "" Then MsgBox "You must enter a Players name and Game Name", vbOKOnly, "Tic Tac Oops" Exit Sub End If Call goplay 'starts direct play object Dim address As DirectPlayAddress 'Selects which choice was made for lan Set address = EnumConnect. GetAddress (lanchoice) 'Binds address to directplay connection Call dxplay. InitializeConnection (address) 'Starts sessiondata information Dim SessionData As DirectPlaySessionData Set SessionData = dxplay. CreateSessionData Call SessionData. SetMaxPlayers (2) Call SessionData. SetSessionName (gamename. Text) Call SessionData. SetFlags (DPSESSION_MIGRATEHOST) Call SessionData. SetGuidApplication (AppGuid) 'Starts a new session initializes connection Call dxplay. Open (SessionData, DPOPEN_CREATE) 'Create Player profile Dim PlayerName As String Dim playerhandle As String PlayerName = playersname. Text profilename = PlayerName playerhandle = "Player (Host)" MyPlayer = dxplay. CreatePlayer (PlayerName, playerhandle, 0, 0) dxHost = True gameopen. Caption = gamename. Text Call updatedisplay 'Updates game list Label8. Caption = "Waiting for other Players" Exit Sub NO_Hosting: MsgBox "Could not Host Game", vbOKOnly, "Try Again" End Sub Private Sub join_Click () On Error GoTo Oops Call goplay Dim address As DirectPlayAddress Set address = EnumConnect. GetAddress (lanchoice) Call dxplay. InitializeConnection (address) Dim details2 As Byte Dim SessionData As DirectPlaySessionData Set SessionData = dxplay. CreateSessionData 'Gets Session any open session info Set EnumSession = dxplay. GetDPEnumSessions (SessionData, 0, DPENUMSESSIONS_AVAILABLE) Set SessionData = EnumSession. GetItem (1) 'Get open session name details = SessionData. GetSessionName If details > "" And usermode = "client" Then joingame. Enabled = True End If Call updatedisplay gameopen. Caption = details Exit Sub Oops: MsgBox "Connection Failed", vbOKOnly, "Tic Tac Oops" Exit Sub End Sub Public Function goplay () Set dxplay = dx7. DirectPlayCreate ("") 'open directplay object 'gets connection types Set EnumConnect = dxplay. GetDPEnumConnections ("", DPCONNECTION_DIRECTPLAY) End Function Private Sub joingame_Click () On Error GoTo Joinfailed If playersname = "" Then MsgBox "You must enter a Players name", vbOKOnly, "Tic Tac Oops" Exit Sub End If Dim SessionData As DirectPlaySessionData Set SessionData = EnumSession. GetItem (1) 'Joins open session Call dxplay. Open (SessionData, DPOPEN_JOIN) 'creats and sends player info PlayerName = playersname. Text profilename = PlayerName playerhandle |