Advertisement
toan9xpro2012

Nút Di chuyển

Sep 16th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. Global $x = 0, $y = 98; Vị trí xuất phát của cái nút
  2. Global $w = 100, $n = 49;$w là tốc độ giữa hai lần nhấn (mili giây) cũng có thể nói là tốc độ di chuyển, $n là khoảng di chuyển
  3. Global $t, $d = "user32.dll" ;Cái vụ này thì soi cái hàm _IsPressed sẽ rõ
  4. Local $key, $dk
  5.  
  6. $F = GUICreate("", 245, 245, 192, 124)
  7. $B = GUICtrlCreateButton("Cái Nút", $x, $y, 49, 49)
  8. $Cnv = GUICtrlCreateButton("CN.Vật", 49, 49, 49, 49)
  9. GUISetState(@SW_SHOW)
  10.  
  11. Func _IsPressed($sHexKey, $vDLL = 'user32.dll') ;Cái này copy trong thư viện Misc.au3 cho nó nhẹ
  12. Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
  13. If @error Then Return SetError(@error, @extended, False)
  14. Return BitAND($a_R[0], 0x8000) <> 0
  15. EndFunc ;==>_IsPressed
  16.  
  17.  
  18. Func Gon($key, $dk) ;Cái này tao rút gọn thôi
  19. $time = @HOUR & ":" & @MIN & ":" & @SEC
  20. If _IsPressed($key, $d) Then
  21. GUICtrlDelete($B)
  22. Switch $dk
  23. Case 1
  24. If ($x = 98 And $y = 49) Then
  25. ConsoleWrite("Can't Left " & $time & @CR)
  26. Else
  27. If $x - $n >= 0 Then $x = $x - $n
  28. EndIf
  29. Case 2
  30. If ($x = 49 And $y = 98) Then
  31. ConsoleWrite("Can't Up " & $time & @CR)
  32. Else
  33. If $y - $n >= 0 Then $y = $y - $n
  34. EndIf
  35. Case 3
  36. If ($x = 0 And $y = 49) Then
  37. ConsoleWrite("Can't Right " & $time & @CR)
  38. Else
  39. If $x + $n <= 196 Then $x = $x + $n
  40. EndIf
  41. Case 4
  42. If ($x = 49 And $y = 0) Then
  43. ConsoleWrite("Can't Down " & $time & @CR)
  44. Else
  45. If $y + $n <= 196 Then $y = $y + $n
  46. EndIf
  47. EndSwitch
  48. $B = GUICtrlCreateButton("Cái Nút ", $x, $y, 49, 49)
  49. Sleep($w)
  50. DllClose($d)
  51. EndIf
  52.  
  53. EndFunc ;==>Gon
  54.  
  55. Func DonBaiChienTruong()
  56. DllClose($d) ;------------------------------------------------;
  57. GUIDelete($F) ;4 dòng này để dọn bãi chiến trường rồi quảng cáo;
  58. ToolTip("", 0, 0);-----------------------------------------------------------------------------------------------------;
  59. MsgBox(0, "", "Code bởi Ngọc Thụ Lâm Phong" & @CR & @CR & "Http://facebook.com/AnhVuongCoDon" & @CR & @CR & "Cảm ơn đã sử dụng ^^");
  60. Exit
  61. EndFunc ;==>DonBaiChienTruong
  62.  
  63. Func Move() ;Cho chạy hết 4 nút mũi tên, nếu nhấn nút nào thì chạy hướng nào
  64. Gon(25, 1)
  65. Gon(26, 2)
  66. Gon(27, 3)
  67. Gon(28, 4)
  68. EndFunc ;==>Move
  69.  
  70. While 1
  71. $GUI = GUIGetMsg()
  72. Move()
  73. If "Tọa cmn độ" & @CR & "x = " & $x & @CR & "y = " & $y <> $t Then ToolTip("Tọa cmn độ" & @CR & "x = " & $x & @CR & "y = " & $y, 0, 0)
  74. $t = "Tọa cmn độ" & @CR & "x = " & $x & @CR & "y = " & $y
  75.  
  76. If $GUI = -3 Then DonBaiChienTruong() ; nếu nhấn x thì dọn bãi ct rồi thoát
  77. If $GUI = $B Then MsgBox(0, "", "Vê lờ, cái nút thôi chớ có gì mà bấm")
  78. If _IsPressed("1B", $d) Then DonBaiChienTruong(); Nếu nhấn Esc thì cũng dọn bãi chiến trường và thoát
  79. WEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement