home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / komix / DATA.Z / TicTacToe_GUI.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-10-01  |  12.7 KB  |  393 lines

  1. VERSION 5.00
  2. Begin VB.Form TicTacToe_GUI 
  3.    BackColor       =   &H00000000&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Tic Tac Toe"
  6.    ClientHeight    =   4170
  7.    ClientLeft      =   8400
  8.    ClientTop       =   2805
  9.    ClientWidth     =   3585
  10.    FillColor       =   &H80000003&
  11.    BeginProperty Font 
  12.       Name            =   "Terminal"
  13.       Size            =   13.5
  14.       Charset         =   255
  15.       Weight          =   700
  16.       Underline       =   0   'False
  17.       Italic          =   0   'False
  18.       Strikethrough   =   0   'False
  19.    EndProperty
  20.    LinkTopic       =   "Form1"
  21.    MaxButton       =   0   'False
  22.    ScaleHeight     =   4170
  23.    ScaleWidth      =   3585
  24.    Begin VB.Frame Board
  25.       BackColor       =   &H00000000&
  26.       ClipControls    =   0   'False
  27.       Height          =   3375
  28.       Left            =   -120
  29.       TabIndex        =   1
  30.       Top             =   -240
  31.       Width           =   3735
  32.       Begin VB.CommandButton CellButton
  33.          BeginProperty Font 
  34.             Name            =   "Arial"
  35.             Size            =   24
  36.             Charset         =   0
  37.             Weight          =   700
  38.             Underline       =   0   'False
  39.             Italic          =   0   'False
  40.             Strikethrough   =   0   'False
  41.          EndProperty
  42.          Height          =   735
  43.          Index           =   8
  44.          Left            =   2280
  45.          TabIndex        =   10
  46.          TabStop         =   0   'False
  47.          Top             =   2160
  48.          Width           =   855
  49.       End
  50.       Begin VB.CommandButton CellButton
  51.          BeginProperty Font 
  52.             Name            =   "Arial"
  53.             Size            =   24
  54.             Charset         =   0
  55.             Weight          =   700
  56.             Underline       =   0   'False
  57.             Italic          =   0   'False
  58.             Strikethrough   =   0   'False
  59.          EndProperty
  60.          Height          =   735
  61.          Index           =   7
  62.          Left            =   1440
  63.          TabIndex        =   9
  64.          TabStop         =   0   'False
  65.          Top             =   2160
  66.          Width           =   855
  67.       End
  68.       Begin VB.CommandButton CellButton
  69.          BeginProperty Font 
  70.             Name            =   "Arial"
  71.             Size            =   24
  72.             Charset         =   0
  73.             Weight          =   700
  74.             Underline       =   0   'False
  75.             Italic          =   0   'False
  76.             Strikethrough   =   0   'False
  77.          EndProperty
  78.          Height          =   735
  79.          Index           =   6
  80.          Left            =   600
  81.          TabIndex        =   8
  82.          TabStop         =   0   'False
  83.          Top             =   2160
  84.          Width           =   855
  85.       End
  86.       Begin VB.CommandButton CellButton
  87.          BeginProperty Font 
  88.             Name            =   "Arial"
  89.             Size            =   24
  90.             Charset         =   0
  91.             Weight          =   700
  92.             Underline       =   0   'False
  93.             Italic          =   0   'False
  94.             Strikethrough   =   0   'False
  95.          EndProperty
  96.          Height          =   735
  97.          Index           =   5
  98.          Left            =   2280
  99.          TabIndex        =   7
  100.          TabStop         =   0   'False
  101.          Top             =   1440
  102.          Width           =   855
  103.       End
  104.       Begin VB.CommandButton CellButton
  105.          BeginProperty Font 
  106.             Name            =   "Arial"
  107.             Size            =   24
  108.             Charset         =   0
  109.             Weight          =   700
  110.             Underline       =   0   'False
  111.             Italic          =   0   'False
  112.             Strikethrough   =   0   'False
  113.          EndProperty
  114.          Height          =   735
  115.          Index           =   4
  116.          Left            =   1440
  117.          TabIndex        =   6
  118.          TabStop         =   0   'False
  119.          Top             =   1440
  120.          Width           =   855
  121.       End
  122.       Begin VB.CommandButton CellButton
  123.          BeginProperty Font 
  124.             Name            =   "Arial"
  125.             Size            =   24
  126.             Charset         =   0
  127.             Weight          =   700
  128.             Underline       =   0   'False
  129.             Italic          =   0   'False
  130.             Strikethrough   =   0   'False
  131.          EndProperty
  132.          Height          =   735
  133.          Index           =   3
  134.          Left            =   600
  135.          TabIndex        =   5
  136.          TabStop         =   0   'False
  137.          Top             =   1440
  138.          Width           =   855
  139.       End
  140.       Begin VB.CommandButton CellButton
  141.          BeginProperty Font 
  142.             Name            =   "Arial"
  143.             Size            =   24
  144.             Charset         =   0
  145.             Weight          =   700
  146.             Underline       =   0   'False
  147.             Italic          =   0   'False
  148.             Strikethrough   =   0   'False
  149.          EndProperty
  150.          Height          =   735
  151.          Index           =   2
  152.          Left            =   2280
  153.          TabIndex        =   4
  154.          TabStop         =   0   'False
  155.          Top             =   720
  156.          Width           =   855
  157.       End
  158.       Begin VB.CommandButton CellButton
  159.          BeginProperty Font 
  160.             Name            =   "Arial"
  161.             Size            =   24
  162.             Charset         =   0
  163.             Weight          =   700
  164.             Underline       =   0   'False
  165.             Italic          =   0   'False
  166.             Strikethrough   =   0   'False
  167.          EndProperty
  168.          Height          =   735
  169.          Index           =   1
  170.          Left            =   1440
  171.          TabIndex        =   3
  172.          TabStop         =   0   'False
  173.          Top             =   720
  174.          Width           =   855
  175.       End
  176.       Begin VB.CommandButton CellButton
  177.          BeginProperty Font 
  178.             Name            =   "Arial"
  179.             Size            =   24
  180.             Charset         =   0
  181.             Weight          =   700
  182.             Underline       =   0   'False
  183.             Italic          =   0   'False
  184.             Strikethrough   =   0   'False
  185.          EndProperty
  186.          Height          =   735
  187.          Index           =   0
  188.          Left            =   600
  189.          TabIndex        =   2
  190.          TabStop         =   0   'False
  191.          Top             =   720
  192.          Width           =   855
  193.       End
  194.    End
  195.    Begin VB.Label Result
  196.       Alignment       =   2  'Center
  197.       BackColor       =   &H80000008&
  198.       BeginProperty Font 
  199.          Name            =   "Arial"
  200.          Size            =   18
  201.          Charset         =   0
  202.          Weight          =   700
  203.          Underline       =   0   'False
  204.          Italic          =   0   'False
  205.          Strikethrough   =   0   'False
  206.       EndProperty
  207.       ForeColor       =   &H0000FFFF&
  208.       Height          =   855
  209.       Left            =   0
  210.       TabIndex        =   0
  211.       Top             =   3360
  212.       Width           =   3615
  213.    End
  214.    Begin VB.Menu GameMenu
  215.       Caption         =   "&Game"
  216.       Begin VB.Menu New
  217.          Caption         =   "&New"
  218.          Shortcut        =   ^N
  219.       End
  220.    End
  221.    Begin VB.Menu Opponent
  222.       Caption         =   "&Opponent"
  223.       Begin VB.Menu Oppo
  224.          Caption         =   "&Human"
  225.          Checked         =   -1  'True
  226.          Index           =   0
  227.          Shortcut        =   ^H
  228.       End
  229.       Begin VB.Menu Oppo
  230.          Caption         =   "Computer &X"
  231.          Index           =   1
  232.          Shortcut        =   ^X
  233.       End
  234.       Begin VB.Menu Oppo
  235.          Caption         =   "Computer &O"
  236.          Index           =   2
  237.          Shortcut        =   ^O
  238.       End
  239.    End
  240. Attribute VB_Name = "TicTacToe_GUI"
  241. Attribute VB_GlobalNameSpace = False
  242. Attribute VB_Creatable = False
  243. Attribute VB_PredeclaredId = True
  244. Attribute VB_Exposed = False
  245. ' File          : TicTacToe_GUI.frm
  246. ' Project       : demo
  247. ' Configuration : demo 1
  248. ' Phase         : Implementation 1
  249. ' System        : TicTacToe 1
  250. ' User defined control GameMenu of TicTacToe_GameMenu
  251. ' User defined control New of TicTacToe_New
  252. ' User defined control Opponent of TicTacToe_OpponentMenu
  253. ' User defined control Oppo of TicTacToe_Opponent
  254. ' User defined control Oppo of TicTacToe_Opponent
  255. ' User defined control Oppo of TicTacToe_Opponent
  256. ' User defined control Board of TicTacToe_Board
  257. ' User defined control CellButton of TicTacToe_CellButton
  258. ' User defined control CellButton of TicTacToe_CellButton
  259. ' User defined control CellButton of TicTacToe_CellButton
  260. ' User defined control CellButton of TicTacToe_CellButton
  261. ' User defined control CellButton of TicTacToe_CellButton
  262. ' User defined control CellButton of TicTacToe_CellButton
  263. ' User defined control CellButton of TicTacToe_CellButton
  264. ' User defined control CellButton of TicTacToe_CellButton
  265. ' User defined control CellButton of TicTacToe_CellButton
  266. ' User defined control Result of TicTacToe_Result
  267. ' Graphical User Interface of the game.
  268. Option Explicit
  269. ' Association attributes
  270. Public computer_ As TicTacToe_Computer
  271. Public game_ As TicTacToe_Game
  272. ' User defined attributes
  273. Private numberOfCells_ As Integer
  274. ' Has default value 9
  275. ' User defined methods
  276. Public Sub TicTacToe_GUI_Constructor(a_computer As TicTacToe_Computer, a_game As TicTacToe_Game)
  277.     numberOfCells = 9
  278.     Set computer = a_computer
  279.     Set game = a_game
  280.     ' Start user section
  281.     game.startGame
  282.     ' End user section
  283. End Sub
  284. Private Sub Form_Terminate()
  285.     ' Start user section
  286.     ' End user section
  287.     If Not (computer_ Is Nothing) Then
  288.         Set computer_.gui_ = Nothing
  289.     End If
  290.     If Not (game_ Is Nothing) Then
  291.         Set game_.gui_ = Nothing
  292.     End If
  293. End Sub
  294. ' Disables all the buttons of the board.
  295. Public Sub disableBoard()
  296.     Dim i As Integer
  297.     For i = 0 To (numberOfCells - 1)
  298.         CellButton(i).Enabled = False
  299.     Next i
  300. End Sub
  301. ' Enables all the buttons of the board.
  302. Public Sub enableBoard()
  303.     Dim i As Integer
  304.     For i = 0 To (numberOfCells - 1)
  305.         If CellButton(i).Caption = "" Then
  306.             CellButton(i).Enabled = True
  307.         End If
  308.     Next i
  309. End Sub
  310. ' Clears the contents of all the buttons of the board.
  311. Public Sub clearBoard()
  312.     Dim i As Integer
  313.     For i = 0 To (numberOfCells - 1)
  314.         CellButton(i).Caption = ""
  315.     Next i
  316. End Sub
  317. ' Displays the specified result.
  318. Public Sub displayResult(text As String)
  319.     Result.Caption = text
  320. End Sub
  321. ' Events
  322. ' Initializes the window.
  323. Private Sub Form_Initialize()
  324.     Dim game_temp As New TicTacToe_Game
  325.     Dim comp_temp As New TicTacToe_Computer
  326.     Me.TicTacToe_GUI_Constructor comp_temp, game_temp
  327.     game_temp.TicTacToe_Game_Constructor
  328.     comp_temp.TicTacToe_Computer_Constructor game_temp
  329. End Sub
  330. ' Starts new game.
  331. Public Sub New_Click()
  332.     game.startGame
  333.     computer.checkTurn
  334. End Sub
  335. ' Sets opponent.
  336. Public Sub Oppo_Click(Index As Integer)
  337.      Oppo(0).Checked = False
  338.      Oppo(1).Checked = False
  339.      Oppo(2).Checked = False
  340.      Oppo(Index).Checked = True
  341.      If Index > 0 Then
  342.         computer.id = Mid(game.players, Index, 1)
  343.         computer.checkTurn
  344.      Else
  345.         computer.id = ""
  346.      End If
  347. End Sub
  348. ' Checks if cell is empty and sets it.
  349. Public Sub CellButton_Click(Index As Integer)
  350.     If CellButton(Index).Enabled Then
  351.         CellButton(Index).Enabled = False
  352.         CellButton(Index).Caption = game.getActivePlayer
  353.         game.selectCell (Index)
  354.         computer.checkTurn
  355.     End If
  356. End Sub
  357. ' Access methods
  358. Public Property Get numberOfCells() As Integer
  359.     numberOfCells = numberOfCells_
  360. End Property
  361. Public Property Let numberOfCells(x As Integer)
  362.     numberOfCells_ = x
  363. End Property
  364. ' Association methods
  365. Public Property Get computer() As TicTacToe_Computer
  366.     Set computer = computer_
  367. End Property
  368. Public Property Set computer(x As TicTacToe_Computer)
  369.     If Not (x Is Nothing) Then
  370.         If x.gui Is Nothing Then
  371.             If Not (computer_ Is Nothing) Then
  372.                 Set computer_.gui_ = Nothing
  373.             End If
  374.             Set computer_ = x
  375.             Set x.gui_ = Me
  376.         End If
  377.     End If
  378. End Property
  379. Public Property Get game() As TicTacToe_Game
  380.     Set game = game_
  381. End Property
  382. Public Property Set game(x As TicTacToe_Game)
  383.     If Not (x Is Nothing) Then
  384.         If x.gui Is Nothing Then
  385.             If Not (game_ Is Nothing) Then
  386.                 Set game_.gui_ = Nothing
  387.             End If
  388.             Set game_ = x
  389.             Set x.gui_ = Me
  390.         End If
  391.     End If
  392. End Property
  393.