Hello!
While i was doing nothing i had an idea : Why don't try to create Tic Tac Toe in AutoIt?
Well , here it is. I think it's quite complete *.
I tryed it and i noticed just one bug , but i don't know how to fix it.(You'll notice it very fast : if you won a match with the last space there will be 2 messages)
Version 0.1:
Fixed a bug.
Thanks to alpines
Here there's the source:
If you figure how to solve the bug then please tell me! :handsdown:
* = You must play it with another person , it's not bot vs human.
While i was doing nothing i had an idea : Why don't try to create Tic Tac Toe in AutoIt?
Well , here it is. I think it's quite complete *.
I tryed it and i noticed just one bug , but i don't know how to fix it.(You'll notice it very fast : if you won a match with the last space there will be 2 messages)
Version 0.1:
Fixed a bug.
Thanks to alpines
Here there's the source:
Code:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$v1 = ""
$v2 = ""
$v3 = ""
$v4 = ""
$v5 = ""
$v6 = ""
$v7 = ""
$v8 = ""
$v9 = ""
FileInstall ("C:\Windows\winsxs\amd64_microsoft-windows-shell-sounds_31bf3856ad364e35_6.1.7600.16385_none_73076dd9cf3a9dce\tada.wav",@TempDir & "\tictacsound.wav")
$Form1 = GUICreate("Tic-Tac-Toe", 205, 205, -1, -1)
GUISetBkColor(0x000000)
GUISetFont(18, 800, 0, "MS Sans Serif")
$a = GUICtrlCreateButton("", 0, 0, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$b = GUICtrlCreateButton("", 70, 0, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$c = GUICtrlCreateButton("", 140, 0, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$d = GUICtrlCreateButton("", 0, 70, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$e = GUICtrlCreateButton("", 70, 70, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$f = GUICtrlCreateButton("", 140, 70, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$g = GUICtrlCreateButton("", 0, 140, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$h = GUICtrlCreateButton("", 70, 140, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$i = GUICtrlCreateButton("", 140, 140, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
GUISetState(@SW_SHOW)
$xo = "O"
$status1 = ""
$status2 = ""
$status3 = ""
$status4 = ""
$status5 = ""
$status6 = ""
$status7 = ""
$status8 = ""
$status9 = ""
$valX = 0
$valO = 0
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $a ;TOPLEFT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($a,$xo)
GUICtrlSetState ($a,$GUI_DISABLE)
$status1 = "1"
Case $b ;TOPCENTER
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($b,$xo)
GUICtrlSetState ($b,$GUI_DISABLE)
$status2 = "1"
Case $c ;TOPRIGHT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($c,$xo)
GUICtrlSetState ($c,$GUI_DISABLE)
$status3 = "1"
Case $d ;LEFT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($d,$xo)
GUICtrlSetState ($d,$GUI_DISABLE)
$status4 = "1"
Case $e ;CENTER
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($e,$xo)
GUICtrlSetState ($e,$GUI_DISABLE)
$status5 = "1"
Case $f ;RIGHT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($f,$xo)
GUICtrlSetState ($f,$GUI_DISABLE)
$status6 = "1"
Case $g ;DOWNLEFT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($g,$xo)
GUICtrlSetState ($g,$GUI_DISABLE)
$status7 = "1"
Case $h ;DOWNCENTER
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($h,$xo)
GUICtrlSetState ($h,$GUI_DISABLE)
$status8 = "1"
Case $i ;DOWNRIGHT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($i,$xo)
GUICtrlSetState ($i,$GUI_DISABLE)
$status9 = "1"
EndSwitch
$statcheck = $status9 & $status8 & $status7 & $status6 & $status5 & $status4 & $status3 & $status2 & $status1
if $status1 = 1 Then
$v1 = GUICtrlRead ($a)
EndIf
if $status2 = 1 Then
$v2 = GUICtrlRead ($b)
EndIf
if $status3 = 1 Then
$v3 = GUICtrlRead ($c)
EndIf
if $status4 = 1 Then
$v4 = GUICtrlRead ($d)
EndIf
if $status5 = 1 Then
$v5 = GUICtrlRead ($e)
EndIf
if $status6 = 1 Then
$v6 = GUICtrlRead ($f)
EndIf
if $status7 = 1 Then
$v7 = GUICtrlRead ($g)
EndIf
if $status8 = 1 Then
$v8 = GUICtrlRead ($h)
EndIf
if $status9 = 1 Then
$v9 = GUICtrlRead ($i)
EndIf
;A B C X
if $v1 = "X" And $v2 = "X" And $v3 = "X" Then
GUICtrlSetBkColor($a, 0x00FFFF)
GUICtrlSetBkColor($b, 0x00FFFF)
GUICtrlSetBkColor($c, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;A B C O
Elseif $v1 = "O" And $v2 = "O" And $v3 = "O" Then
GUICtrlSetBkColor($a, 0x00FF00)
GUICtrlSetBkColor($b, 0x00FF00)
GUICtrlSetBkColor($c, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;D E F X
Elseif $v4 = "X" And $v5 = "X" And $v6 = "X" Then
GUICtrlSetBkColor($d, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($f, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;D E F O
Elseif $v4 = "O" And $v5 = "O" And $v6 = "O" Then
GUICtrlSetBkColor($d, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($f, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;G H I X
Elseif $v7 = "X" And $v8 = "X" And $v9 = "X" Then
GUICtrlSetBkColor($g, 0x00FFFF)
GUICtrlSetBkColor($h, 0x00FFFF)
GUICtrlSetBkColor($i, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
;G H I O
Elseif $v7 = "O" And $v8 = "O" And $v9 = "O" Then
GUICtrlSetBkColor($g, 0x00FF00)
GUICtrlSetBkColor($h, 0x00FF00)
GUICtrlSetBkColor($i, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
; A D G X
Elseif $v1 = "X" And $v4 = "X" And $v7 = "X" Then
GUICtrlSetBkColor($a, 0x00FFFF)
GUICtrlSetBkColor($d, 0x00FFFF)
GUICtrlSetBkColor($g, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
; A D G O
Elseif $v1 = "O" And $v4 = "O" And $v7 = "O" Then
GUICtrlSetBkColor($a, 0x00FF00)
GUICtrlSetBkColor($d, 0x00FF00)
GUICtrlSetBkColor($g, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;B E H X
Elseif $v2 = "X" And $v5 = "X" And $v8 = "X" Then
GUICtrlSetBkColor($b, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($h, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
; B E H O
Elseif $v2 = "O" And $v5 = "O" And $v8 = "O" Then
GUICtrlSetBkColor($b, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($h, 0x00FF00)
win()
MsgBox (0,"","Player 'X' won the match!")
$valO = $valO+ 1
reset()
score()
;C F I X
Elseif $v3 = "X" And $v6 = "X" And $v9 = "X" Then
GUICtrlSetBkColor($c, 0x00FFFF)
GUICtrlSetBkColor($f, 0x00FFFF)
GUICtrlSetBkColor($i, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
; C F I O
Elseif $v3 = "O" And $v6 = "O" And $v9 = "O" Then
GUICtrlSetBkColor($c, 0x00FF00)
GUICtrlSetBkColor($f, 0x00FF00)
GUICtrlSetBkColor($i, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
;A E I X
Elseif $v1 = "X" And $v5 = "X" And $v9 = "X" Then
GUICtrlSetBkColor($a, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($i, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;A E I O
Elseif $v1 = "O" And $v5 = "O" And $v9 = "O" Then
GUICtrlSetBkColor($a, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($i, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;C E G X
Elseif $v3 = "X" And $v5 = "X" And $v7 = "X" Then
GUICtrlSetBkColor($C, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($g, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;C E G O
Elseif $v3 = "O" And $v5 = "O" And $v7 = "O" Then
GUICtrlSetBkColor($C, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($g, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
ElseIf $statcheck = 111111111 Then
Sleep (500)
win()
MsgBox (0,"","Game over")
reset()
EndIf
WEnd
Func reset()
$status1 = ""
$status2 = ""
$status3 = ""
$status4 = ""
$status5 = ""
$status6 = ""
$status7 = ""
$status8 = ""
$status9 = ""
GUICtrlSetData ($a,"")
GUICtrlSetData ($b,"")
GUICtrlSetData ($c,"")
GUICtrlSetData ($d,"")
GUICtrlSetData ($e,"")
GUICtrlSetData ($f,"")
GUICtrlSetData ($g,"")
GUICtrlSetData ($h,"")
GUICtrlSetData ($i,"")
$v1 = ""
$v2 = ""
$v3 = ""
$v4 = ""
$v5 = ""
$v6 = ""
$v7 = ""
$v8 = ""
$v9 = ""
GUICtrlSetBkColor($a, 0xFFFBF0)
GUICtrlSetBkColor($b, 0xFFFBF0)
GUICtrlSetBkColor($c, 0xFFFBF0)
GUICtrlSetBkColor($d, 0xFFFBF0)
GUICtrlSetBkColor($e, 0xFFFBF0)
GUICtrlSetBkColor($f, 0xFFFBF0)
GUICtrlSetBkColor($g, 0xFFFBF0)
GUICtrlSetBkColor($h, 0xFFFBF0)
GUICtrlSetBkColor($i, 0xFFFBF0)
GUICtrlSetState ($a,$GUI_ENABLE)
GUICtrlSetState ($b,$GUI_ENABLE)
GUICtrlSetState ($c,$GUI_ENABLE)
GUICtrlSetState ($d,$GUI_ENABLE)
GUICtrlSetState ($e,$GUI_ENABLE)
GUICtrlSetState ($f,$GUI_ENABLE)
GUICtrlSetState ($g,$GUI_ENABLE)
GUICtrlSetState ($h,$GUI_ENABLE)
GUICtrlSetState ($i,$GUI_ENABLE)
EndFunc
Func score()
MsgBox (0,"Score","Player X = " & $valX & @CRLF & "Player O = " & $valO)
EndFunc
Func win()
SoundPlay (@TempDir & "\tictacsound.wav")
EndFunc
* = You must play it with another person , it's not bot vs human.