Tic Tac Toe Version 0.3

Fixed the error thanks to Shawn

Also reduced the code to make it smaller.

Disabled the Buttons after they are picked which was Alex's suggestion.

Added a check for a tie.

Now it asks when the game is over to play again and resets the board or closes the board if no.

code:
 

Break on
SetConsole("hide")

$root=createobject("Kixgui.Desktop")
If Len($root)=0
Exit 1
EndIf

:Start
$Playagain = "maybe"
$input = "X"
Global $Checkme[8]
$Checkme[0] = "N"
$Checkme[1] = "N"
$Checkme[2] = "N"
$Checkme[3] = "N"
$Checkme[4] = "N"
$Checkme[5] = "N"
$Checkme[6] = "N"
$Checkme[7] = "N"
$Checkme[8] = "N"
; Draws the Starting Board and places it on the Screen
$Board = $root.createform("FrmBoard","Tic Tac Toe Board")
$Board.Width = 310
$Board.Height = 340
$Board.Top = ($Board.parent.height - $Board.height) / 2
$Board.Left = ($root.width - $Board.width ) / 2
; Draws the lines to seperate the board.
$one=$Board.addcmdbutton("cmdStyle1",$1,1,1,98,98,"Choose_click($$one,0,$$input)")
$one.borderstyle=1
$Two=$Board.addcmdbutton("cmdStyle2",$2,1,99,98,100,"Choose_click($$two,1,$$input)")
$Two.borderstyle=1
$Three =$Board.addcmdbutton("cmdStyle3",$3,0,199,99,99,"Choose_click($$Three,2,$$input)")
$Three.borderstyle=1
$Four =$Board.addcmdbutton("cmdStyle4",$4,99,1,100,98,"Choose_click($$four,3,$$input)")
$Four.borderstyle=1
$Five =$Board.addcmdbutton("cmdStyle5",$5,99,99,100,100,"Choose_click($$five,4,$$input)")
$Five.borderstyle=1
$Six =$Board.addcmdbutton("cmdStyle6",$6,99,199,100,99,"Choose_click($$six,5,$$input)")
$Six.borderstyle=1
$Seven =$Board.addcmdbutton("cmdStyle7",$7,199,1,98,98,"Choose_click($$seven,6,$$input)")
$Seven.borderstyle=1
$Eight=$Board.addcmdbutton("cmdStyle8",$8,199,99,99,100,"Choose_click($$eight,7,$$input)")
$Eight.borderstyle=1
$Nine =$Board.addcmdbutton("cmdStyle9",$9,199,199,99,99,"Choose_click($$nine,8,$$input)")
$Nine.borderstyle=1
; Makes the board Visible
$Board.visible = 1
While ($Board.visible) AND ($playagain = "maybe")
$=Execute($Board.lastevent())
Loop
If $playagain = "yes"
Goto start
EndIf
Exit
Function Choose_click($Pick,$num,$Check)
$Pick.fontsize = 75
$pick.enable = 0
$Pick.caption = $input
$Checkme[$num] = $check
$Win = CheckWin($Check)
If ($win = "YES") OR ($Win = "tie")
If $win = "tie"
$Check = "Nobody"
EndIf
$test=MessageBox(" $check won! @crlfDo you want to play again","Tic Tac Toe",4)
If $test = "6"
$playagain = "yes"
Else
$playagain = "no"
EndIf
EndIf
If $Check = "X"
$input = "O"
Else
$Input = "X"
EndIf

Exit
EndFunction
Function Checkwin($input)
Select
Case ($checkme[0] = $input) AND ($Checkme[1] = $input) AND ($checkme[2] = $input)
$checkwin = "YES"
Case ($checkme[3] = $input) AND ($Checkme[4] = $input) AND ($checkme[5] = $input)
$checkwin = "YES"
Case ($checkme[6] = $input) AND ($Checkme[7] = $input) AND ($checkme[8] = $input)
$checkwin = "YES"
Case ($checkme[0] = $input) AND ($Checkme[3] = $input) AND ($checkme[6] = $input)
$checkwin = "YES"
Case ($checkme[1] = $input) AND ($Checkme[4] = $input) AND ($checkme[7] = $input)
$checkwin = "YES"
Case ($checkme[2] = $input) AND ($Checkme[5] = $input) AND ($checkme[8] = $input)
$checkwin = "YES"
Case ($checkme[0] = $input) AND ($Checkme[4] = $input) AND ($checkme[8] = $input)
$checkwin = "YES"
Case ($checkme[2] = $input) AND ($Checkme[4] = $input) AND ($checkme[6] = $input)
$checkwin = "YES"
Case ($checkme[0] <> "N") AND ($checkme[1] <> "N") AND($checkme[2] <> "N") AND($checkme[3] <> "N") AND($checkme[4] <> "N") AND($checkme[5] <> "N") AND($checkme[6] <> "N") AND($checkme[7] <> "N") AND($checkme[8] <> "N")
$Checkwin = "Tie"
Case 1
$Checkwin = "NO"
EndSelect

EndFunction


[ 06 February 2002: Message edited by: Will Hetrick ]

_________________________
You have at least 2 choices. Each choice changes your destiny. Choose wisely!