home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 September / CHIPCD_9_99.iso / software / uaktualnienia / OptionPackPL / MTS4.CAB / TClient_frmMain.frm < prev    next >
Text File  |  1998-04-27  |  26KB  |  975 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMain 
  3.    AutoRedraw      =   -1  'True
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Tic-Tac-Toe client"
  6.    ClientHeight    =   5550
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   9300
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   6366.517
  14.    ScaleMode       =   0  'User
  15.    ScaleWidth      =   9423.598
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   2  'CenterScreen
  18.    Begin VB.TextBox lossesT 
  19.       Height          =   375
  20.       Left            =   5280
  21.       Locked          =   -1  'True
  22.       TabIndex        =   16
  23.       Text            =   "0"
  24.       Top             =   3000
  25.       Width           =   375
  26.    End
  27.    Begin VB.TextBox tiesT 
  28.       Height          =   375
  29.       Left            =   4680
  30.       Locked          =   -1  'True
  31.       TabIndex        =   15
  32.       Text            =   "0"
  33.       Top             =   3000
  34.       Width           =   375
  35.    End
  36.    Begin VB.TextBox winsT 
  37.       Height          =   375
  38.       Left            =   4080
  39.       Locked          =   -1  'True
  40.       TabIndex        =   12
  41.       Text            =   "0"
  42.       Top             =   3000
  43.       Width           =   375
  44.    End
  45.    Begin VB.OptionButton Hard 
  46.       Caption         =   "Hard"
  47.       Height          =   255
  48.       Left            =   4440
  49.       TabIndex        =   10
  50.       Top             =   1440
  51.       Value           =   -1  'True
  52.       Width           =   1095
  53.    End
  54.    Begin VB.OptionButton Easy 
  55.       Caption         =   "Easy"
  56.       Height          =   255
  57.       Left            =   4440
  58.       TabIndex        =   9
  59.       Top             =   1800
  60.       Width           =   855
  61.    End
  62.    Begin VB.TextBox Nombre 
  63.       Height          =   285
  64.       Left            =   4440
  65.       TabIndex        =   8
  66.       Top             =   600
  67.       Width           =   1335
  68.    End
  69.    Begin VB.Timer ServerPoll 
  70.       Enabled         =   0   'False
  71.       Interval        =   300
  72.       Left            =   3840
  73.       Top             =   0
  74.    End
  75.    Begin VB.TextBox Result 
  76.       Height          =   285
  77.       Left            =   120
  78.       Locked          =   -1  'True
  79.       TabIndex        =   7
  80.       Top             =   5160
  81.       Width           =   5895
  82.    End
  83.    Begin VB.CommandButton Exit 
  84.       Caption         =   "Exit Tic-Tac-Toe"
  85.       BeginProperty Font 
  86.          Name            =   "Arial"
  87.          Size            =   8.25
  88.          Charset         =   0
  89.          Weight          =   400
  90.          Underline       =   0   'False
  91.          Italic          =   0   'False
  92.          Strikethrough   =   0   'False
  93.       EndProperty
  94.       Height          =   375
  95.       Left            =   3960
  96.       TabIndex        =   5
  97.       Top             =   4560
  98.       Width           =   2055
  99.    End
  100.    Begin VB.TextBox Name2 
  101.       Height          =   315
  102.       Left            =   2520
  103.       Locked          =   -1  'True
  104.       TabIndex        =   4
  105.       Top             =   600
  106.       Width           =   1215
  107.    End
  108.    Begin VB.TextBox Name1 
  109.       Height          =   285
  110.       Left            =   120
  111.       Locked          =   -1  'True
  112.       TabIndex        =   3
  113.       Top             =   600
  114.       Width           =   1215
  115.    End
  116.    Begin VB.CommandButton PlayHuman 
  117.       Caption         =   "Play against a Human"
  118.       BeginProperty Font 
  119.          Name            =   "Arial"
  120.          Size            =   8.25
  121.          Charset         =   0
  122.          Weight          =   400
  123.          Underline       =   0   'False
  124.          Italic          =   0   'False
  125.          Strikethrough   =   0   'False
  126.       EndProperty
  127.       Height          =   375
  128.       Left            =   3960
  129.       TabIndex        =   1
  130.       Top             =   4080
  131.       Width           =   2055
  132.    End
  133.    Begin VB.CommandButton PlayComputer 
  134.       Caption         =   "Play against the computer"
  135.       BeginProperty Font 
  136.          Name            =   "Arial"
  137.          Size            =   8.25
  138.          Charset         =   0
  139.          Weight          =   400
  140.          Underline       =   0   'False
  141.          Italic          =   0   'False
  142.          Strikethrough   =   0   'False
  143.       EndProperty
  144.       Height          =   375
  145.       Left            =   3960
  146.       TabIndex        =   0
  147.       Top             =   3600
  148.       Width           =   2055
  149.    End
  150.    Begin VB.Image bmpSmallX 
  151.       Height          =   315
  152.       Left            =   8640
  153.       Picture         =   "frmMain.frx":0000
  154.       Top             =   2400
  155.       Visible         =   0   'False
  156.       Width           =   315
  157.    End
  158.    Begin VB.Image bmpSmallO 
  159.       Height          =   315
  160.       Left            =   8160
  161.       Picture         =   "frmMain.frx":017E
  162.       Top             =   2400
  163.       Visible         =   0   'False
  164.       Width           =   315
  165.    End
  166.    Begin VB.Image bmpNull 
  167.       Height          =   315
  168.       Left            =   8400
  169.       Picture         =   "frmMain.frx":02FC
  170.       Top             =   2880
  171.       Visible         =   0   'False
  172.       Width           =   315
  173.    End
  174.    Begin VB.Image bmpBigX 
  175.       Height          =   900
  176.       Left            =   8040
  177.       Picture         =   "frmMain.frx":047A
  178.       Top             =   1200
  179.       Visible         =   0   'False
  180.       Width           =   900
  181.    End
  182.    Begin VB.Image bmpBigO 
  183.       Height          =   900
  184.       Left            =   8040
  185.       Picture         =   "frmMain.frx":0C7C
  186.       Top             =   120
  187.       Visible         =   0   'False
  188.       Width           =   900
  189.    End
  190.    Begin VB.Image Image12 
  191.       Height          =   900
  192.       Left            =   1440
  193.       Top             =   3960
  194.       Width           =   900
  195.    End
  196.    Begin VB.Label Label4 
  197.       Caption         =   "Losses"
  198.       Height          =   255
  199.       Left            =   5280
  200.       TabIndex        =   18
  201.       Top             =   2640
  202.       Width           =   495
  203.    End
  204.    Begin VB.Label Label3 
  205.       Caption         =   "Ties"
  206.       Height          =   255
  207.       Left            =   4680
  208.       TabIndex        =   17
  209.       Top             =   2640
  210.       Width           =   375
  211.    End
  212.    Begin VB.Label Label2 
  213.       Caption         =   "Wins"
  214.       Height          =   255
  215.       Left            =   4080
  216.       TabIndex        =   14
  217.       Top             =   2640
  218.       Width           =   375
  219.    End
  220.    Begin VB.Label SessionLabel 
  221.       Caption         =   "This session:"
  222.       Height          =   255
  223.       Left            =   4440
  224.       TabIndex        =   13
  225.       Top             =   2280
  226.       Width           =   975
  227.    End
  228.    Begin VB.Label ComputerLabel 
  229.       Caption         =   "Select degree of difficulty"
  230.       Height          =   255
  231.       Left            =   4320
  232.       TabIndex        =   11
  233.       Top             =   1080
  234.       Width           =   1935
  235.    End
  236.    Begin VB.Image Image02 
  237.       Height          =   900
  238.       Left            =   240
  239.       Top             =   3960
  240.       Width           =   900
  241.    End
  242.    Begin VB.Image Image22 
  243.       Height          =   900
  244.       Left            =   2760
  245.       Top             =   3960
  246.       Width           =   900
  247.    End
  248.    Begin VB.Image Image21 
  249.       Height          =   900
  250.       Left            =   2760
  251.       Top             =   2640
  252.       Width           =   900
  253.    End
  254.    Begin VB.Image Image10 
  255.       Height          =   915
  256.       Left            =   1440
  257.       Top             =   1320
  258.       Width           =   945
  259.    End
  260.    Begin VB.Image Image20 
  261.       Height          =   900
  262.       Left            =   2760
  263.       Top             =   1320
  264.       Width           =   900
  265.    End
  266.    Begin VB.Image Image01 
  267.       Height          =   900
  268.       Left            =   240
  269.       Top             =   2640
  270.       Width           =   900
  271.    End
  272.    Begin VB.Image Image11 
  273.       Height          =   900
  274.       Left            =   1440
  275.       Top             =   2640
  276.       Width           =   900
  277.    End
  278.    Begin VB.Image Image00 
  279.       Height          =   900
  280.       Left            =   240
  281.       Top             =   1320
  282.       Width           =   900
  283.    End
  284.    Begin VB.Label NameLabel 
  285.       Caption         =   "Your name is..."
  286.       Height          =   255
  287.       Left            =   4560
  288.       TabIndex        =   6
  289.       Top             =   240
  290.       Width           =   1095
  291.    End
  292.    Begin VB.Image Player2 
  293.       Height          =   315
  294.       Left            =   3000
  295.       Top             =   120
  296.       Width           =   315
  297.    End
  298.    Begin VB.Image Player1 
  299.       Height          =   315
  300.       Left            =   600
  301.       Top             =   120
  302.       Width           =   315
  303.    End
  304.    Begin VB.Image GameScreen 
  305.       Height          =   3615
  306.       Left            =   120
  307.       Picture         =   "frmMain.frx":147E
  308.       Top             =   1320
  309.       Width           =   3615
  310.    End
  311.    Begin VB.Label Label1 
  312.       Caption         =   "Versus"
  313.       Height          =   255
  314.       Left            =   1680
  315.       TabIndex        =   2
  316.       Top             =   360
  317.       Width           =   495
  318.    End
  319. End
  320. Attribute VB_Name = "frmMain"
  321. Attribute VB_GlobalNameSpace = False
  322. Attribute VB_Creatable = False
  323. Attribute VB_PredeclaredId = True
  324. Attribute VB_Exposed = False
  325. ' Filename: tClient.vbp
  326. '
  327. ' Description:  Tic-Tac-Toe Client
  328. '
  329. ' This file is provided as part of the Microsoft Transaction Server
  330. ' Software Development Kit
  331. '
  332. ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT
  333. ' WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
  334. ' INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
  335. ' OF MERCHANTABILITY AND/OR FITNESS FOR A  PARTICULAR
  336. ' PURPOSE.
  337. '
  338. ' Copyright (C) 1997 Microsoft Corporation, All rights reserved
  339.  
  340. Option Explicit
  341.  
  342. Private viper As Boolean
  343. Private organic As Boolean
  344. Private playing As Boolean
  345. Private gameID As Long
  346. Private localX As Long
  347. Private localY As Long
  348. Private localOrder As Long
  349. Private localName As String
  350. Private remoteName As String
  351. Private easyComputer As Boolean
  352. Private wins As Long
  353. Private ties As Long
  354. Private losses As Long
  355.  
  356. Private localPic As Picture
  357. Private remotePic As Picture
  358.  
  359. Private full(3, 3) As Long
  360. Private waiting As Boolean
  361.  
  362. Private Sub Easy_Click()
  363.     easyComputer = True
  364. End Sub
  365.  
  366. Private Sub Form_Load()
  367.     Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000)
  368.     Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000)
  369.     Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 6500)
  370.     Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6500)
  371.     
  372.     ' Make sure the Tic-Tac-Toe components are properly installed in MTS
  373.     On Error GoTo objError
  374.     Dim computer As Object
  375.     Dim human As Object
  376.     Set computer = CreateObject("tServer.Computer")
  377.     Set human = CreateObject("tServer.Human")
  378.     On Error GoTo 0
  379.     
  380.     ' Init
  381.     localName = "tClient User"
  382.     remoteName = "No one"
  383.     viper = False
  384.     organic = False
  385.     playing = False
  386.     gameID = -1
  387.     waiting = False
  388.     ServerPoll.Enabled = False
  389.     easyComputer = False
  390.     wins = 0
  391.     ties = 0
  392.     losses = 0
  393.     
  394.     Nombre = localName
  395.     Name1 = "No one"
  396.     Name2 = remoteName
  397.     Player1.Picture = bmpNull
  398.     Player2.Picture = bmpNull
  399.     Result = "Press a button and start a game"
  400.     
  401.     Exit Sub
  402.     
  403. objError:
  404.     MsgBox "Error " & Err.Number & ": Make sure the Tic-Tac-Toe package has been correctly installed in MTS."
  405.     End
  406. End Sub
  407.  
  408.  
  409. Private Sub Form_Unload(Cancel As Integer)
  410.     Dim i As Integer
  411.  
  412.     'Close all sub forms
  413.     For i = Forms.Count - 1 To 1 Step -1
  414.         Unload Forms(i)
  415.     Next
  416.     If Me.WindowState <> vbMinimized Then
  417.         SaveSetting App.Title, "Settings", "MainLeft", Me.Left
  418.         SaveSetting App.Title, "Settings", "MainTop", Me.Top
  419.         SaveSetting App.Title, "Settings", "MainWidth", Me.Width
  420.         SaveSetting App.Title, "Settings", "MainHeight", Me.Height
  421.     End If
  422. End Sub
  423.  
  424. Private Sub Hard_Click()
  425.     easyComputer = False
  426. End Sub
  427.  
  428. Private Sub Image00_Click()
  429.     
  430.     If playing And full(0, 0) = 0 Then
  431.         If localOrder = 1 Then
  432.             Image00.Picture = bmpBigX
  433.         Else
  434.             Image00.Picture = bmpBigO
  435.         End If
  436.     
  437.         MovePiece 0, 0
  438.     End If
  439.     
  440. End Sub
  441.  
  442. Private Sub Image01_Click()
  443.     
  444.     If playing And full(0, 1) = 0 Then
  445.         If localOrder = 1 Then
  446.             Image01.Picture = bmpBigX
  447.         Else
  448.             Image01.Picture = bmpBigO
  449.         End If
  450.     
  451.         MovePiece 0, 1
  452.     End If
  453.     
  454. End Sub
  455.  
  456. Private Sub Image02_Click()
  457.  
  458.     If playing And full(0, 2) = 0 Then
  459.         If localOrder = 1 Then
  460.             Image02.Picture = bmpBigX
  461.         Else
  462.             Image02.Picture = bmpBigO
  463.         End If
  464.     
  465.         MovePiece 0, 2
  466.     End If
  467.     
  468. End Sub
  469.  
  470. Private Sub Image10_Click()
  471.     
  472.     If playing And full(1, 0) = 0 Then
  473.         If localOrder = 1 Then
  474.             Image10.Picture = bmpBigX
  475.         Else
  476.             Image10.Picture = bmpBigO
  477.         End If
  478.     
  479.         MovePiece 1, 0
  480.     End If
  481.     
  482. End Sub
  483.  
  484. Private Sub Image11_Click()
  485.  
  486.     If playing And full(1, 1) = 0 Then
  487.         If (localOrder = 1) Then
  488.             Image11.Picture = bmpBigX
  489.         Else
  490.             Image11.Picture = bmpBigO
  491.         End If
  492.     
  493.         MovePiece 1, 1
  494.     End If
  495.     
  496. End Sub
  497.  
  498. Private Sub Image12_Click()
  499.     
  500.     If playing And full(1, 2) = 0 Then
  501.         If localOrder = 1 Then
  502.             Image12.Picture = bmpBigX
  503.         Else
  504.             Image12.Picture = bmpBigO
  505.         End If
  506.     
  507.         MovePiece 1, 2
  508.     End If
  509.     
  510. End Sub
  511.  
  512. Private Sub Image20_Click()
  513.     
  514.     If playing And full(2, 0) = 0 Then
  515.         If localOrder = 1 Then
  516.             Image20.Picture = bmpBigX
  517.         Else
  518.             Image20.Picture = bmpBigO
  519.         End If
  520.     
  521.         MovePiece 2, 0
  522.     End If
  523.     
  524. End Sub
  525.  
  526. Private Sub Image21_Click()
  527.     
  528.     If playing And full(2, 1) = 0 Then
  529.         If localOrder = 1 Then
  530.             Image21.Picture = bmpBigX
  531.         Else
  532.             Image21.Picture = bmpBigO
  533.         End If
  534.     
  535.         MovePiece 2, 1
  536.     End If
  537.     
  538. End Sub
  539.  
  540. Private Sub Image22_Click()
  541.     
  542.     If playing And full(2, 2) = 0 Then
  543.         If localOrder = 1 Then
  544.             Image22.Picture = bmpBigX
  545.         Else
  546.             Image22.Picture = bmpBigO
  547.         End If
  548.     
  549.         MovePiece 2, 2
  550.     End If
  551.     
  552. End Sub
  553.  
  554. Private Sub Nombre_Change()
  555.     localName = Nombre
  556. End Sub
  557.  
  558.  
  559. Private Sub PlayHuman_Click()
  560.       
  561.     ' Present hourglass pointer
  562.     Me.MousePointer = vbHourglass
  563.     
  564.     ' Clean up screen
  565.     ClearScreen
  566.     InitArray
  567.     
  568.     ' Create server human object
  569.     Dim human As Object
  570.     Set human = CreateObject("tServer.Human")
  571.     If human Is Nothing Then
  572.         MsgBox "Create object " + "tServer.Human" + " failed."
  573.         Exit Sub
  574.     End If
  575.     
  576.     ' Notify server of new game
  577.     Dim order As Variant
  578.     Dim player2Name As Variant
  579.     Dim gameNumber As Variant
  580.     human.EnterNewGame localName, gameNumber, player2Name, order
  581.     remoteName = player2Name
  582.     gameID = gameNumber
  583.     
  584.     ' Set up screen
  585.     Name1 = localName
  586.     Name2 = remoteName
  587.     PlayComputer.Enabled = False
  588.     PlayHuman.Enabled = False
  589.     Nombre.Locked = True
  590.     Easy.Enabled = False
  591.     Hard.Enabled = False
  592.     
  593.     ' Set up local variables
  594.     viper = False
  595.     organic = True
  596.     playing = False
  597.     ServerPoll.Enabled = True
  598.     
  599.     ' Set up order
  600.     localOrder = order
  601.     If order = 1 Then
  602.         Player1.Picture = bmpSmallX
  603.         Player2.Picture = bmpSmallO
  604.         Set localPic = bmpBigX
  605.         Set remotePic = bmpBigO
  606.         Result = "You are now in game " & gameID & ", we are waiting for another 'human' to join the game."
  607.     Else
  608.         Player1.Picture = bmpSmallO
  609.         Player2.Picture = bmpSmallX
  610.         Set localPic = bmpBigO
  611.         Set remotePic = bmpBigX
  612.         Result = "Game " & gameID & " against '" & remoteName & "' has begun.  Waiting for '" & remoteName & "' to move."
  613.         waiting = True
  614.     End If
  615.     
  616.     ' Clean up
  617.     Set human = Nothing
  618.     
  619.     ' Return control
  620.     Me.MousePointer = vbArrow
  621.     
  622. End Sub
  623.  
  624. Private Sub PlayComputer_Click()
  625.  
  626.     ' Present hourglass pointer
  627.     Me.MousePointer = vbHourglass
  628.     
  629.     ' Clean up screen
  630.     InitArray
  631.     ClearScreen
  632.     
  633.     ' Create server computer object
  634.     Dim computer As Object
  635.     Set computer = CreateObject("tServer.Computer")
  636.     If computer Is Nothing Then
  637.         MsgBox "Create object " + "tServer.Computer" + " failed."
  638.         Exit Sub
  639.     End If
  640.     
  641.     ' Notify server of new game
  642.     Dim lGameID As Variant
  643.     Dim order As Variant
  644.     Dim foeX As Variant
  645.     Dim foeY As Variant
  646.     computer.AddNewGame easyComputer, lGameID, order, foeX, foeY
  647.     gameID = lGameID
  648.  
  649.     ' Set up screen
  650.     If easyComputer = True Then
  651.         remoteName = "I am, I think"
  652.     Else
  653.         remoteName = "I think I am"
  654.     End If
  655.     Name1 = localName
  656.     Name2 = remoteName
  657.     PlayComputer.Enabled = False
  658.     PlayHuman.Enabled = False
  659.     Nombre.Locked = True
  660.     Easy.Enabled = False
  661.     Hard.Enabled = False
  662.     
  663.     ' Set up local variables
  664.     viper = True
  665.     organic = False
  666.     playing = True
  667.     
  668.     ' Set up order
  669.     localOrder = order
  670.     If order = 1 Then
  671.         Player1.Picture = bmpSmallX
  672.         Player2.Picture = bmpSmallO
  673.         Set localPic = bmpBigX
  674.         Set remotePic = bmpBigO
  675.  
  676.     Else
  677.         Player1.Picture = bmpSmallO
  678.         Player2.Picture = bmpSmallX
  679.         Set localPic = bmpBigO
  680.         Set remotePic = bmpBigX
  681.        
  682.         ' Process opponent's first move
  683.         Display remotePic, foeX, foeY
  684.         full(foeX, foeY) = 1
  685.         
  686.     End If
  687.     
  688.     ' Clean up
  689.     Set computer = Nothing
  690.     
  691.     ' Return control
  692.     Result = "Game " & gameID & " against '" & remoteName & "' has begun.  It is now your turn."
  693.     Me.MousePointer = vbArrow
  694.     
  695. End Sub
  696.  
  697. Private Sub Exit_Click()
  698.     ' Notify opponent of exit
  699.     End
  700. End Sub
  701.  
  702. Private Sub MovePiece(X As Long, Y As Long)
  703.  
  704.     Dim win As Variant
  705.     If viper Then
  706.         
  707.         ' Create server computer object
  708.         Dim computer As Object
  709.         Set computer = CreateObject("tServer.Computer")
  710.         If computer Is Nothing Then
  711.             MsgBox "Create object " + "tServer.Computer" + " failed."
  712.             Exit Sub
  713.         End If
  714.     
  715.         ' Submit move
  716.         Dim foeX As Variant
  717.         Dim foeY As Variant
  718.         computer.NewMove gameID, easyComputer, X, Y, foeX, foeY, win
  719.          
  720.         ' Win protocol
  721.         ' ============
  722.         ' 0  -> moves did not end game
  723.         ' 1  -> player won
  724.         ' -1 -> computer won
  725.         ' 2  -> player's move tied the game
  726.         ' -2 -> computer's move tied the game
  727.     
  728.         ' Display local move
  729.         Display localPic, X, Y
  730.         full(X, Y) = 1
  731.         
  732.         ' Check for win or loss
  733.         If Abs(win) = 1 Then
  734.             If win = 1 Then
  735.                 wins = wins + 1
  736.                 winsT = wins
  737.                 Result = "Congratulations!  You won your game against '" & remoteName & "'."
  738.                 Cleanup
  739.                 Exit Sub
  740.             Else
  741.                 Display remotePic, foeX, foeY
  742.                 losses = losses + 1
  743.                 lossesT = losses
  744.                 Result = "Too bad, '" & remoteName & "' won.  Better luck next time!"
  745.                 Cleanup
  746.                 Exit Sub
  747.             End If
  748.         Else
  749.             If Abs(win) = 2 Then
  750.                 If win = 2 Then
  751.                     Display remotePic, foeX, foeY
  752.                 End If
  753.                 ties = ties + 1
  754.                 tiesT = ties
  755.                 Result = "You tied '" & remoteName & ".' " & " Keep trying!"
  756.                 Cleanup
  757.                 Exit Sub
  758.             Else
  759.                 ' Display opponent's move
  760.                 Display remotePic, foeX, foeY
  761.                 full(foeX, foeY) = 1
  762.             End If
  763.         End If
  764.         
  765.         ' Clean up
  766.         Set computer = Nothing
  767.     
  768.         Result = "It is now your turn."
  769.  
  770.     Else
  771.     
  772.         ' Shut down server polling
  773.         ServerPoll.Enabled = False
  774.         
  775.         ' Create server human object
  776.         Dim human As Object
  777.         Set human = CreateObject("tServer.Human")
  778.         If human Is Nothing Then
  779.             MsgBox "Create object " + "tServer.Human" + " failed."
  780.             Exit Sub
  781.         End If
  782.         
  783.         ' Submit move
  784.         human.NewMove gameID, localOrder, X, Y, win
  785.         
  786.         ' Win protocol
  787.         ' ============
  788.         ' 0  -> move did not end game
  789.         ' 1  -> player won
  790.         ' -1 -> remote player won (won't occur in this function)
  791.         ' 2  -> player's move tied the game
  792.         ' -2 -> remote player's move tied the game (won't occur in this function)
  793.         
  794.         ' Display local move
  795.         Display localPic, X, Y
  796.         full(X, Y) = 1
  797.         
  798.         ' Check for win or loss
  799.         If win = 1 Then
  800.             wins = wins + 1
  801.             winsT = wins
  802.             Result = "Congratulations!  You won your game against '" & remoteName & "'."
  803.             Cleanup
  804.             Exit Sub
  805.         Else
  806.             If win = 2 Then
  807.                 ties = ties + 1
  808.                 tiesT = ties
  809.                 Result = "You tied '" & remoteName & ".' " & " Keep trying!"
  810.                 Cleanup
  811.                 Exit Sub
  812.             Else
  813.                 ' Reenable server polling
  814.                 ServerPoll.Enabled = True
  815.             End If
  816.         End If
  817.  
  818.         ' We're waiting for a move or we finished the game
  819.         playing = False
  820.         
  821.         ' Clean up
  822.         Set human = Nothing
  823.         
  824.         Result = "Waiting for '" & remoteName & "'s next move."
  825.     End If
  826.  
  827. End Sub
  828.  
  829. Private Sub Display(pic As Picture, X As Variant, Y As Variant)
  830.  
  831.     Dim hash As Long
  832.     hash = X * 10 + Y
  833.     
  834.     Select Case hash
  835.     
  836.         Case 0
  837.             Image00.Picture = pic
  838.         Case 1
  839.             Image01.Picture = pic
  840.         Case 2
  841.             Image02.Picture = pic
  842.         Case 10
  843.             Image10.Picture = pic
  844.         Case 11
  845.             Image11.Picture = pic
  846.         Case 12
  847.             Image12.Picture = pic
  848.         Case 20
  849.             Image20.Picture = pic
  850.         Case 21
  851.             Image21.Picture = pic
  852.         Case 22
  853.             Image22.Picture = pic
  854.         Case Else
  855.             MsgBox ("Invalid Display Parameter")
  856.             
  857.     End Select
  858.     
  859. End Sub
  860.  
  861. Private Sub Cleanup()
  862.  
  863.     ' Reset variables
  864.     playing = False
  865.     viper = False
  866.     organic = False
  867.     PlayHuman.Enabled = True
  868.     PlayComputer.Enabled = True
  869.     Nombre.Locked = False
  870.     Easy.Enabled = True
  871.     Hard.Enabled = True
  872.  
  873. End Sub
  874.  
  875. Private Sub InitArray()
  876.     
  877.     Dim i, j As Long
  878.     For i = 0 To 2
  879.         For j = 0 To 2
  880.             full(i, j) = 0
  881.         Next
  882.     Next
  883.  
  884. End Sub
  885.  
  886.  
  887. Private Sub ServerPoll_Timer()
  888.  
  889.     If organic And Not playing Then
  890.  
  891.         ' Create server human object
  892.         Dim human As Object
  893.         Set human = CreateObject("tServer.Human")
  894.         If human Is Nothing Then
  895.             MsgBox "Create object " + "tServer.Human" + " failed."
  896.             Exit Sub
  897.         End If
  898.     
  899.         ' Poll server
  900.         Dim name As Variant
  901.         Dim foeX As Variant
  902.         Dim foeY As Variant
  903.         Dim win As Variant
  904.         Dim update As Variant
  905.         human.GetNewMove gameID, localOrder, name, foeX, foeY, win, update
  906.         
  907.         ' Win protocol
  908.         ' ============
  909.         ' 0  -> move did not end game
  910.         ' 1  -> player won (won't occur in this function)
  911.         ' -1 -> remote player won
  912.         ' 2  -> player's move tied the game (won't occur in this function)
  913.         ' -2 -> remote player's move tied the game
  914.     
  915.         ' Routine move
  916.         If update = 1 Then
  917.         
  918.             ' Stop polling
  919.             ServerPoll.Enabled = False
  920.             
  921.             ' Display opponent's move
  922.             Display remotePic, foeX, foeY
  923.             full(foeX, foeY) = 2
  924.             
  925.             ' Check for win or loss
  926.             If win = -1 Then
  927.                 losses = losses + 1
  928.                 lossesT = losses
  929.                 Result = "Too bad, '" & remoteName & "' won.  Better luck next time!"
  930.                 Cleanup
  931.                 Exit Sub
  932.             Else
  933.                 If win = -2 Then
  934.                     ties = ties + 1
  935.                     tiesT = ties + 1
  936.                     Result = "You tied '" & remoteName & ".' " & " Keep trying!"
  937.                     Cleanup
  938.                     Exit Sub
  939.                 Else
  940.                     Result = "'" & remoteName & "' has moved.  It is now your turn."
  941.                     playing = True
  942.                 End If
  943.             End If
  944.         Else
  945.             ' Player just joined
  946.             If update = 2 Then
  947.                 remoteName = name
  948.                 Name2 = remoteName
  949.                 Result = "'" & remoteName & "' has joined your game.  It is now your turn."
  950.                 playing = True
  951.             End If
  952.         End If
  953.         
  954.         ' Clean up
  955.         Set human = Nothing
  956.     
  957.     End If
  958.  
  959. End Sub
  960.  
  961. Private Sub ClearScreen()
  962.  
  963.     Image00.Picture = LoadPicture
  964.     Image10.Picture = LoadPicture
  965.     Image20.Picture = LoadPicture
  966.     Image01.Picture = LoadPicture
  967.     Image11.Picture = LoadPicture
  968.     Image21.Picture = LoadPicture
  969.     Image02.Picture = LoadPicture
  970.     Image12.Picture = LoadPicture
  971.     Image22.Picture = LoadPicture
  972.     
  973. End Sub
  974.  
  975.