VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form frmTicTacToe 
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "Tic-Tac-Toe"
   ClientHeight    =   3090
   ClientLeft      =   45
   ClientTop       =   405
   ClientWidth     =   4350
   ControlBox      =   0   'False
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmTicTacToe.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3090
   ScaleWidth      =   4350
   StartUpPosition =   3  'Windows Default
   Begin MSComctlLib.ImageList ImageList1 
      Left            =   3720
      Top             =   600
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   32
      ImageHeight     =   32
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   3
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmTicTacToe.frx":058A
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmTicTacToe.frx":05ED
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmTicTacToe.frx":0BEA
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin VB.CommandButton cmdReset 
      Caption         =   "Reset Board"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   2400
      TabIndex        =   2
      Top             =   1560
      Width           =   1815
   End
   Begin VB.CommandButton cmdEndGame 
      Caption         =   "End Game"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   2400
      TabIndex        =   1
      Top             =   2160
      Width           =   1815
   End
   Begin VB.Label lblStatus 
      Caption         =   "..."
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000C0C0&
      Height          =   255
      Left            =   120
      TabIndex        =   6
      Top             =   2760
      Width           =   4095
   End
   Begin VB.Label lblDraw 
      Caption         =   "Draw: 0"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF0000&
      Height          =   255
      Left            =   2520
      TabIndex        =   5
      Top             =   960
      Width           =   1695
   End
   Begin VB.Label lblLost 
      Caption         =   "Lost: 0"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF0000&
      Height          =   255
      Left            =   2520
      TabIndex        =   4
      Top             =   720
      Width           =   1695
   End
   Begin VB.Label lblWon 
      Caption         =   "Won: 0"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF0000&
      Height          =   255
      Left            =   2520
      TabIndex        =   3
      Top             =   480
      Width           =   1695
   End
   Begin VB.Image square 
      Height          =   480
      Index           =   8
      Left            =   1680
      Picture         =   "frmTicTacToe.frx":11F6
      Top             =   2040
      Width           =   480
   End
   Begin VB.Image square 
      Height          =   480
      Index           =   7
      Left            =   960
      Picture         =   "frmTicTacToe.frx":1249
      Top             =   2040
      Width           =   480
   End
   Begin VB.Image square 
      Height          =   480
      Index           =   6
      Left            =   240
      Picture         =   "frmTicTacToe.frx":129C
      Top             =   2040
      Width           =   480
   End
   Begin VB.Image square 
      Height          =   480
      Index           =   5
      Left            =   1680
      Picture         =   "frmTicTacToe.frx":12EF
      Top             =   1320
      Width           =   480
   End
   Begin VB.Image square 
      Height          =   480
      Index           =   4
      Left            =   960
      Picture         =   "frmTicTacToe.frx":1342
      Top             =   1320
      Width           =   480
   End
   Begin VB.Image square 
      Height          =   480
      Index           =   3
      Left            =   240
      Picture         =   "frmTicTacToe.frx":1395
      Top             =   1320
      Width           =   480
   End
   Begin VB.Image square 
      Height          =   480
      Index           =   2
      Left            =   1680
      Picture         =   "frmTicTacToe.frx":13E8
      Top             =   600
      Width           =   480
   End
   Begin VB.Image square 
      Height          =   480
      Index           =   1
      Left            =   960
      Picture         =   "frmTicTacToe.frx":143B
      Top             =   600
      Width           =   480
   End
   Begin VB.Image square 
      Height          =   480
      Index           =   0
      Left            =   240
      Picture         =   "frmTicTacToe.frx":148E
      Top             =   600
      Width           =   480
   End
   Begin VB.Line Line4 
      X1              =   120
      X2              =   2280
      Y1              =   1920
      Y2              =   1920
   End
   Begin VB.Line Line3 
      X1              =   120
      X2              =   2280
      Y1              =   1200
      Y2              =   1200
   End
   Begin VB.Line Line2 
      X1              =   1560
      X2              =   1560
      Y1              =   480
      Y2              =   2640
   End
   Begin VB.Line Line1 
      X1              =   840
      X2              =   840
      Y1              =   480
      Y2              =   2640
   End
   Begin VB.Label Label1 
      Caption         =   "Playing Tic-Tac-Toe with Chriso"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   4095
   End
End
Attribute VB_Name = "frmTicTacToe"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public BotIndex As Integer
Public Player As String
Public Naut As Boolean
Public Wins As Long, Loss As Long, Draw As Long
Private IsYourGo As Boolean

Public Property Get YourGo() As Boolean
    YourGo = IsYourGo
End Property

