#85023 - 2002-01-31 12:57 AM
KixGui Tic Tac Toe Version 0.3
|
Will Hetrick
Hey THIS is FUN
Registered: 2001-10-02
Posts: 320
Loc: Harrisburg, PA USA
|
Tic Tac Toe Version 0.3Fixed 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!
|
|
Top
|
|
|
|
#85024 - 2002-01-31 03:43 AM
Re: KixGui Tic Tac Toe Version 0.3
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
i think one of the problems is that in you checkwin, your exceeding the array bounds of $checkme[8]. the other thing is you might want to pass the index number of the button in your choose_click() as a straight number, ie:$one=$Board.addcmdbutton("cmdStyle1",$1,1,1,98,98,"Choose_click($$one,0,$$input)") anyways, i made a couple of small changes, hope you don't mind: code:
Break on ;SetConsole("hide") $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" $root=createobject("Kixgui.Desktop") If Len($root)=0 Exit 1 EndIf ; 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. ;$PegPos = $Board.addlabel("Lblstyle1","",0,0,100,100) ;$PegPos.borderstyle = 1 ;$Pegpos.textalign=1 ;center $one=$Board.addcmdbutton("cmdStyle1",$1,1,1,98,98,"Choose_click($$one,0,$$input)") $one.borderstyle=1 $PegPos = $Board.addlabel("Lblstyle2","",0,100,100,100) $PegPos.borderstyle = 1 $Pegpos.textalign=1 ;center $Two=$Board.addcmdbutton("cmdStyle2",$2,1,99,98,100,"Choose_click($$two,1,$$input)") $Two.borderstyle=1 $PegPos = $Board.addlabel("Lblstyle3","",0,200,100,100) $PegPos.borderstyle = 1 $Pegpos.textalign=1 ;center $Three =$Board.addcmdbutton("cmdStyle3",$3,0,199,99,99,"Choose_click($$Three,2,$$input)") $Three.borderstyle=1 $PegPos = $Board.addlabel("Lblstyle4","",100,0,100,100) $PegPos.borderstyle = 1 $Pegpos.textalign=1 ;center $Four =$Board.addcmdbutton("cmdStyle4",$4,99,1,100,98,"Choose_click($$four,3,$$input)") $Four.borderstyle=1 $PegPos = $Board.addlabel("Lblstyle5","",100,100,100,100) $PegPos.borderstyle = 1 $Pegpos.textalign=1 ;center $Five =$Board.addcmdbutton("cmdStyle5",$5,99,99,100,100,"Choose_click($$five,4,$$input)") $Five.borderstyle=1 $PegPos = $Board.addlabel("Lblstyle6","",100,200,100,100) $PegPos.borderstyle = 1 $Pegpos.textalign=1 ;center $Six =$Board.addcmdbutton("cmdStyle6",$6,99,199,100,99,"Choose_click($$six,5,$$input)") $Six.borderstyle=1 $PegPos = $Board.addlabel("Lblstyle7","",200,0,100,100) $PegPos.borderstyle = 1 $Pegpos.textalign=1 ;center $Seven =$Board.addcmdbutton("cmdStyle7",$7,199,1,98,98,"Choose_click($$seven,6,$$input)") $Seven.borderstyle=1 $PegPos = $Board.addlabel("Lblstyle8","",200,100,100,100) $PegPos.borderstyle = 1 $Pegpos.textalign=1 ;center $Eight=$Board.addcmdbutton("cmdStyle8",$8,199,99,99,100,"Choose_click($$eight,7,$$input)") $Eight.borderstyle=1 $PegPos = $Board.addlabel("Lblstyle9","",200,200,100,100) $PegPos.borderstyle = 1 $Pegpos.textalign=1 ;center $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) OR ($playagain = "no") $=Execute($Board.lastevent()) Loop Exit Function Choose_click($Pick,$num,$Check) If ($Pick.Caption = "X") OR ($Pick.Caption ="O") $RC = MessageBox("Try an Empty Square","Box in use",1,3) Exit Else $Pick.caption = $input $Checkme[$num] = $check $Win = CheckWin($Check) if $win = "YES" $=messagebox("$check won!","",0) endif If $Check = "X" $input = "O" Else $Input = "X" EndIf 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 1 $Checkwin = "NO" EndSelect EndFunction
-Shawn
|
|
Top
|
|
|
|
#85025 - 2002-01-31 04:58 AM
Re: KixGui Tic Tac Toe Version 0.3
|
Will Hetrick
Hey THIS is FUN
Registered: 2001-10-02
Posts: 320
Loc: Harrisburg, PA USA
|
Thanks Shawn.I don't mind the changes at all. I would not have thought about global and I could not spot the over on the array.
_________________________
You have at least 2 choices. Each choice changes your destiny. Choose wisely!
|
|
Top
|
|
|
|
#85027 - 2002-02-04 12:47 AM
Re: KixGui Tic Tac Toe Version 0.3
|
Alex.H
Seasoned Scripter
Registered: 2001-04-10
Posts: 406
Loc: France
|
Will, seems going nice New KiXGUI version (not released, i have to finish the package) will help you, as all the font syles are corrected, so you'll be able to use big X and O. Dunno how far you goes now, but here are my suggestions : Resize the upper left button to get rid of the huge black border When a button has been selected, disable it. No need for a messagebox after. When any players win or end in a draw, clear everythingAdd network support (ok, just kidding 
_________________________
? getobject(Kixtart.org.Signature)
|
|
Top
|
|
|
|
#85028 - 2002-02-05 12:52 AM
Re: KixGui Tic Tac Toe Version 0.3
|
Will Hetrick
Hey THIS is FUN
Registered: 2001-10-02
Posts: 320
Loc: Harrisburg, PA USA
|
Hey Alex, My next big thing to work on is 1 player mode. Then maybe I will work on network support. I was just happy to get the Check for win working(Thanks to Shawn's help for noticing my mistakes).Let me know when you have the next Kixgui and I will test it.
_________________________
You have at least 2 choices. Each choice changes your destiny. Choose wisely!
|
|
Top
|
|
|
|
#85029 - 2002-02-06 02:04 AM
Re: KixGui Tic Tac Toe Version 0.3
|
Will Hetrick
Hey THIS is FUN
Registered: 2001-10-02
Posts: 320
Loc: Harrisburg, PA USA
|
Bump to the top.Version 0.3 of tictactoe available. I finally had time to work on this and I used the new version of kixgui and it works nicely.
_________________________
You have at least 2 choices. Each choice changes your destiny. Choose wisely!
|
|
Top
|
|
|
|
#85030 - 2002-02-06 04:02 AM
Re: KixGui Tic Tac Toe Version 0.3
|
cj
MM club member
   
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
|
|
Top
|
|
|
|
#85031 - 2002-02-06 01:00 PM
Re: KixGui Tic Tac Toe Version 0.3
|
Will Hetrick
Hey THIS is FUN
Registered: 2001-10-02
Posts: 320
Loc: Harrisburg, PA USA
|
Thanks CJ,That is exactly what I needed to make it better! I will try to decode the computer play and add that in first. Then if everyting goes well, I will try and add in network play.
_________________________
You have at least 2 choices. Each choice changes your destiny. Choose wisely!
|
|
Top
|
|
|
|
#85032 - 2002-02-06 02:13 PM
Re: KixGui Tic Tac Toe Version 0.3
|
Alex.H
Seasoned Scripter
Registered: 2001-04-10
Posts: 406
Loc: France
|
Will, I didn't try it for the moment, but something disturb me with the goto start Doing this, you are creating a new KiXGUI, and keeping the previous one (exactly as if you called the script another time without closing kixtart). This can lead to a memory leech. maybe adding a $root=0 will help just before the goto start I'll get a closer look this evening
_________________________
? getobject(Kixtart.org.Signature)
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 2312 anonymous users online.
|
|
|