PunProgram Posted October 19, 2012 Share Posted October 19, 2012 (edited) expandcollapse popupHotKeySet("{Esc}","esc") Global $board[8][8] For $x=1 To 7 Step +1 for $y=1 To 6 Step + 1 $board[$x][$y]=0 Next Next Global $turn = 1 Global $a1 = 250 Global $a2 = 250 Global $a3 = 250 Global $a4 = 250 Global $a5 = 250 Global $a6 = 250 Global $a7 = 250 Global $play = 1 Global $color = 0xff0000 Func esc() Exit EndFunc #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Four Stars", 350, 350, -1,-1) $b1 = GUICtrlCreateButton("1",0,300,50,50) $b2 = GUICtrlCreateButton("2",50,300,50,50) $b3 = GUICtrlCreateButton("3",100,300,50,50) $b4 = GUICtrlCreateButton("4",150,300,50,50) $b5 = GUICtrlCreateButton("5",200,300,50,50) $b6 = GUICtrlCreateButton("6",250,300,50,50) $b7 = GUICtrlCreateButton("7",300,300,50,50) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 if mod($turn,2) = 0 Then $play = 2 $color=0x0000ff Else $play = 1 $color=0xff0000 EndIf if $a1 < 0 Then GUICtrlSetState($b1,$GUI_HIDE) EndIf if $a2 < 0 Then GUICtrlSetState($b2,$GUI_HIDE) EndIf if $a3 < 0 Then GUICtrlSetState($b3,$GUI_HIDE) EndIf if $a4 < 0 Then GUICtrlSetState($b4,$GUI_HIDE) EndIf if $a5 < 0 Then GUICtrlSetState($b5,$GUI_HIDE) EndIf if $a6 < 0 Then GUICtrlSetState($b6,$GUI_HIDE) EndIf if $a7 < 0 Then GUICtrlSetState($b7,$GUI_HIDE) EndIf $m = GUIGetMsg() Switch $m Case $GUI_EVENT_CLOSE Exit Case $b1 GUICtrlCreateButton($play,0,$a1,50,50) GUICtrlSetBkColor(-1,$color) $turn = $turn + 1 $yi= $a1/50+1 $board[1][$yi]=$play $a1 = $a1 - 50 check() Case $b2 GUICtrlCreateButton($play,50,$a2,50,50) GUICtrlSetBkColor(-1,$color) $turn = $turn + 1 $yi= $a2/50+1 $board[2][$yi]=$play $a2 = $a2 - 50 check() Case $b3 GUICtrlCreateButton($play,100,$a3,50,50) GUICtrlSetBkColor(-1,$color) $turn = $turn + 1 $yi= $a3/50+1 $board[3][$yi]=$play $a3 = $a3 - 50 check() Case $b4 GUICtrlCreateButton($play,150,$a4,50,50) GUICtrlSetBkColor(-1,$color) $turn = $turn + 1 $yi= $a4/50+1 $board[4][$yi]=$play $a4 = $a4 - 50 check() Case $b5 GUICtrlCreateButton($play,200,$a5,50,50) GUICtrlSetBkColor(-1,$color) $turn = $turn + 1 $yi= $a5/50+1 $board[5][$yi]=$play $a5 = $a5 - 50 check() Case $b6 GUICtrlCreateButton($play,250,$a6,50,50) GUICtrlSetBkColor(-1,$color) $turn = $turn + 1 $yi= $a6/50+1 $board[6][$yi]=$play $a6 = $a6 - 50 check() Case $b7 GUICtrlCreateButton($play,300,$a7,50,50) GUICtrlSetBkColor(-1,$color) $turn = $turn + 1 $yi= $a7/50+1 $board[7][$yi]=$play $a7 = $a7 - 50 check() EndSwitch WEnd Func check() For $t=1 to 2 Step +1 For $x=1 to 4 step +1 For $y = 6 to 4 step -1 if $board[$x][$y]=$t And $board[$x+1][$y-1]=$t And $board[$x+2][$y-2]=$t And $board[$x+3][$y-3]=$t Then MsgBox(0,"The winner is","Player" & $t) Exit EndIf Next Next For $x=1 To 4 Step +1 for $y=1 To 6 Step + 1 if $board[$x][$y]=$t And $board[$x][$y+1]=$t And $board[$x][$y+2]=$t And $board[$x][$y+3]=$t Then MsgBox(0,"The winner is","Player" & $t) Exit EndIf if $board[$x][$y]=$t And $board[$x+1][$y]=$t And $board[$x+2][$y]=$t And $board[$x+3][$y]=$t Then MsgBox(0,"The winner is","Player" & $t) Exit EndIf if $board[$x][$y]=$t And $board[$x+1][$y+1]=$t And $board[$x+2][$y+2]=$t And $board[$x+3][$y+3]=$t Then MsgBox(0,"The winner is","Player" & $t) Exit EndIf Next Next Next EndFunc Edited October 19, 2012 by Melba23 Added code tags Chance 1 Link to comment Share on other sites More sharing options...
JohnOne Posted October 19, 2012 Share Posted October 19, 2012 hehe. Nice, I just won myself too. FireFox 1 AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Chance Posted October 19, 2012 Share Posted October 19, 2012 lol, why didn't anyone thought of this before Link to comment Share on other sites More sharing options...
JohnOne Posted October 19, 2012 Share Posted October 19, 2012 They have, I've seen it before. Doesn't mean someone else cannot think of it too though AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted October 19, 2012 Share Posted October 19, 2012 Perhaps you should indicate which player is to go next. AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
PunProgram Posted October 20, 2012 Author Share Posted October 20, 2012 hehe. Nice, I just won myself too.Thank for comments. I am a new Autoit programmer from Thailand (Just only 15). I learn autoit by just reading Help. I don't know much about this Autoit Social Network. Link to comment Share on other sites More sharing options...
E1M1 Posted October 20, 2012 Share Posted October 20, 2012 Very nice. PunProgram 1 edited Link to comment Share on other sites More sharing options...
jaberwacky Posted October 21, 2012 Share Posted October 21, 2012 Now all I gotta do is learn to play Connect4. PunProgram 1 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now