home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectPlay / Memory / modDPlay.bas < prev    next >
Encoding:
BASIC Source File  |  2001-10-08  |  2.8 KB  |  99 lines

  1. Attribute VB_Name = "modDPlay"
  2. Option Explicit
  3. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  4. '
  5. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  6. '
  7. '  File:       modDplay.bas
  8. '
  9. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  10.  
  11. 'Here are our msgs
  12. Public Enum Const_MemoryMsgs
  13.     MSG_SETUPBOARD
  14.     MSG_SHOWPIECE
  15.     MSG_HIDEPIECES
  16.     MSG_TURNEND
  17.     MSG_CHAT
  18.     MSG_MATCHED
  19. End Enum
  20.  
  21. 'Constants
  22. Public Const NumCells = 36
  23. Public Const MaxPlayers = 4
  24. Public Const AppGuid = "{31368C80-341E-4365-BD80-66D203D367BE}"
  25.  
  26. Public dx As DirectX8
  27. Public dpp As DirectPlay8Peer
  28.  
  29. 'App vars
  30. Public gbNumPlayers As Byte
  31. Public gsUserName As String
  32. Public gbPicArray(NumCells) As Byte
  33. Public gfMatchedCells(NumCells) As Boolean
  34. Public glCurrentPlayer As Long
  35. Public gbPlayerScores(MaxPlayers) As Byte
  36. Public glPlayerIDs(MaxPlayers) As Long      ' Indexed by order of play
  37. Public glMyPlayerID As Long
  38. Public gfHost As Boolean
  39.  
  40. Public DPlayEventsForm As DPlayConnect
  41.  
  42. Public Sub InitDPlay()
  43.     Set dx = New DirectX8
  44.     Set dpp = dx.DirectPlayPeerCreate
  45. End Sub
  46.  
  47. Public Sub Cleanup()
  48.     'Terminate our session if there is one
  49.     gbNumPlayers = 0
  50.     If Not (DPlayEventsForm Is Nothing) Then
  51.         'Turn off our message handler
  52.         If Not (dpp Is Nothing) Then dpp.UnRegisterMessageHandler
  53.         'Close down our session
  54.         If Not (dpp Is Nothing) Then dpp.Close
  55.         'Lose references to peer and dx objects
  56.         Set dpp = Nothing
  57.         Set dx = Nothing
  58.         'Get rid of our message pump
  59.         DPlayEventsForm.GoUnload
  60.     End If
  61. End Sub
  62.  
  63. ' Assign pieces to cells and initialize the state. Done only by the host
  64. ' in the multiplayer game. In single-player, can be called to restart.
  65.  
  66. Public Sub SetupBoard()
  67.  
  68. Dim lCount As Integer
  69. Dim Pic As Integer
  70. Dim PicInstance As Integer
  71. Dim RandCell As Integer
  72.  
  73.     ' Empty the image index array
  74.     For lCount = 0 To NumCells - 1
  75.         gbPicArray(lCount) = 0
  76.     Next lCount
  77.     
  78.     ' Assign pictures to cells
  79.     
  80.     ' For every picture except #0, find two empty cells. The two leftover cells
  81.     ' have picture #0 by default.
  82.     ' PicArray indexes the play cells into the image cells stored on the invisible form.
  83.     
  84.     For Pic = 1 To NumCells \ 2 - 1
  85.         For PicInstance = 1 To 2
  86.             Randomize
  87.             Do
  88.                 RandCell = Fix(Rnd * NumCells)
  89.             Loop Until gbPicArray(RandCell) = 0
  90.             gbPicArray(RandCell) = Pic
  91.         Next PicInstance
  92.     Next Pic
  93.  
  94. End Sub
  95.  
  96. Public Sub SendMessage(oBuf() As Byte)
  97.     dpp.SendTo DPNID_ALL_PLAYERS_GROUP, oBuf, 0, DPNSEND_NOLOOPBACK Or DPNSEND_GUARANTEED
  98. End Sub
  99.