Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. Hi Argumentum No, I didn't forget to add GUISetState() By design, the script is not supposed to show the window on startup. The window is supposed to show only after starting again the exe. The application will be started automatically at Windows startup and will be hidden. The application is an address book. The application is to have an option to be invoked (show main window) in three ways: 1. keyboard shortcut 3. clicking on the systray icon 4. running a shortcut on the desktop Yes, at first I thought that Nine's solution would be ok but unfortunately not in the case when we do not want to show the window at the start of the script.
  3. All, sorry for the long delay, work took over. The script is: #include <WinAPIShellEx.au3> Local $PhotosPath = @UserProfileDir & "\Pictures\iCloud Photos\Photos\" Local $PhotosPathBackup = @UserProfileDir & "\Pictures\iCloudPhotosBackUp\" If not FileExists($PhotosPathBackup) Then DirCreate($PhotosPathBackup) ShellExecute($PhotosPath) Sleep(500) If @UserName = "Raziel" Then Send("^e") Else Send("^a") EndIf Sleep(500) Send("{LSHIFT}+{F10}") Sleep(200) Send("{DOWN 14}") Sleep(100) Send("{ENTER}") Sleep(30000) ;one second just for testing change to (1000*60*30) for wait 30 minutes ;some bug here it seems to be always overwrite file ;~ _WinAPI_ShellFileOperation( $PhotosPath & "*.*", $PhotosPathBackup, $FO_COPY,BitOR( $FOF_NOCONFIRMMKDIR, $FOF_NOCONFIRMATION , $FOF_NOERRORUI, $FOF_NO_UI)) Local $hSearch = FileFindFirstFile($PhotosPath & "*.*") While 1 $sFileName = FileFindNextFile($hSearch) If @error Then ExitLoop If not FileExists($PhotosPathBackup & $sFileName) Then FileCopy($PhotosPath & $sFileName, $PhotosPathBackup) WEnd FileClose($hSearch) MsgBox(0,"Information","Process Finsihed" & @CRLF & "Script will be closed in 5 Seconds...",5) This works in principle, but - for whatever reason, not all photos are downloaded, and clicking the menu item "keep on computer" toggles the command, so every other time it un-sets what I want to achieve. But it's the closest I have. Thanks to @Danyfirex
  4. Today
  5. 'cause you forgot to add GUISetState() ; display the GUI No big deal #include <GUIConstantsEx.au3> #include <Misc.au3> If Not _Singleton("MyGui", 1) Then WinSetState("gui V1.1.1", "", @SW_SHOW) WinActivate("gui V1.1.1") ; easier to see when you "click click" the script Exit 5 EndIf $gui = GUICreate("gui V1.1.1",445,262,-1,-1,-1,-1) $button = GUICtrlCreateButton("Button",60,20,100,30,-1,-1) $bHide = GUICtrlCreateButton("Hide",60,60,100,30,-1,-1) $label = GUICtrlCreateLabel("My Text",80,100,50,15,-1,-1) GUISetState() ; display the GUI $counter = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete() ; this should be here too Exit case $button $counter +=1 guictrlsetdata($label, $counter) case $bHide WinSetState($gui, "", @SW_HIDE) EndSwitch WEnd Edit: ..read the whole post and still believe that this code should have no problem. Edit 2: I see that you marked yourself as solving the problem. Genieal ?
  6. Thank you for your reply. I'm just not sure we understand each other. Use the code below and see if the button works for you after you run the exe a second time. The conditions that must be met are that the window after the startup must be hidden. The window is to appear only after the second launch of the exe. #include <GUIConstantsEx.au3> #include <Misc.au3> If Not _Singleton("MyGui", 1) Then Exit WinSetState("gui V1.1.1", "", @SW_SHOW) $gui = GUICreate("gui V1.1.1",445,262,-1,-1,-1,-1) $button = GUICtrlCreateButton("Button",60,20,100,30,-1,-1) $bHide = GUICtrlCreateButton("Hide",60,60,100,30,-1,-1) $label = GUICtrlCreateLabel("My Text",80,100,50,15,-1,-1) $counter = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $button $counter +=1 guictrlsetdata($label, $counter) case $bHide WinSetState($gui, "", @SW_HIDE) EndSwitch WEnd
  7. EDIT : I've added a pause feature for the snake. You can now press the S key to put the game on hold and take a coffee break.
  8. I've come up with a simplified version of the code where I've addressed the issue of the snake's self-collision. Additionally, you have the freedom to choose the color of the snake. This showcases the versatility of the tool I'm using. #include-once #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #INDEX# ======================================================================================================================= ; Title .........: Snake Game ; AutoIt Version : 3.3 ; AutoItObject Version : v1.2.8.2 ; Language ......: English ; Description ...: A simple Snake game implementation using AutoIt->AutoItObject.au3. ; Dependencies ..: AutoItObject.au3 ; Author ........: Numeric ; =============================================================================================================================== #include <GUIConstantsEx.au3> #include "AutoItObject.au3" #include <GDIPlus.au3> #include <Misc.au3> Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") _GDIPlus_Startup() _AutoItObject_Startup() Func Snake($iBgColor = 0xFF0000FF) Local $dx = Random(-1, 1, 1) Local $dy = Random(-1, 1, 1) Local $aMap[] MapAppend($aMap, Point(Random(10, 380, 1), Random(10, 380, 1))) ;food MapAppend($aMap, Point(Random(10, 380, 1), Random(10, 380, 1))) ; head Local $Board = GUICreate("Snake", 400, 400) GUISetState() Local $aBoardPos = WinGetClientSize($Board) Local $iBoardWidth = $aBoardPos[0] Local $iBoardHeight = $aBoardPos[1] Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($Board) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iBoardWidth, $iBoardHeight, $hGraphics) Local $hGraphicsCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphicsCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Local $hBrush = _GDIPlus_BrushCreateSolid($iBgColor) Local $hFoodBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00) ;(0x00FF00) Local $aGDIMap[] $aGDIMap["hGraphics"] = $hGraphics $aGDIMap["hBitmap"] = $hBitmap $aGDIMap["hGraphicsCtxt"] = $hGraphicsCtxt $aGDIMap["hBrush"] = $hBrush $aGDIMap["hFoodBrush"] = $hFoodBrush Local $sClass = _AutoItObject_Class() With $sClass .Create() .AddProperty("dx", $ELSCOPE_PUBLIC, $dx) .AddProperty("dy", $ELSCOPE_PUBLIC, $dy) .AddProperty("speedLevel", $ELSCOPE_PUBLIC, 100) .AddProperty("foodCounter", $ELSCOPE_PUBLIC, 0) .AddProperty("Map", $ELSCOPE_PUBLIC, $aMap) .AddProperty("gdiMap", $ELSCOPE_PUBLIC, $aGDIMap) .AddProperty("Board", $ELSCOPE_PUBLIC, $Board) .AddProperty("iBoardWidth", $ELSCOPE_PUBLIC, $iBoardWidth) .AddProperty("iBoardHeight", $ELSCOPE_PUBLIC, $iBoardHeight) .AddMethod("move", "_move") .AddMethod("drawStage", "_drawStage") .AddMethod("resetGame", "_resetGame") .AddMethod("runGameLoop", "_runGameLoop") .AddMethod("cleanUpResources", "_cleanUpResources") .AddDestructor("_cleanUpResources") EndWith Return $sClass.Object EndFunc ;==>Snake Func _runGameLoop($this) While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop If _IsPressed(25) Then $this.dx = -1 $this.dy = 0 EndIf If _IsPressed(27) Then $this.dx = 1 $this.dy = 0 EndIf If _IsPressed(26) Then $this.dx = 0 $this.dy = -1 EndIf If _IsPressed(28) Then $this.dx = 0 $this.dy = 1 EndIf If _IsPressed(53) Then While 1 If _IsPressed(25) Or _IsPressed(26) Or _IsPressed(27) Or _IsPressed(28) Then ExitLoop Sleep(100) WEnd EndIf $this.drawStage() Sleep($this.speedLevel) WEnd EndFunc ;==>_runGameLoop Func _move($this) Local $aMap = $this.Map Local $head = $aMap[1] Local $newX = $head.getXPos() + $this.dx * 10 Local $newY = $head.getYPos() + $this.dy * 10 Local $hW = $newX + 10 Local $hH = $newY + 10 If $newX <= 0 Or $newX >= 390 Or $newY <= 0 Or $newY >= 390 Then MsgBox(64, "Game Over", "Collision! Game Over.") Local $iResponse = MsgBox(36, "Restart Game", "Do you want to restart the game?") If $iResponse = 6 Then $this.resetGame() Return True Else $this.cleanUpResources() _GDIPlus_Shutdown() _AutoItObject_Shutdown() Exit EndIf EndIf For $i = 2 To UBound($aMap) - 1 Local $cX = $aMap[$i].getXPos() Local $cY = $aMap[$i].getYPos() Local $cW = $cX + 10 Local $cH = $cY + 10 If $newX < $cW And $hW > $cX And $newY < $cH And $hH > $cY Then MsgBox(64, "Game Over", " SELF!!! Collision! Game Over.") $iResponse = MsgBox(36, "Restart Game", "Do you want to restart the game?") If $iResponse = 6 Then $this.resetGame() Return True Else $this.cleanUpResources() _GDIPlus_Shutdown() _AutoItObject_Shutdown() Exit EndIf EndIf Next Local $food = $aMap[0] Local $fX = $food.getXPos() Local $fY = $food.getYPos() Local $fW = $fX + 10 Local $fH = $fY + 10 If $newX < $fW And $hW > $fX And $newY < $fH And $hH > $fY Then ;generate food $aMap[0].setXPos(Random(10, 390, 1)) $aMap[0].setYPos(Random(10, 390, 1)) Local $lastSegment = $aMap[UBound($aMap) - 1] Local $lastX = $lastSegment.getXPos() + $this.dx() * 10 Local $lastY = $lastSegment.getYPos() + $this.dy() * 10 MapAppend($aMap, Point($lastX, $lastY)) $this.Map = $aMap $this.foodCounter += 1 If $this.foodCounter = 4 Then $this.speedLevel -= 20 If $this.speedLevel < 0 Then $this.speedLevel = 1 EndIf $this.foodCounter = 0 EndIf EndIf $head.setXPos($newX) $head.setYPos($newY) For $i = UBound($aMap) - 1 To 2 Step -1 $aMap[$i].setXPos($aMap[$i - 1].getXPos()) $aMap[$i].setYPos($aMap[$i - 1].getYPos()) Next EndFunc ;==>_move Func _drawStage($this) Local $gdiMap = $this.gdiMap Local $aMap = $this.Map Local $hGraphics = $gdiMap["hGraphics"] Local $hBrush = $gdiMap["hBrush"] Local $hFoodBrush = $gdiMap["hFoodBrush"] $this.move() _GDIPlus_GraphicsClear($hGraphics, 0xFF000000) _GDIPlus_GraphicsFillRect($hGraphics, $aMap[0].getXPos(), $aMap[0].getYPos(), 10, 10, $hFoodBrush) For $i = 1 To UBound($aMap) - 1 _GDIPlus_GraphicsFillRect($hGraphics, $aMap[$i].getXPos(), $aMap[$i].getYPos(), 10, 10, $hBrush) Next EndFunc ;==>_drawStage Func _resetGame($this) For $item In $this.Map $item = 0 Next $this.Map = 0 Local $aNewMap[] MapAppend($aNewMap, Point(Random(10, $this.iBoardWidth - 10), Random(10, $this.iBoardHeight - 10))) MapAppend($aNewMap, Point(Random(10, $this.iBoardWidth - 10), Random(10, $this.iBoardHeight - 10))) $this.Map = $aNewMap $this.dx = Random(-1, 1, 1) $this.dy = Random(-1, 1, 1) $this.speedLevel = 100 $this.foodCounter = 0 $this.drawStage() EndFunc ;==>_resetGame Func _cleanUpResources($this) Local $gdiMap = $this.gdiMap Local $hGraphics = $gdiMap["hGraphics"] Local $hBrush = $gdiMap["hBrush"] Local $hFoodBrush = $gdiMap["hFoodBrush"] _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hFoodBrush) _GDIPlus_Shutdown() For $gdih In $gdiMap $gdih = 0 Next $this.gdiMap = 0 For $oPoint In $this.Map $oPoint = 0 Next $this.Map = 0 _AutoItObject_Shutdown() EndFunc ;==>_cleanUpResources Func Point($X = 0, $Y = 0) Local $cPoint = _AutoItObject_Class() With $cPoint .Create() .AddProperty("X", $ELSCOPE_PRIVATE, $X) .AddProperty("Y", $ELSCOPE_PRIVATE, $Y) .AddMethod("setXPos", "_setXPos") .AddMethod("setYPos", "_setYPos") .AddMethod("getXPos", "_getXPos") .AddMethod("getYPos", "_getYPos") EndWith Return $cPoint.Object EndFunc ;==>Point Func _setXPos($this, $iX) $this.X = $iX EndFunc ;==>_setXPos Func _setYPos($this, $iY) $this.Y = $iY EndFunc ;==>_setYPos Func _getXPos($this) Return $this.X EndFunc ;==>_getXPos Func _getYPos($this) Return $this.Y EndFunc ;==>_getYPos Func _ErrFunc($oError) ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc ;***************************************************************************************************************************************** Global $sNake = Snake(0xFF8B4513) $sNake.runGameLoop() $sNake = 0 ;***************************************************************************************************************************************** _AutoItObject_Shutdown()
  9. Yesterday
  10. Congrats, it works way better. The double buffering fixed the flickers and border collisions works now but self collision still doesn't work. Look what snake I managed to create.
  11. Thank you very much, Andreik, for your constructive feedback. Indeed, the adoption of GDI+ has significantly improved the fluidity of the snake's movements in its eternal quest for food. This major change was accomplished in record time (including a 5-minute coffee break) thanks to the flexibility of the object-oriented paradigm offered by the AutoItObject.au3 UDF. With this tool, you can literally build an empire, brick by brick. Now, you have the freedom to adjust the snake's speed, change its color on the fly, even during gameplay, and even generate fake prey of different colors to try to trap "Kaa," Mowgli's old companion. In other words, you can unleash your imagination and push the boundaries of what's possible. #include-once #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #INDEX# ======================================================================================================================= ; Title .........: Snake Game ; AutoIt Version : 3.3 ; AutoItObject Version : v1.2.8.2 ; Language ......: English ; Description ...: A simple Snake game implementation using AutoIt->AutoItObject.au3. ; Dependencies ..: AutoItObject.au3 ; Author ........: Numeric ; =============================================================================================================================== #include <GUIConstantsEx.au3> #include "AutoItObject.au3" #include <Misc.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPIGdi.au3> Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") _GDIPlus_Startup() _AutoItObject_Startup() Func Snake($oPoint = 0, $Board = Default, $iBgColor = 0xFF0000FF) Local $aRandomDirectionTab = [-1, 0, 1] Local $dx = $aRandomDirectionTab[Int(Random(0, 2, 1))] Local $dy = $aRandomDirectionTab[Int(Random(0, 2, 1))] Local $iLowSpeed = 100 Local $foodCounter = 0 If $Board = Default Then $Board = GUICreate("Snake", 400, 400) GUISetBkColor(0x303030) GUISetState() Local $aBoardPos = WinGetClientSize($Board) If @error Then Return SetError(1, 0, False) ; window not found Local $iBoardWidth = $aBoardPos[0] Local $iBoardHeight = $aBoardPos[1] Local $X = Random(10, $iBoardWidth - 10, 1) Local $Y = Random(10, $iBoardHeight - 10, 1) Local $aMap[] Local $oFood = Point(Random(10, $iBoardWidth - 10), Random(10, $iBoardHeight - 10)) MapAppend($aMap, $oFood) If $oPoint = 0 Then $oPoint = Point($X, $Y) MapAppend($aMap, $oPoint) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($Board) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iBoardWidth, $iBoardHeight, $hGraphics) Local $hGraphicsCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphicsCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Local $hBrush = _GDIPlus_BrushCreateSolid($iBgColor) Local $hFoodBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00) ;(0x00FF00) Local $sClass = _AutoItObject_Class() With $sClass .Create() .AddProperty("hGraphics", $ELSCOPE_PRIVATE, $hGraphics) .AddProperty("hBitmap", $ELSCOPE_PRIVATE, $hBitmap) .AddProperty("hGraphicsCtxt", $ELSCOPE_PRIVATE, $hGraphicsCtxt) .AddProperty("hBrush", $ELSCOPE_PRIVATE, $hBrush) .AddProperty("iColor", $ELSCOPE_PRIVATE, 0xFF8080FF) .AddProperty("hFoodBrush", $ELSCOPE_PRIVATE, $hFoodBrush) .AddProperty("head", $ELSCOPE_PRIVATE, $oPoint) .AddProperty("aMap", $ELSCOPE_PRIVATE, $aMap) .AddProperty("food", $ELSCOPE_PRIVATE, $oFood) .AddProperty("foodCounter", $ELSCOPE_PRIVATE, $foodCounter) .AddProperty("dx", $ELSCOPE_PRIVATE, $dx) .AddProperty("dy", $ELSCOPE_PRIVATE, $dy) .AddProperty("Board", $ELSCOPE_PRIVATE, $Board) .AddProperty("speedLevel", $ELSCOPE_PRIVATE, $iLowSpeed) .AddProperty("iBoardWidth", $ELSCOPE_PRIVATE, $iBoardWidth) .AddProperty("iBoardHeight", $ELSCOPE_PRIVATE, $iBoardHeight) .AddMethod("getBoard", "_getBoard") .AddMethod("setSpeedLevel", "_setSpeedLevel") .AddMethod("getSpeedLevel", "_getSpeedLevel") .AddMethod("runGameLoop", "_runGameLoop") .AddMethod("getFoodBrush", "_getFoodBrush") .AddMethod("setdx", "_setdx") .AddMethod("setdy", "_setdy") .AddMethod("getdx", "_getdx") .AddMethod("getdy", "_getdy") .AddMethod("sleepW", "_sleepW") .AddMethod("getMap", "_getMap") .AddMethod("setMap", "_setMap") .AddMethod("getHead", "_getHead") .AddMethod("getBoardHeight", "_getBoardHeight") .AddMethod("getBoardWidth", "_getBoardWidth") .AddMethod("getFoodCounter", "_getFoodCounter") .AddMethod("setFoodCounter", "_setFoodCounter", True) .AddMethod("move", "_move", True) .AddMethod("generateFood", "_generateFood") .AddMethod("setFood", "_setFood") .AddMethod("getFood", "_getFood") .AddMethod("getSColor", "_getSColor") .AddMethod("setSColor", "_setSColor") .AddMethod("getGraphics", "_getGraphics") .AddMethod("getBitmap", "_getBitmap") .AddMethod("getGraphicsCtxt", "_getGraphicsCtxt") .AddMethod("getBrush", "_getBrush") .AddMethod("drawStage", "_drawStage") .AddMethod("checkBorderCollision", "_checkBorderCollision") .AddMethod("checkSelfCollision", "_checkSelfCollision") .AddMethod("checkFoodCollision", "_checkFoodCollision") .AddMethod("resetGame", "_resetGame") .AddMethod("cleanUpResources", "_cleanUpResources") .AddDestructor("_cleanUpResources") EndWith Return $sClass.Object EndFunc ;==>Snake Func _getFoodBrush($this) Return $this.hFoodBrush EndFunc ;==>_getFoodBrush Func _getGraphics($this) Return $this.hGraphics EndFunc ;==>_getGraphics Func _getBitmap($this) Return $this.hBitmap EndFunc ;==>_getBitmap Func _getGraphicsCtxt($this) Return $this.hGraphicsCtxt EndFunc ;==>_getGraphicsCtxt Func _getBrush($this) Return $this.hBrush EndFunc ;==>_getBrush Func _drawStage($this, $aPoints) Local $hGraphicsCtxt = $this.getGraphicsCtxt() $this.move() ; Effacer l'arrière-plan _GDIPlus_GraphicsClear($hGraphicsCtxt, 0xFF000000) ; Dessiner la nourriture Local $oFood = $this.getMap()[0] _GDIPlus_GraphicsFillRect($hGraphicsCtxt, $oFood.getXPos(), $oFood.getYPos(), $oFood.getWidth(), $oFood.getHeight(), $this.getFoodBrush()) ; Dessiner les segments du serpent For $i = 1 To UBound($aPoints) - 1 Local $oPoint = $aPoints[$i] _GDIPlus_GraphicsFillRect($hGraphicsCtxt, $oPoint.getXPos(), $oPoint.getYPos(), $oPoint.getWidth(), $oPoint.getHeight(), $this.getBrush()) Next ; Mettre à jour l'affichage _GDIPlus_GraphicsDrawImageRect($this.getGraphics(), $this.getBitmap(), 0, 0, $this.getBoardWidth(), $this.getBoardHeight()) EndFunc ;==>_drawStage Func _drawStage2($this, $aPoints) _GDIPlus_GraphicsClear($this.getGraphicsCtxt(), 0xFF000000) $this.move() Local $oFood = $this.getMap()[0] _GDIPlus_GraphicsFillRect($this.getGraphicsCtxt(), $oFood.getXPos(), $oFood.getYPos(), $oFood.getWidth(), $oFood.getHeight(), $this.getFoodBrush()) For $i = 1 To UBound($aPoints) - 1 Local $oPoint = $aPoints[$i] _GDIPlus_GraphicsFillRect($this.getGraphicsCtxt(), $oPoint.getXPos(), $oPoint.getYPos(), $oPoint.getWidth(), $oPoint.getHeight(), $this.getBrush()) Next _GDIPlus_GraphicsDrawImageRect($this.getGraphics(), $this.getBitmap(), 0, 0, $this.getBoardWidth(), $this.getBoardHeight()) EndFunc ;==>_drawStage2 Func _getFoodCounter($this) Return $this.foodCounter EndFunc ;==>_getFoodCounter Func _setFoodCounter($this, $foodCounter) $this.foodCounter = $foodCounter EndFunc ;==>_setFoodCounter Func _setSpeedLevel($this, $iLevel) $this.speedLevel = $iLevel EndFunc ;==>_setSpeedLevel Func _getSpeedLevel($this) Return $this.speedLevel EndFunc ;==>_getSpeedLevel Func _getBoard($this) Return $this.Board EndFunc ;==>_getBoard Func _runGameLoop($this) While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop If _IsPressed(25) Then $this.setdx(-1) $this.setdy(0) EndIf If _IsPressed(27) Then $this.setdx(1) $this.setdy(0) EndIf If _IsPressed(26) Then $this.setdx(0) $this.setdy(-1) EndIf If _IsPressed(28) Then $this.setdx(0) $this.setdy(1) EndIf If _IsPressed(53) Then $this.sleepW() EndIf $this.drawStage($this.getMap()) Sleep($this.getSpeedLevel()) WEnd EndFunc ;==>_runGameLoop Func _getBoardWidth($this) Return $this.iBoardWidth EndFunc ;==>_getBoardWidth Func _getBoardHeight($this) Return $this.iBoardHeight EndFunc ;==>_getBoardHeight Func _generateFood($this) Local $aMap = $this.getMap() Local $oFood = $aMap[0] $oFood.setXPos(Random(10, $this.getBoardWidth() - 10)) $oFood.setXPos(Random(10, $this.getBoardHeight() - 10)) $this.setMap($aMap) EndFunc ;==>_generateFood Func _setFood($this, $oFood) $this.food = $oFood EndFunc ;==>_setFood Func _getFood($this) Return $this.food EndFunc ;==>_getFood Func _getHead($this) Return $this.head EndFunc ;==>_getHead Func _setdx($this, $dx) $this.dx = $dx EndFunc ;==>_setdx Func _setdy($this, $dy) $this.dy = $dy EndFunc ;==>_setdy Func _getdx($this) Return $this.dx EndFunc ;==>_getdx Func _getdy($this) Return $this.dy EndFunc ;==>_getdy Func _getMap($this) Return $this.aMap EndFunc ;==>_getMap Func _setMap($this, $aMap) $this.aMap = $aMap EndFunc ;==>_setMap Func _checkBorderCollision($this) Local $aMap = $this.getMap() Local $head = $aMap[1] Local $hX = $head.getXPos() + $this.getdx() * 10 Local $hY = $head.getYPos() + $this.getdy() * 10 If $hX <= 0 Or $hX >= $this.getBoardWidth() - 10 Or $hY <= 0 Or $hY >= $this.getBoardHeight() - 10 Then Return True EndIf Return False EndFunc ;==>_checkBorderCollision Func _checkSelfCollision($this) Local $aMap = $this.getMap() Local $head = $aMap[1] Local $hX = $head.getXPos() Local $hY = $head.getYPos() Local $hW = $hX + $this.getdx() * 10 Local $hH = $hY + $this.getdy() * 10 For $i = 2 To UBound($aMap) - 1 Local $segment = $aMap[$i] Local $segX = $segment.getXPos() Local $segY = $segment.getYPos() Local $segW = $segX + $segment.getWidth() Local $segH = $segY + $segment.getHeight() If $hX < $segW And $hW > $segX And $hY < $segH And $hH > $segY Then Return True EndIf Next Return False EndFunc ;==>_checkSelfCollision Func _checkFoodCollision($this) Local $aMap = $this.getMap() Local $head = $aMap[1] Local $hX = $head.getXPos() + $this.getdx() * 10 Local $hY = $head.getYPos() + $this.getdy() * 10 Local $hW = $hX + $head.getWidth() Local $hH = $hY + $head.getHeight() Local $food = $aMap[0] Local $fX = $food.getXPos() Local $fY = $food.getYPos() Local $fW = $fX + $food.getWidth() Local $fH = $fY + $food.getHeight() If $hX < $fW And $hW > $fX And $hY < $fH And $hH > $fY Then $this.generateFood() Local $lastSegment = $aMap[UBound($aMap) - 1] Local $lastX = $lastSegment.getXPos() + $this.getdx() * 10 Local $lastY = $lastSegment.getYPos() + $this.getdy() * 10 MapAppend($aMap, Point($lastX, $lastY)) $this.setMap($aMap) Return True EndIf Return False EndFunc ;==>_checkFoodCollision Func _resetGame($this) Local $aMap = $this.getMap() For $e In $aMap $e = 0 Next $aMap = 0 Local $aNewMap[] MapAppend($aNewMap, Point()) $this.setMap($aNewMap) $this.generateFood() MapAppend($aNewMap, Point(Random(10, $this.getBoardWidth() - 10), Random(10, $this.getBoardHeight() - 10))) $this.setMap($aNewMap) Local $aRandomDirectionTab = [-1, 0, 1] Local $dx = $aRandomDirectionTab[Int(Random(0, 2, 1))] Local $dy = $aRandomDirectionTab[Int(Random(0, 2, 1))] $this.setdx($dx) $this.setdy($dy) $this.setSpeedLevel(100) $this.setFoodCounter(0) $this.drawStage($aNewMap) EndFunc ;==>_resetGame Func _move($this) Local $aMap = $this.getMap() Local $head = $aMap[1] Local $newX = $head.getXPos() + $this.getdx() * 10 Local $newY = $head.getYPos() + $this.getdy() * 10 If $this.checkBorderCollision() Or $this.checkSelfCollision() Then MsgBox(64, "Game Over", "Collision! Game Over.") Local $iResponse = MsgBox(36, "Restart Game", "Do you want to restart the game?") If $iResponse = 6 Then _resetGame($this) Return True Else $this.cleanUpResources() _GDIPlus_Shutdown() _AutoItObject_Shutdown() Exit EndIf EndIf If $this.checkFoodCollision() Then $this.setFoodCounter($this.getFoodCounter() + 1) Local $lastSegment = $aMap[UBound($aMap) - 1] Local $lastX = $lastSegment.getXPos() + $this.getdx() * 10 Local $lastY = $lastSegment.getYPos() + $this.getdy() * 10 MapAppend($aMap, Point($lastX, $lastY)) If $this.getFoodCounter() = 4 Then Local $newSpeedLevel = $this.getSpeedLevel() - 20 If $newSpeedLevel < 0 Then $newSpeedLevel = 1 $this.setSpeedLevel($newSpeedLevel) $this.setFoodCounter(0) EndIf $this.generateFood() EndIf $head.setXPos($newX) $head.setYPos($newY) For $i = UBound($aMap) - 1 To 2 Step -1 $aMap[$i].setXPos($aMap[$i - 1].getXPos()) $aMap[$i].setYPos($aMap[$i - 1].getYPos()) Next $this.setMap($aMap) EndFunc ;==>_move ; #FUNCTION# ==================================================================================================================== ; Name ..........: _sleepW ; Description ...: Waits for keyboard input to change the direction of movement in the Snake game. ; Syntax ........: _sleepW(ByRef $this) ; Parameters ....: $this - [in/out] A reference to the Snake object. ; Return values .: None ; Modified ......: ; Remarks .......: This function is triggered when the player presses the 'S' key in the Snake game. It waits for directional input ; (arrow keys) to change the movement direction of the snake. The function updates the movement direction properties ; of the Snake object accordingly. Note: There seems to be a crashing issue with this function that needs further investigation. ; Related .......: Snake ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _sleepW($this) Do Do Sleep(100) Until _IsPressed(25) Or _IsPressed(26) Or _IsPressed(27) Or _IsPressed(28) If _IsPressed(25) Then $this.setdx(-1) $this.setdy(0) EndIf If _IsPressed(27) Then $this.setdx(1) $this.setdy(0) EndIf If _IsPressed(26) Then $this.setdx(0) $this.setdy(-1) EndIf If _IsPressed(28) Then $this.setdx(0) $this.setdy(1) EndIf Until _IsPressed(25) Or _IsPressed(26) Or _IsPressed(27) Or _IsPressed(28) EndFunc ;==>_sleepW ; #FUNCTION# ==================================================================================================================== ; Name ..........: _cleanUpResources ; Description ...: Cleans up all resources used in the Snake game. ; Syntax ........: _cleanUpResources() ; Parameters ....: None ; Return values .: None ; Remarks .......: This function deallocates all resources used in the Snake game, including graphics resources, objects, and variables. ; Related .......: Snake ; =============================================================================================================================== Func _cleanUpResources($this) ConsoleWrite("cleanUpRessources" & @CRLF) Local $aMap = $this.getMap() For $oPoint In $aMap $oPoint = 0 Next $aMap = 0 $this.setMap(0) ; Deallocate GDI+ resources _GDIPlus_GraphicsDispose($this.getGraphicsCtxt()) _GDIPlus_BrushDispose($this.getBrush()) _GDIPlus_BrushDispose($this.getFoodBrush()) _GDIPlus_BitmapDispose($this.getBitmap()) _GDIPlus_Shutdown() EndFunc ;==>_cleanUpResources ; #FUNCTION# ==================================================================================================================== ; Name ..........: Point ; Description ...: Creates a Point object used in the Snake game to represent coordinates. ; Syntax ........: Point([$X = 0[, $Y = 0]]) ; Parameters ....: $X - [optional] The X coordinate value. Default is 0. ; $Y - [optional] The Y coordinate value. Default is 0. ; Return values .: Returns a Point object with specified coordinates. ; Remarks .......: This function is used to create a Point object representing coordinates on the game board for the Snake game. ; It is used to manage positions of the snake segments and the food items. ; Related .......: Snake, _AutoItObject_Class ; =============================================================================================================================== Func Point($X = 0, $Y = 0) Local $cPoint = _AutoItObject_Class() Local Const $iWidth = 10 Local Const $iHeight = 10 With $cPoint .Create() .AddProperty("X", $ELSCOPE_PRIVATE, $X) .AddProperty("Y", $ELSCOPE_PRIVATE, $Y) .AddProperty("iWidth", $ELSCOPE_PRIVATE, $iWidth) .AddProperty("iHeight", $ELSCOPE_PRIVATE, $iHeight) .AddMethod("setXPos", "_setXPos") .AddMethod("setYPos", "_setYPos") .AddMethod("getXPos", "_getXPos") .AddMethod("getYPos", "_getYPos") .AddMethod("setWidth", "_setWidth", True) .AddMethod("setHeight", "_setHeight", True) .AddMethod("getWidth", "_getWidth") .AddMethod("getHeight", "_getHeight") .AddDestructor("_pointDestructor") EndWith Return $cPoint.Object EndFunc ;==>Point Func _setXPos($this, $iX) $this.X = $iX EndFunc ;==>_setXPos Func _setYPos($this, $iY) $this.Y = $iY EndFunc ;==>_setYPos Func _getXPos($this) Return $this.X EndFunc ;==>_getXPos Func _getYPos($this) Return $this.Y EndFunc ;==>_getYPos Func _getWidth($this) Return $this.iWidth EndFunc ;==>_getWidth Func _getHeight($this) Return $this.iHeight EndFunc ;==>_getHeight Func _setColor($this, $iClolor) $this.iColor = $iClolor EndFunc ;==>_setColor Func _getColor($this) Return $this.iColor EndFunc ;==>_getColor Func _ErrFunc($oError) ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc ;***************************************************************************************************************************************** Global $sNake = Snake() $sNake.runGameLoop() $sNake = 0 ;***************************************************************************************************************************************** _AutoItObject_Shutdown()
  12. It's the same problem, GUISetState won't work correctly with WinSetState. If you just remove the GUISetState(), it is like doing a GUISetState(@SW_HIDE). Then it will not work afterward. Use that instead : GUISetState() WinSetState($gui, "", @SW_HIDE)
  13. Last words on this, for my side today: There is a "normal" keyword which is also new to me. Maybe even better then the restore thingy. I don't know yet, but I will investigate a bit. https://w3c.github.io/webdriver/#resizing-and-positioning-windows Best regards Sven
  14. Thanks again. I was looking directly in the WebDriver documentation, not in au3WebDriver project. I am a bit suprised now, because I would have used null instead of the zeros. Interesting ... . I will also test it tomorrow and will have a look into the docs again. Maybe I will create an GitHub issue (or even PR) for @Danp2. Then we will see 🤝😀 . Best regards Sven
  15. Here : _WD_Window($sSession, "rect", '{"value":{"height":0,"width":0,"x":0,"y":0}}') restores as it should be. Not obvious to know it. Should be in help file, or like you propose to have a specific "restore" command.
  16. Can you please share how you did it? I cannot test it right now, but I believe to know how I would do it 😅 . Thanks again in advance. Best regards Sven
  17. Okay, that's a good one, thanks @Nine 👍 . Best regards Sven
  18. In some web sites, it will continually ask you to accept cookies for example. But when you use your own profile, they will ask you only once. Same goes for un/pw, etc.
  19. Not working for me, what would be the syntax that you have in mind, I tried a few and no success... NVM -- got it working, had a syntax error
  20. Okay thanks. Then I have to read about these settings/options more in depth, because I still don't see the advantages of it. Best regards Sven
  21. Nine, there is a small problem I forgot an important thing. The application is supposed to run as a hide. The window is to restore either a keyboard shortcut or by running again the exe. And in that case the button no longer works To summarize. If the application is launched normally (the window is immediately visible) then everything is ok. If the application is launched as hidden. Restarting the exe restores the window but the button no longer works. In this configuration app does not work: #include <GUIConstantsEx.au3> #include <Misc.au3> If Not _Singleton("MyGui", 1) Then Exit WinSetState("gui V1.1.1", "", @SW_SHOW) $gui = GUICreate("gui V1.1.1",445,262,-1,-1,-1,-1) $button = GUICtrlCreateButton("Button",60,20,100,30,-1,-1) $bHide = GUICtrlCreateButton("Hide",60,60,100,30,-1,-1) $label = GUICtrlCreateLabel("My Text",80,100,50,15,-1,-1) ;GUISetState() $counter = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $button $counter +=1 guictrlsetdata($label, $counter) case $bHide WinSetState($gui, "", @SW_HIDE) EndSwitch WEnd ---edit--- It seems that GUISetState() does more than just show the window so it must be at the beginning of the script. So I came up with a kind of workaround: WinSetTrans($gui, "", 0) GUISetState() WinSetState($gui, "", @SW_HIDE) WinSetTrans($gui, "", 255) Not very pretty but it works.
  22. Thanks for taking the time to look at this, Nine... While fiddling around with it, I also discovered that replacing Send with ControlSend("", "", "",... solved nearly all of the mal-functions. And your creation of SendString(), with the use of _IsPressed and _BlockInput is a very good way to keep the user from inadvertently making the script send strings to itself. Your suggestion of using Ctrl instead of Alt for hotkeys makes sense. Less chance of interfering with other apps. I would have preferred single keys, but I was concerned about using Fx keys for this purpose. I now consider the task to be finished.
  23. Because I prefer to use my own personal profile, not a generic/empty one.
  24. Genieal! Simple and effective. Thank you so much Nine
  25. Only out of curiosity @Nine , why do you define these "args"? --user-data-dir --profile-directory Is there a specific need for it or is it just a "copy and paste" thingy? I am really asking because I don't know why this should be defined 🤔 . Thanks for any explanation 🤝 . ------------------------------- @Danp2 could this be a improvement, to have something like ... _WD_Window($sSession, 'restore') in version v1.4.0 maybe? Besides that, I also see that the browser compatibility isn't very good 😔 . Best regards Sven
  26. As a complete different approach: Read this article that could be helpful - I don't know. => Usage of an API (yahoo finance) to get the information you want. https://algotrading101.com/learn/yahoo-finance-api-guide/ 💡 I was just searching for "yahoo finance api" on google ... several API ideas. Best regards Sven
  1. Load more activity
×
×
  • Create New...