home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / adx7mu1a / lobby.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-10-07  |  6.7 KB  |  208 lines

  1. VERSION 5.00
  2. Begin VB.Form Lobby 
  3.    Caption         =   "Tic Tac Lobby"
  4.    ClientHeight    =   3195
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4680
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3195
  10.    ScaleWidth      =   4680
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.TextBox GameName 
  13.       Height          =   375
  14.       Left            =   480
  15.       TabIndex        =   3
  16.       Text            =   "Text1"
  17.       Top             =   2040
  18.       Width           =   2415
  19.    End
  20.    Begin VB.CommandButton startgame 
  21.       Caption         =   "Start Game"
  22.       Height          =   495
  23.       Left            =   3360
  24.       TabIndex        =   2
  25.       Top             =   1680
  26.       Width           =   1095
  27.    End
  28.    Begin VB.CommandButton join 
  29.       Caption         =   "Join"
  30.       Height          =   495
  31.       Left            =   3360
  32.       TabIndex        =   1
  33.       Top             =   600
  34.       Width           =   1095
  35.    End
  36.    Begin VB.ListBox playerlist 
  37.       Height          =   1230
  38.       Left            =   360
  39.       TabIndex        =   0
  40.       Top             =   720
  41.       Width           =   2655
  42.    End
  43. Attribute VB_Name = "Lobby"
  44. Attribute VB_GlobalNameSpace = False
  45. Attribute VB_Creatable = False
  46. Attribute VB_PredeclaredId = True
  47. Attribute VB_Exposed = False
  48. Option Explicit
  49. Private Sub cmdCancel_Click()
  50.   Hide
  51.  ' Unload frmMultiplayer  ' Force reset of DPlay
  52.   'frmMainMenu.Show
  53. End Sub
  54. Private Sub cmdRefresh_Click()
  55.     Screen.MousePointer = vbHourglass
  56.     UpdateSessionList
  57.     Screen.MousePointer = vbNormal
  58. End Sub
  59. Private Sub Form_Unload(Cancel As Integer)
  60.   cmdCancel_Click
  61. End Sub
  62. Private Sub cmdCreate_Click()
  63.   Hide
  64.  ' frmCreateGame.Show
  65.     ' Put focus on name
  66.   'frmCreateGame.txtGameName.SetFocus
  67. End Sub
  68. ' Join game
  69. Private Sub cmdJoin_Click()
  70.   Dim SessionData As DirectPlaySessionData
  71.   ' Join selected session
  72.   'Set SessionData = gObjDPEnumSessions.GetItem(lstSessions.ListIndex + 1)
  73.   On Error GoTo NOSESSION
  74.  ' Call gObjDPlay.Open(SessionData, DPOPEN_JOIN)
  75.   On Error GoTo 0
  76.   ' Create player
  77.   Dim PlayerHandle As String
  78.   Dim PlayerName As String
  79.   'PlayerName = frmMultiplayer.txtYourName.Text
  80.   PlayerHandle = "Player"    ' We don't use this
  81.   ' Create the player
  82.   On Error GoTo FAILEDCREATE
  83.   'gMyPlayerID = gObjDPlay.CreatePlayer(PlayerName, PlayerHandle, 0, 0)
  84.   On Error GoTo 0
  85.   ' Only host can start game, so disable Start button
  86.   'frmWaiting.cmdStart.Enabled = False
  87.   ' Hide this and show status window
  88.   Hide
  89.   'frmWaiting.Show
  90.   'frmWaiting.UpdateWaiting  ' show the player list
  91.   Exit Sub
  92. ' Error handlers
  93. NOSESSION:
  94.   MsgBox ("Failed to join game.")
  95.   UpdateSessionList
  96.   Exit Sub
  97. FAILEDCREATE:
  98.   MsgBox ("Failed to create player.")
  99.   Exit Sub
  100. End Sub
  101. ' Update session listbox.
  102. Public Function UpdateSessionList() As Boolean
  103.   Dim SessionCount As Integer, x As Integer
  104.   Dim SessionData As DirectPlaySessionData
  105.   Dim Details As String
  106.   ' Delete the old list
  107.   playerlist.Clear
  108.   Set SessionData = dxplay.CreateSessionData
  109.   ' Enumerate the sessions in synchronous mode.
  110.   Call SessionData.SetGuidApplication(AppGuid)
  111.   Call SessionData.SetSessionPassword("")
  112.   If usermode = "host" Then
  113.   Set SessionData = dxplay.CreateSessionData
  114. ' Finish describing the session
  115.   Call SessionData.SetSessionName(GameName.Text)
  116.   Call SessionData.SetGuidApplication(AppGuid)
  117.   Call SessionData.SetFlags(DPSESSION_MIGRATEHOST)
  118.   ' Create (and join) the session.
  119.   ' Failure can result from the user cancelling out of the service provider dialog.
  120.   ' In the case of the modem, this is the "answer" dialog.
  121.   Call dxplay.Open(SessionData, DPOPEN_CREATE)
  122.   ' Describe the host player
  123.   Dim PlayerHandle As String
  124.   Dim PlayerName As String
  125.   PlayerName = connectfrm.PlayersName.Text
  126.   PlayerHandle = "Player 1 (Host)"
  127.   ' Create the host player
  128.   MyPlayer = dxplay.CreatePlayer(PlayerName, PlayerHandle, 0, 0)
  129.   On Error GoTo 0
  130.   dxHost = True
  131.   End If
  132.   On Error GoTo USERCANCEL
  133.   Set EnumSessions = dxplay.GetDPEnumSessions(SessionData, 0, _
  134.           DPENUMSESSIONS_AVAILABLE)
  135.   On Error GoTo 0
  136.   ' List info for enumerated sessions: name, players, max. players
  137.   On Error GoTo ENUM_ERROR
  138.   SessionCount = EnumSessions.GetCount
  139.   For x = 1 To SessionCount
  140.     Set SessionData = EnumSessions.GetItem(x)
  141.     Details = SessionData.GetSessionName & " (" & SessionData.GetCurrentPlayers _
  142.             & "/" & SessionData.GetMaxPlayers & ")"
  143.     playerlist.AddItem (Details)
  144.   Next x
  145.   ' Update Join button
  146.   If SessionCount = 0 Then
  147.    join.Enabled = False
  148.   Else
  149.     join.Enabled = True
  150.   End If
  151.   ' Initialize selection
  152.   If playerlist.ListCount > 0 Then playerlist.ListIndex = 0
  153.   UpdateSessionList = True
  154.   Exit Function
  155.   ' Error handlers
  156.   ' User cancelled out of service provider dialog, e.g. for modem connection.
  157.   ' We can't enumerate sessions but the user can still host a game.
  158. USERCANCEL:
  159.   UpdateSessionList = False
  160.   join.Enabled = False
  161.   Exit Function
  162. ENUM_ERROR:
  163.   UpdateSessionList = False
  164.   MsgBox ("Error in enumeration functions.")
  165.   Exit Function
  166. End Function
  167. Private Sub startgame_Click()
  168.  Dim ConnectionMade As Boolean
  169. Dim dxAddress As DirectPlayAddress
  170.  Dim SessionData As DirectPlaySessionData
  171. Set SessionData = dxplay.CreateSessionData
  172. ' Finish describing the session
  173.   Call SessionData.SetSessionName(GameName.Text)
  174.   Call SessionData.SetGuidApplication(AppGuid)
  175.   Call SessionData.SetFlags(DPSESSION_MIGRATEHOST)
  176.   ' Create (and join) the session.
  177.   Dim cindex As Long
  178.   ' Failure can result from the user cancelling out of the service provider dialog.
  179.   ' In the case of the modem, this is the "answer" dialog.
  180.   cindex = connectfrm.connectiontype.ListIndex + 1
  181.   Set dxAddress = EnumConnections.GetAddress(cindex)
  182.   Call dxplay.InitializeConnection(dxAddress)
  183.   ConnectionMade = Lobby.UpdateSessionList
  184.   If ConnectionMade Then
  185.     Hide
  186.     Lobby.Show
  187.   Else
  188.     InitDPlay
  189.   End If
  190.   Exit Sub
  191.   ' Error handlers
  192. INITIALIZEFAILED:
  193.   If Err.Number <> DPERR_ALREADYINITIALIZED Then
  194.     MsgBox ("Failed to initialize connection.")
  195.     Exit Sub
  196.   End If
  197.   'Call dxplay.Open(SessionData, DPOPEN_CREATE)
  198.   ' Describe the host player
  199.   Dim PlayerHandle As String
  200.   Dim PlayerName As String
  201.   PlayerName = connectfrm.PlayersName.Text
  202.   PlayerHandle = "Player 1 (Host)"
  203.   ' Create the host player
  204.   MyPlayer = dxplay.CreatePlayer(PlayerName, PlayerHandle, 0, 0)
  205.   On Error GoTo 0
  206.   dxHost = True
  207. End Sub
  208.