Untitled


SUBMITTED BY: Guest

DATE: May 31, 2015, 3:03 a.m.

FORMAT: Text only

SIZE: 9.6 kB

HITS: 993

  1. #include-once
  2. #include <array.au3>
  3. #include <Misc.au3>
  4. Global $CellW = 35 ;Chiều rộng ô
  5. Global $CellH = 35 ;Chiều dài ô
  6. Global $Map[24][30] ;Vị trí mìn
  7. Global $Stats[24][30] ;Các ô
  8. Global $Stats2[24][30] ;Trạng thái các ô
  9. Global $MWidth = 9 ;Bản đồ
  10. Global $MHeight = 9 ;Bản đồ
  11. Global $MMines = 10 ;Số mìn
  12. Global $UMines = 10 ;Số mìn còn lại
  13. Global $Playing = False ;Trạng thái game
  14. Global $First_click = False ;cái này cho bộ đếm thời gian
  15. Global $Count_time = 0 ;Biến đếm thời gian
  16. Global $DMoveX[9] = [-1,0,1,1,1,0,-1,-1,0] ;các hướng di chuyển
  17. Global $DMovey[9] = [-1,-1,-1,0,1,1,1,0,0] ;các hướng di chuyển
  18. ;// Tạo GUI
  19. $hGUI = GUICreate('AutMinesweeper',335,385)
  20. GUISetFont(9,default,default,'Arial',default,100)
  21. $FMenu = GUICtrlCreateMenu('Game')
  22. $NGame = GUICtrlCreateMenuItem('New Game',$Fmenu)
  23. GUICtrlCreateMenuItem('',$Fmenu)
  24. $SGame = GUICtrlCreateMenuItem('Statistics',$Fmenu)
  25. $OGame = GUICtrlCreateMenuItem('Options',$Fmenu)
  26. GUICtrlCreateMenuItem('',$Fmenu)
  27. $EGame = GUICtrlCreateMenuItem('Exit',$Fmenu)
  28. $HMenu = GUICtrlCreateMenu('Help')
  29. $VHelp = GUICtrlCreateMenuItem('View Help F1',$Hmenu)
  30. GUICtrlCreateMenuItem('',$Hmenu)
  31. $AHelp = GUICtrlCreateMenuItem('About AutMinesweeper',$Hmenu)
  32. GUICtrlCreateMenuItem('',$Hmenu)
  33. $GHelp = GUICtrlCreateMenuItem('Get more AutGame!',$Hmenu)
  34. ;////////////////////////////////////////////////////////////
  35. GUICtrlCreateLabel('Õ',50,325,40,40)
  36. GUICtrlSetFont(-1,40,400,Default,'Webdings')
  37. GUICtrlCreateLabel('Õ',232.5,325,40,40)
  38. GUICtrlSetFont(-1,40,400,Default,'Webdings')
  39. GUICtrlCreateLabel('l',75,335,40,40)
  40. GUICtrlSetFont(-1,11,500)
  41. GUICtrlSetBkColor(-1,-2)
  42. GUICtrlCreateLabel('!',252,337,40,40)
  43. GUICtrlSetFont(-1,10,500,Default,'Webdings')
  44. GUICtrlSetBkColor(-1,-2)
  45. GUICtrlCreateLabel('\',76,344,40,40)
  46. GUICtrlSetFont(-1,8,400)
  47. GUICtrlSetBkColor(-1,-2)
  48. GUICtrlCreateButton('',5,5,324,324)
  49. GUICtrlSetBkColor(-1,0xd0d0d0)
  50. GUICtrlSetState(-1,128)
  51. GUICtrlCreateLabel('',95,337.5,50,20,0x100b)
  52. GUICtrlCreateLabel('',190,337.5,50,20,0x100b)
  53. ;////////////////////////////////////////////////////////////
  54. $Timer_Show = GUICtrlCreateLabel(0,96,338.5,48,18,0x201)
  55. $Mine_Show = GUICtrlCreateLabel($UMines,191,338.5,48,18,0x201)
  56. For $i = 0 to $MWidth-1
  57. For $u = 0 to $MHeight-1
  58. GUICtrlCreateLabel('',10+$CellW*$i,10+$CellH*$u,$CellW-1,$CellH-1,0x100B)
  59. GUICtrlSetState(-1,128)
  60. $Stats[$i][$u] = GUICtrlCreateLabel('',12+$CellW*$i,12+$CellH*$u,$CellW-5,$CellH-5,0x0201)
  61. GUICtrlSetFont(-1,18,800)
  62. GUICtrlSetBkColor(-1,0xa0a0ff)
  63. Next
  64. Next
  65. newgame()
  66. GUISetState()
  67. While True
  68. $msg = GUIGetMsg()
  69. Switch $msg
  70. case -3
  71. Exit
  72. case $EGame
  73. Exit
  74. case $Ngame
  75. newgame()
  76. case $SGame
  77. MsgBox(4096,'AutMinesweeper','Not available now!',0,$hGUI)
  78. case $OGame
  79. MsgBox(4096,'AutMinesweeper','Not available now!',0,$hGUI)
  80. case $VHelp
  81. MsgBox(4096,'AutMinesweeper','Not available now!',0,$hGUI)
  82. case $AHelp
  83. MsgBox(4096,'AutMinesweeper','Not available now!',0,$hGUI)
  84. case $GHelp
  85. ShellExecute('http://hocautoit.com/')
  86. EndSwitch
  87. WEnd
  88. Func newgame()
  89. AdlibUnRegister('timer')
  90. AdlibUnRegister('event')
  91. Dim $Map[24][30]
  92. Dim $Stats2[24][30]
  93. For $i = 0 to $MWidth-1
  94. For $u = 0 to $MHeight-1
  95. GUICtrlSetData($Stats[$i][$u],'')
  96. GUICtrlSetFont($Stats[$i][$u],18,800)
  97. GUICtrlSetColor($Stats[$i][$u],0x)
  98. GUICtrlSetBkColor($Stats[$i][$u],0xa0a0ff)
  99. $Stats2[$i][$u] = 1
  100. Next
  101. Next
  102. Dim $UMines = $MMines
  103. Dim $Playing = True
  104. Dim $First_click = False
  105. addmines()
  106. AdlibRegister('event',100)
  107. EndFunc
  108. Func event()
  109. If WinActive($hGUI) == 0 then return False
  110. Local $MPo = GUIGetCursorInfo($hGUI)
  111. If @error Then Return False
  112. For $i = 0 to $MWidth-1
  113. For $u = 0 To $MHeight-1
  114. If $MPo[4] == $Stats[$i][$u] Then
  115. If $Playing == True Then
  116. If _IsPressed(01) And _IsPressed(02) Then
  117. Updown($i,$u,0)
  118. While _IsPressed(01) And _IsPressed(02)
  119. Sleep(10)
  120. WEnd
  121. Updown($i,$u,1)
  122. QuestionMarks($i,$u)
  123. ElseIf _IsPressed(02) Then
  124. FlagCell($i,$u)
  125. While _IsPressed(02)
  126. Sleep(10)
  127. WEnd
  128. ElseIf _IsPressed(01) Then
  129. If $First_click == False Then
  130. $First_click = True
  131. $Count_time = TimerInit()
  132. AdlibRegister('timer',100)
  133. EndIf
  134. $Res = open($i,$u,1)
  135. If $Res == 'Bom' Then
  136. Boooom()
  137. $Playing = False
  138. AdlibUnRegister('timer')
  139. MsgBox(4096,'AutMinesweeper','Game over',0,$hGUI)
  140. EndIf
  141. While _IsPressed(01)
  142. Sleep(10)
  143. WEnd
  144. EndIf
  145. EndIf
  146. EndIf
  147. Next
  148. Next
  149. If checkwin() == True Then
  150. $Playing = False
  151. AdlibUnRegister('timer')
  152. AdlibUnRegister('event')
  153. MsgBox(4096,'AutMinesweeper','Win',0,$hGUI)
  154. EndIf
  155. EndFunc
  156. Func color($snum)
  157. Switch $snum
  158. case 1
  159. Return 0x0100FE
  160. case 2
  161. return 0x017F01
  162. case 3
  163. return 0xFE0000
  164. case 4
  165. Return 0x010080
  166. case 5
  167. return 0x810102
  168. case 6
  169. Return 0x008081
  170. case 7
  171. return 0x000000
  172. case 8
  173. return 0x808080
  174. EndSwitch
  175. return 0xabcdef
  176. EndFunc
  177. Func timer()
  178. Local $GetTime = Floor(TimerDiff($Count_time)/1000)
  179. If GUICtrlRead($timer_show) <> $GetTime then GUICtrlSetData($timer_show,$Gettime)
  180. EndFunc
  181. Func Updown($r,$c,$type)
  182. For $n = 0 to 8
  183. If maps($r+$DMoveX[$n],$c+$DMovey[$n]) == True Then
  184. If $stats2[$r+$DMoveX[$n]][$c+$DMovey[$n]] == 1 Then
  185. If $type = 1 Then
  186. GUICtrlSetBkColor($stats[$r+$DMoveX[$n]][$c+$DMovey[$n]],0xa0a0ff)
  187. Else
  188. GUICtrlSetBkColor($stats[$r+$DMoveX[$n]][$c+$DMovey[$n]],0xd0d0d0)
  189. EndIf
  190. EndIf
  191. EndIf
  192. Next
  193. EndFunc
  194. Func QuestionMarks($r,$c)
  195. If $Stats2[$r][$c] == 1 or $Stats2[$r][$c] == 3 Then Return False
  196. If Maps($r,$c) == False Then Return False
  197. Local $Num = 0
  198. For $n = 0 to 7
  199. If maps($r+$DMoveX[$n],$c+$DMovey[$n]) == True Then
  200. If $map[$r+$DMoveX[$n]][$c+$DMovey[$n]] == 1 And $Stats2 [$r+$DMoveX[$n]][$c+$DMovey[$n]] == 1 Then
  201. $Num += 1
  202. EndIf
  203. EndIf
  204. Next
  205. If $Num == 0 Then
  206. For $n = 0 to 7
  207. If maps($r+$DMoveX[$n],$c+$DMovey[$n]) == True Then
  208. If $Stats2[$r+$DMoveX[$n]][$c+$DMovey[$n]] == 1 Then
  209. Open($r+$DMoveX[$n],$c+$DMovey[$n],1)
  210. EndIf
  211. EndIf
  212. Next
  213. EndIf
  214. EndFunc
  215. Func countMines($r,$c)
  216. Local $Num = 0
  217. For $n = 0 to 7
  218. If maps($r+$DMoveX[$n],$c+$DMovey[$n]) == True Then
  219. If $map[$r+$DMoveX[$n]][$c+$DMovey[$n]] == 1 Then
  220. $Num += 1
  221. EndIf
  222. EndIf
  223. Next
  224. Return $Num
  225. EndFunc
  226. Func FlagCell($r,$c)
  227. If $Stats2[$r][$c] == 2 Then Return False
  228. If $Stats2[$r][$c] == 1 Then
  229. $Stats2[$r][$c] = 3
  230. $UMines -= 1
  231. GUICtrlSetData($Stats[$r][$c],'w')
  232. GUICtrlSetColor($Stats[$r][$c],0xff0000)
  233. GUICtrlSetFont($Stats[$r][$c],25,800,Default,'Webdings')
  234. ElseIf $Stats2[$r][$c] == 3 Then
  235. $Stats2[$r][$c] = 1
  236. $UMines += 1
  237. GUICtrlSetData($Stats[$r][$c],'')
  238. GUICtrlSetColor($Stats[$r][$c],0x)
  239. GUICtrlSetFont($Stats[$r][$c],18,800,Default,'Arial')
  240. EndIf
  241. GUICtrlSetData($Mine_show,$UMines)
  242. Return True
  243. EndFunc
  244. Func open($r,$c,$type)
  245. If $Stats2[$r][$c] == 2 or $Stats2[$r][$c] == 3 Then Return False
  246. If Maps($r,$c) == False Then Return False
  247. If $map[$r][$c] == 1 Then
  248. If $type == 1 Then Return 'Bom'
  249. Return False
  250. EndIf
  251. Local $Cnt = countMines($r,$c)
  252. $Stats2[$r][$c] = 2
  253. GUICtrlSetBkColor($Stats[$r][$c],0xd0d0d0)
  254. If $Cnt > 0 Then
  255. GUICtrlSetData($Stats[$r][$c],$Cnt)
  256. GUICtrlSetColor($Stats[$r][$c],color($Cnt))
  257. Else
  258. For $n = 0 to 7
  259. $rX = $r+$DMoveX[$n]
  260. $cY = $c+$DMoveY[$n]
  261. If Maps($rX,$cY) == True Then
  262. open($rX,$cY,0)
  263. EndIf
  264. Next
  265. EndIf
  266. Return False
  267. EndFunc
  268. Func Maps($r,$c)
  269. If $r > -1 and $r < $MWidth and $c > -1 and $c < $MHeight Then Return True
  270. Return False
  271. EndFunc
  272. Func Boooom()
  273. for $i = 0 to $MWidth-1
  274. for $u = 0 to $MHeight-1
  275. If $Map[$i][$u] == 1 Then
  276. GUICtrlSetData($Stats[$i][$u],'!')
  277. GUICtrlSetFont($Stats[$i][$u],20,600,Default,'Webdings')
  278. GUICtrlSetBkColor($Stats[$i][$u],0xd0d0d0)
  279. EndIf
  280. Next
  281. Next
  282. EndFunc
  283. Func checkwin()
  284. Local $MaxCellAvai = $MWidth*$MHeight-$MMines
  285. Local $Opened = 0
  286. For $i = 0 to $MWidth-1
  287. For $u = 0 to $MHeight-1
  288. If $Stats2[$i][$u] == 2 then $Opened += 1
  289. Next
  290. Next
  291. If $Opened == $MaxCellAvai then Return True
  292. Return False
  293. EndFunc
  294. Func addmines()
  295. For $i = 1 to $MMines
  296. Do
  297. Local $mmr_ = Random(0,$MWidth-1,1)
  298. Local $mmr__ = Random(0,$MHeight-1,1)
  299. If $Map[$mmr_][$mmr__] == '' Then
  300. $Map[$mmr_][$mmr__] = 1
  301. ExitLoop
  302. EndIf
  303. Until True == False
  304. Next
  305. EndFunc

comments powered by Disqus