Public Property Let YourGo(value As Boolean)
    If value Then
        lblStatus = "Your turn!"
        lblStatus.ForeColor = &HC000&
    Else
        lblStatus = "Waiting for other player..."
        lblStatus.ForeColor = &HC0C0&
    End If
    cmdReset.Enabled = value
    IsYourGo = value
End Property

Private Sub cmdEndGame_Click()
    frmBot.Bot(BotIndex).SendText "/w " & Player & " $_endgame"
    Unload Me
End Sub

Private Sub cmdReset_Click()
    frmBot.Bot(BotIndex).SendText "/w " & Player & " $_reset"
End Sub

Private Sub Form_Load()
    Reset
End Sub

Public Sub Clicked(Index As Integer)
    If Not YourGo Then
        'Player clicked a square
        If square(Index).Picture = ImageList1.ListImages(1).Picture Then
            If Naut Then
                square(Index).Picture = ImageList1.ListImages(3).Picture
            Else
                square(Index).Picture = ImageList1.ListImages(2).Picture
            End If
            Check
            YourGo = True
        End If
    End If
End Sub

Public Sub Check()
    Dim Pos(7, 2) As Byte
    'Accross
    Pos(0, 0) = 0
    Pos(0, 1) = 1
    Pos(0, 2) = 2
    Pos(1, 0) = 3
    Pos(1, 1) = 4
    Pos(1, 2) = 5
    Pos(2, 0) = 6
    Pos(2, 1) = 7
    Pos(2, 2) = 8
    
    'Down
    Pos(3, 0) = 0
    Pos(3, 1) = 3
    Pos(3, 2) = 6
    Pos(4, 0) = 1
    Pos(4, 1) = 4
    Pos(4, 2) = 7
    Pos(5, 0) = 2
    Pos(5, 1) = 5
    Pos(5, 2) = 8
    
    'Diagonal
    Pos(6, 0) = 0
    Pos(6, 1) = 4
    Pos(6, 2) = 8
    Pos(7, 0) = 2
    Pos(7, 1) = 4
    Pos(7, 2) = 6
    
    Dim I As Integer, Won As Boolean, Finish As Boolean
    For I = 0 To 7
        If square(Pos(I, 0)).Picture = ImageList1.ListImages(2).Picture And _
            square(Pos(I, 1)).Picture = ImageList1.ListImages(2).Picture And _
            square(Pos(I, 2)).Picture = ImageList1.ListImages(2).Picture Then
            If Naut Then
                Wins = Wins + 1
                lblWon = "Won: " & Wins
                Won = True
            Else
                Loss = Loss + 1
                lblLost = "Lost: " & Loss
            End If
            Finish = True
            Exit For
        ElseIf square(Pos(I, 0)).Picture = ImageList1.ListImages(3).Picture And _
            square(Pos(I, 1)).Picture = ImageList1.ListImages(3).Picture And _
            square(Pos(I, 2)).Picture = ImageList1.ListImages(3).Picture Then
            If Not Naut Then
                Wins = Wins + 1
                lblWon = "Won: " & Wins
                Won = True
            Else
                Loss = Loss + 1
                lblLost = "Lost: " & Loss
            End If
            Finish = True
            Exit For
        End If
    Next I
    
    Erase Pos()
    
    If Finish Then
        If Won Then
            MsgBox "Congratulations, you won!", vbInformation, "Tic-Tac-Toe"
        Else
            MsgBox "Sorry, you lost!", vbInformation, "Tic-Tac-Toe"
        End If
        Reset
        Exit Sub
    End If
    
    Dim Count As Integer
    For I = 0 To 8
        If square(I).Picture <> ImageList1.ListImages(1).Picture Then
            Count = Count + 1
        End If
    Next I
    If Count = 9 Then
        Draw = Draw + 1
        lblDraw.Caption = "Draw: " & Draw
        MsgBox "Game resulted in a draw!", vbInformation, "Tic-Tac-Toe"
        Reset
    End If
End Sub

Private Sub square_Click(Index As Integer)
    If YourGo Then
        frmBot.Bot(BotIndex).SendText "/w " & Player & " $_square#" & Index
        'You clicked a square
        If square(Index).Picture = ImageList1.ListImages(1).Picture Then
            If Naut Then
                square(Index).Picture = ImageList1.ListImages(2).Picture
            Else
                square(Index).Picture = ImageList1.ListImages(3).Picture
            End If
            Check
            YourGo = False
        End If
    End If
End Sub

Public Sub endgame()
    'Player endgameed
    MsgBox Player & " ended the game!", vbInformation, "Tic-Tac-Toe"
    Unload Me
End Sub

Public Sub Reset()
    'Player accepted reset or you confirmed
    Dim I As Integer
    For I = 0 To square.UBound
        square(I).Picture = ImageList1.ListImages(1).Picture
    Next I
End Sub
