home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / mts4.cab / TClient_frmMain.frm (.txt) < prev    next >
Visual Basic Form  |  1997-11-14  |  26KB  |  862 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. Attribute VB_Name = "frmMain"
  320. Attribute VB_GlobalNameSpace = False
  321. Attribute VB_Creatable = False
  322. Attribute VB_PredeclaredId = True
  323. Attribute VB_Exposed = False
  324. ' Filename: tClient.vbp
  325. ' Description:  Tic-Tac-Toe Client
  326. ' This file is provided as part of the Microsoft Transaction Server
  327. ' Software Development Kit
  328. ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT
  329. ' WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
  330. ' INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
  331. ' OF MERCHANTABILITY AND/OR FITNESS FOR A  PARTICULAR
  332. ' PURPOSE.
  333. ' Copyright (C) 1997 Microsoft Corporation, All rights reserved
  334. Option Explicit
  335. Private viper As Boolean
  336. Private organic As Boolean
  337. Private playing As Boolean
  338. Private gameID As Long
  339. Private localX As Long
  340. Private localY As Long
  341. Private localOrder As Long
  342. Private localName As String
  343. Private remoteName As String
  344. Private easyComputer As Boolean
  345. Private wins As Long
  346. Private ties As Long
  347. Private losses As Long
  348. Private localPic As Picture
  349. Private remotePic As Picture
  350. Private full(3, 3) As Long
  351. Private waiting As Boolean
  352. Private Sub Easy_Click()
  353.     easyComputer = True
  354. End Sub
  355. Private Sub Form_Load()
  356.     Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000)
  357.     Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000)
  358.     Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 6500)
  359.     Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6500)
  360.     ' Make sure the Tic-Tac-Toe components are properly installed in MTS
  361.     On Error GoTo objError
  362.     Dim computer As Object
  363.     Dim human As Object
  364.     Set computer = CreateObject("tServer.Computer")
  365.     Set human = CreateObject("tServer.Human")
  366.     On Error GoTo 0
  367.     ' Init
  368.     localName = "tClient User"
  369.     remoteName = "No one"
  370.     viper = False
  371.     organic = False
  372.     playing = False
  373.     gameID = -1
  374.     waiting = False
  375.     ServerPoll.Enabled = False
  376.     easyComputer = False
  377.     wins = 0
  378.     ties = 0
  379.     losses = 0
  380.     Nombre = localName
  381.     Name1 = "No one"
  382.     Name2 = remoteName
  383.     Player1.Picture = bmpNull
  384.     Player2.Picture = bmpNull
  385.     Result = "Press a button and start a game"
  386.     Exit Sub
  387. objError:
  388.     MsgBox "Error " & Err.Number & ": Make sure the Tic-Tac-Toe package has been correctly installed in MTS."
  389.     End
  390. End Sub
  391. Private Sub Form_Unload(Cancel As Integer)
  392.     Dim i As Integer
  393.     'Close all sub forms
  394.     For i = Forms.Count - 1 To 1 Step -1
  395.         Unload Forms(i)
  396.     Next
  397.     If Me.WindowState <> vbMinimized Then
  398.         SaveSetting App.Title, "Settings", "MainLeft", Me.Left
  399.         SaveSetting App.Title, "Settings", "MainTop", Me.Top
  400.         SaveSetting App.Title, "Settings", "MainWidth", Me.Width
  401.         SaveSetting App.Title, "Settings", "MainHeight", Me.Height
  402.     End If
  403. End Sub
  404. Private Sub Hard_Click()
  405.     easyComputer = False
  406. End Sub
  407. Private Sub Image00_Click()
  408.     If playing And full(0, 0) = 0 Then
  409.         If localOrder = 1 Then
  410.             Image00.Picture = bmpBigX
  411.         Else
  412.             Image00.Picture = bmpBigO
  413.         End If
  414.         MovePiece 0, 0
  415.     End If
  416. End Sub
  417. Private Sub Image01_Click()
  418.     If playing And full(0, 1) = 0 Then
  419.         If localOrder = 1 Then
  420.             Image01.Picture = bmpBigX
  421.         Else
  422.             Image01.Picture = bmpBigO
  423.         End If
  424.         MovePiece 0, 1
  425.     End If
  426. End Sub
  427. Private Sub Image02_Click()
  428.     If playing And full(0, 2) = 0 Then
  429.         If localOrder = 1 Then
  430.             Image02.Picture = bmpBigX
  431.         Else
  432.             Image02.Picture = bmpBigO
  433.         End If
  434.         MovePiece 0, 2
  435.     End If
  436. End Sub
  437. Private Sub Image10_Click()
  438.     If playing And full(1, 0) = 0 Then
  439.         If localOrder = 1 Then
  440.             Image10.Picture = bmpBigX
  441.         Else
  442.             Image10.Picture = bmpBigO
  443.         End If
  444.         MovePiece 1, 0
  445.     End If
  446. End Sub
  447. Private Sub Image11_Click()
  448.     If playing And full(1, 1) = 0 Then
  449.         If (localOrder = 1) Then
  450.             Image11.Picture = bmpBigX
  451.         Else
  452.             Image11.Picture = bmpBigO
  453.         End If
  454.         MovePiece 1, 1
  455.     End If
  456. End Sub
  457. Private Sub Image12_Click()
  458.     If playing And full(1, 2) = 0 Then
  459.         If localOrder = 1 Then
  460.             Image12.Picture = bmpBigX
  461.         Else
  462.             Image12.Picture = bmpBigO
  463.         End If
  464.         MovePiece 1, 2
  465.     End If
  466. End Sub
  467. Private Sub Image20_Click()
  468.     If playing And full(2, 0) = 0 Then
  469.         If localOrder = 1 Then
  470.             Image20.Picture = bmpBigX
  471.         Else
  472.             Image20.Picture = bmpBigO
  473.         End If
  474.         MovePiece 2, 0
  475.     End If
  476. End Sub
  477. Private Sub Image21_Click()
  478.     If playing And full(2, 1) = 0 Then
  479.         If localOrder = 1 Then
  480.             Image21.Picture = bmpBigX
  481.         Else
  482.             Image21.Picture = bmpBigO
  483.         End If
  484.         MovePiece 2, 1
  485.     End If
  486. End Sub
  487. Private Sub Image22_Click()
  488.     If playing And full(2, 2) = 0 Then
  489.         If localOrder = 1 Then
  490.             Image22.Picture = bmpBigX
  491.         Else
  492.             Image22.Picture = bmpBigO
  493.         End If
  494.         MovePiece 2, 2
  495.     End If
  496. End Sub
  497. Private Sub Nombre_Change()
  498.     localName = Nombre
  499. End Sub
  500. Private Sub PlayHuman_Click()
  501.       
  502.     ' Present hourglass pointer
  503.     Me.MousePointer = vbHourglass
  504.     ' Clean up screen
  505.     ClearScreen
  506.     InitArray
  507.     ' Create server human object
  508.     Dim human As Object
  509.     Set human = CreateObject("tServer.Human")
  510.     If human Is Nothing Then
  511.         MsgBox "Create object " + "tServer.Human" + " failed."
  512.         Exit Sub
  513.     End If
  514.     ' Notify server of new game
  515.     Dim order As Variant
  516.     Dim player2Name As Variant
  517.     Dim gameNumber As Variant
  518.     human.EnterNewGame localName, gameNumber, player2Name, order
  519.     remoteName = player2Name
  520.     gameID = gameNumber
  521.     ' Set up screen
  522.     Name1 = localName
  523.     Name2 = remoteName
  524.     PlayComputer.Enabled = False
  525.     PlayHuman.Enabled = False
  526.     Nombre.Locked = True
  527.     Easy.Enabled = False
  528.     Hard.Enabled = False
  529.     ' Set up local variables
  530.     viper = False
  531.     organic = True
  532.     playing = False
  533.     ServerPoll.Enabled = True
  534.     ' Set up order
  535.     localOrder = order
  536.     If order = 1 Then
  537.         Player1.Picture = bmpSmallX
  538.         Player2.Picture = bmpSmallO
  539.         Set localPic = bmpBigX
  540.         Set remotePic = bmpBigO
  541.         Result = "You are now in game " & gameID & ", we are waiting for another 'human' to join the game."
  542.     Else
  543.         Player1.Picture = bmpSmallO
  544.         Player2.Picture = bmpSmallX
  545.         Set localPic = bmpBigO
  546.         Set remotePic = bmpBigX
  547.         Result = "Game " & gameID & " against '" & remoteName & "' has begun.  Waiting for '" & remoteName & "' to move."
  548.         waiting = True
  549.     End If
  550.     ' Clean up
  551.     Set human = Nothing
  552.     ' Return control
  553.     Me.MousePointer = vbArrow
  554. End Sub
  555. Private Sub PlayComputer_Click()
  556.     ' Present hourglass pointer
  557.     Me.MousePointer = vbHourglass
  558.     ' Clean up screen
  559.     InitArray
  560.     ClearScreen
  561.     ' Create server computer object
  562.     Dim computer As Object
  563.     Set computer = CreateObject("tServer.Computer")
  564.     If computer Is Nothing Then
  565.         MsgBox "Create object " + "tServer.Computer" + " failed."
  566.         Exit Sub
  567.     End If
  568.     ' Notify server of new game
  569.     Dim lGameID As Variant
  570.     Dim order As Variant
  571.     Dim foeX As Variant
  572.     Dim foeY As Variant
  573.     computer.AddNewGame easyComputer, lGameID, order, foeX, foeY
  574.     gameID = lGameID
  575.     ' Set up screen
  576.     If easyComputer = True Then
  577.         remoteName = "I am, I think"
  578.     Else
  579.         remoteName = "I think I am"
  580.     End If
  581.     Name1 = localName
  582.     Name2 = remoteName
  583.     PlayComputer.Enabled = False
  584.     PlayHuman.Enabled = False
  585.     Nombre.Locked = True
  586.     Easy.Enabled = False
  587.     Hard.Enabled = False
  588.     ' Set up local variables
  589.     viper = True
  590.     organic = False
  591.     playing = True
  592.     ' Set up order
  593.     localOrder = order
  594.     If order = 1 Then
  595.         Player1.Picture = bmpSmallX
  596.         Player2.Picture = bmpSmallO
  597.         Set localPic = bmpBigX
  598.         Set remotePic = bmpBigO
  599.     Else
  600.         Player1.Picture = bmpSmallO
  601.         Player2.Picture = bmpSmallX
  602.         Set localPic = bmpBigO
  603.         Set remotePic = bmpBigX
  604.        
  605.         ' Process opponent's first move
  606.         Display remotePic, foeX, foeY
  607.         full(foeX, foeY) = 1
  608.         
  609.     End If
  610.     ' Clean up
  611.     Set computer = Nothing
  612.     ' Return control
  613.     Result = "Game " & gameID & " against '" & remoteName & "' has begun.  It is now your turn."
  614.     Me.MousePointer = vbArrow
  615. End Sub
  616. Private Sub Exit_Click()
  617.     ' Notify opponent of exit
  618.     End
  619. End Sub
  620. Private Sub MovePiece(X As Long, Y As Long)
  621.     Dim win As Variant
  622.     If viper Then
  623.         
  624.         ' Create server computer object
  625.         Dim computer As Object
  626.         Set computer = CreateObject("tServer.Computer")
  627.         If computer Is Nothing Then
  628.             MsgBox "Create object " + "tServer.Computer" + " failed."
  629.             Exit Sub
  630.         End If
  631.         ' Submit move
  632.         Dim foeX As Variant
  633.         Dim foeY As Variant
  634.         computer.NewMove gameID, easyComputer, X, Y, foeX, foeY, win
  635.          
  636.         ' Win protocol
  637.         ' ============
  638.         ' 0  -> moves did not end game
  639.         ' 1  -> player won
  640.         ' -1 -> computer won
  641.         ' 2  -> player's move tied the game
  642.         ' -2 -> computer's move tied the game
  643.         ' Display local move
  644.         Display localPic, X, Y
  645.         full(X, Y) = 1
  646.         
  647.         ' Check for win or loss
  648.         If Abs(win) = 1 Then
  649.             If win = 1 Then
  650.                 wins = wins + 1
  651.                 winsT = wins
  652.                 Result = "Congratulations!  You won your game against '" & remoteName & "'."
  653.                 Cleanup
  654.                 Exit Sub
  655.             Else
  656.                 Display remotePic, foeX, foeY
  657.                 losses = losses + 1
  658.                 lossesT = losses
  659.                 Result = "Too bad, '" & remoteName & "' won.  Better luck next time!"
  660.                 Cleanup
  661.                 Exit Sub
  662.             End If
  663.         Else
  664.             If Abs(win) = 2 Then
  665.                 If win = 2 Then
  666.                     Display remotePic, foeX, foeY
  667.                 End If
  668.                 ties = ties + 1
  669.                 tiesT = ties
  670.                 Result = "You tied '" & remoteName & ".' " & " Keep trying!"
  671.                 Cleanup
  672.                 Exit Sub
  673.             Else
  674.                 ' Display opponent's move
  675.                 Display remotePic, foeX, foeY
  676.                 full(foeX, foeY) = 1
  677.             End If
  678.         End If
  679.         
  680.         ' Clean up
  681.         Set computer = Nothing
  682.         Result = "It is now your turn."
  683.     Else
  684.         ' Shut down server polling
  685.         ServerPoll.Enabled = False
  686.         
  687.         ' Create server human object
  688.         Dim human As Object
  689.         Set human = CreateObject("tServer.Human")
  690.         If human Is Nothing Then
  691.             MsgBox "Create object " + "tServer.Human" + " failed."
  692.             Exit Sub
  693.         End If
  694.         
  695.         ' Submit move
  696.         human.NewMove gameID, localOrder, X, Y, win
  697.         
  698.         ' Win protocol
  699.         ' ============
  700.         ' 0  -> move did not end game
  701.         ' 1  -> player won
  702.         ' -1 -> remote player won (won't occur in this function)
  703.         ' 2  -> player's move tied the game
  704.         ' -2 -> remote player's move tied the game (won't occur in this function)
  705.         
  706.         ' Display local move
  707.         Display localPic, X, Y
  708.         full(X, Y) = 1
  709.         
  710.         ' Check for win or loss
  711.         If win = 1 Then
  712.             wins = wins + 1
  713.             winsT = wins
  714.             Result = "Congratulations!  You won your game against '" & remoteName & "'."
  715.             Cleanup
  716.             Exit Sub
  717.         Else
  718.             If win = 2 Then
  719.                 ties = ties + 1
  720.                 tiesT = ties
  721.                 Result = "You tied '" & remoteName & ".' " & " Keep trying!"
  722.                 Cleanup
  723.                 Exit Sub
  724.             Else
  725.                 ' Reenable server polling
  726.                 ServerPoll.Enabled = True
  727.             End If
  728.         End If
  729.         ' We're waiting for a move or we finished the game
  730.         playing = False
  731.         
  732.         ' Clean up
  733.         Set human = Nothing
  734.         
  735.         Result = "Waiting for '" & remoteName & "'s next move."
  736.     End If
  737. End Sub
  738. Private Sub Display(pic As Picture, X As Variant, Y As Variant)
  739.     Dim hash As Long
  740.     hash = X * 10 + Y
  741.     Select Case hash
  742.         Case 0
  743.             Image00.Picture = pic
  744.         Case 1
  745.             Image01.Picture = pic
  746.         Case 2
  747.             Image02.Picture = pic
  748.         Case 10
  749.             Image10.Picture = pic
  750.         Case 11
  751.             Image11.Picture = pic
  752.         Case 12
  753.             Image12.Picture = pic
  754.         Case 20
  755.             Image20.Picture = pic
  756.         Case 21
  757.             Image21.Picture = pic
  758.         Case 22
  759.             Image22.Picture = pic
  760.         Case Else
  761.             MsgBox ("Invalid Display Parameter")
  762.             
  763.     End Select
  764. End Sub
  765. Private Sub Cleanup()
  766.     ' Reset variables
  767.     playing = False
  768.     viper = False
  769.     organic = False
  770.     PlayHuman.Enabled = True
  771.     PlayComputer.Enabled = True
  772.     Nombre.Locked = False
  773.     Easy.Enabled = True
  774.     Hard.Enabled = True
  775. End Sub
  776. Private Sub InitArray()
  777.     Dim i, j As Long
  778.     For i = 0 To 2
  779.         For j = 0 To 2
  780.             full(i, j) = 0
  781.         Next
  782.     Next
  783. End Sub
  784. Private Sub ServerPoll_Timer()
  785.     If organic And Not playing Then
  786.         ' Create server human object
  787.         Dim human As Object
  788.         Set human = CreateObject("tServer.Human")
  789.         If human Is Nothing Then
  790.             MsgBox "Create object " + "tServer.Human" + " failed."
  791.             Exit Sub
  792.         End If
  793.         ' Poll server
  794.         Dim name As Variant
  795.         Dim foeX As Variant
  796.         Dim foeY As Variant
  797.         Dim win As Variant
  798.         Dim update As Variant
  799.         human.GetNewMove gameID, localOrder, name, foeX, foeY, win, update
  800.         
  801.         ' Win protocol
  802.         ' ============
  803.         ' 0  -> move did not end game
  804.         ' 1  -> player won (won't occur in this function)
  805.         ' -1 -> remote player won
  806.         ' 2  -> player's move tied the game (won't occur in this function)
  807.         ' -2 -> remote player's move tied the game
  808.         ' Routine move
  809.         If update = 1 Then
  810.         
  811.             ' Stop polling
  812.             ServerPoll.Enabled = False
  813.             
  814.             ' Display opponent's move
  815.             Display remotePic, foeX, foeY
  816.             full(foeX, foeY) = 2
  817.             
  818.             ' Check for win or loss
  819.             If win = -1 Then
  820.                 losses = losses + 1
  821.                 lossesT = losses
  822.                 Result = "Too bad, '" & remoteName & "' won.  Better luck next time!"
  823.                 Cleanup
  824.                 Exit Sub
  825.             Else
  826.                 If win = -2 Then
  827.                     ties = ties + 1
  828.                     tiesT = ties + 1
  829.                     Result = "You tied '" & remoteName & ".' " & " Keep trying!"
  830.                     Cleanup
  831.                     Exit Sub
  832.                 Else
  833.                     Result = "'" & remoteName & "' has moved.  It is now your turn."
  834.                     playing = True
  835.                 End If
  836.             End If
  837.         Else
  838.             ' Player just joined
  839.             If update = 2 Then
  840.                 remoteName = name
  841.                 Name2 = remoteName
  842.                 Result = "'" & remoteName & "' has joined your game.  It is now your turn."
  843.                 playing = True
  844.             End If
  845.         End If
  846.         
  847.         ' Clean up
  848.         Set human = Nothing
  849.     End If
  850. End Sub
  851. Private Sub ClearScreen()
  852.     Image00.Picture = LoadPicture
  853.     Image10.Picture = LoadPicture
  854.     Image20.Picture = LoadPicture
  855.     Image01.Picture = LoadPicture
  856.     Image11.Picture = LoadPicture
  857.     Image21.Picture = LoadPicture
  858.     Image02.Picture = LoadPicture
  859.     Image12.Picture = LoadPicture
  860.     Image22.Picture = LoadPicture
  861. End Sub
  862.