Jump to content

[Solved] - Rabbit Maze - Need some help and idea!


 Share

Recommended Posts

Solved.

I'm writing a Maze with AutoIt, take a look on it and don't make me to explain more!

#NoTrayIcon
#include <Misc.au3>
Opt("GUICloseOnESC", 0)
Const $Title = "Rabbit Maze"
_Singleton($Title)
Global $BestScore = 9999
$GUI = GUICreate($Title, 640, 480)
GUISetBkColor(0xFFFFFF)
GUICtrlCreateGroup("Coordinate", 530, 400, 100, 70)
GUICtrlCreateLabel("X Pos:", 540, 420, 35, 17)
GUICtrlCreateLabel("Y Pos:", 540, 445, 35, 17)
$X = GUICtrlCreateLabel(198, 580, 420, 35, 17)
$Y = GUICtrlCreateLabel(38, 580, 445, 35, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Game Field", 10, 10, 620, 380)
$Maze = GUICtrlCreatePic("Maze.jpg", 180, 50, 300, 300)
$Carrot = GUICtrlCreatePic("Carrot.jpg", 490, 308, 24, 36)
$Rabbit = GUICtrlCreatePic("Rabbit.jpg", 198, 38, 12, 10)
GUICtrlSetBkColor($Rabbit, 0xFF0000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", 10, 400, 315, 70)
GUICtrlCreateLabel("Use the Arrow keys to reach the Carrot through the Maze.", 20, 420, 276, 17)
GUICtrlCreateLabel("Press Enter to restart the Game.", 20, 445, 154, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Timer:", 335, 400, 185, 70)
GUICtrlCreateLabel("Time Spent:", 345, 430, 61, 17)
$Timer = GUICtrlCreateLabel(0, 410, 430, 16, 17, 0x1)
GUICtrlCreateLabel("second(s).", 435, 430, 53, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()
AdlibRegister("_Timer", 1000)
;~ ----------------------------------------------------------------------------------------------------
While 1
Switch GUIGetMsg()
  Case -3
   Exit
EndSwitch
Select
  Case _IsPressed(25)
   _Move("Left")
  Case _IsPressed(26)
   _Move("Up")
  Case _IsPressed(27)
   _Move("Right")
  Case _IsPressed(28)
   _Move("Down")
  Case _IsPressed("0D")
   _Restart()
EndSelect
WEnd
;~ ----------------------------------------------------------------------------------------------------
Func _Move($Key)
If WinActive($Title, "Game Field") Then
  Switch $Key
   Case "Left"
    GUICtrlSetPos($Rabbit, GUICtrlRead($X) - 1, GUICtrlRead($Y))
    GUICtrlSetData($X, GUICtrlRead($X) - 1)
   Case "Up"
    GUICtrlSetPos($Rabbit, GUICtrlRead($X), GUICtrlRead($Y) - 1)
    GUICtrlSetData($Y, GUICtrlRead($Y) - 1)
   Case "Right"
    GUICtrlSetPos($Rabbit, GUICtrlRead($X) + 1, GUICtrlRead($Y))
    GUICtrlSetData($X, GUICtrlRead($X) + 1)
   Case "Down"
    GUICtrlSetPos($Rabbit, GUICtrlRead($X), GUICtrlRead($Y) + 1)
    GUICtrlSetData($Y, GUICtrlRead($Y) + 1)
  EndSwitch
  _Check()
EndIf
EndFunc   ;==>_Move
Func _Check()
$RabbitPos = ControlGetPos($Title, "Game Field", "[CLASS:Static; INSTANCE:7]")
If $RabbitPos[0] >= 490 And $RabbitPos[0] <= 514 Then
  If $RabbitPos[1] >= 308 And $RabbitPos[1] <= 344 Then
   If GUICtrlRead($Timer) < $BestScore Then $BestScore = GUICtrlRead($Timer)
   MsgBox(64, $Title, "Congratulations! You have won the Carrot!" & @CRLF & "Your best score is " & $BestScore & " Second(s)" & @CRLF & "Click OK to restart the Game.", 0, $GUI)
   _Restart()
  EndIf
EndIf
EndFunc   ;==>_Check
Func _Timer()
GUICtrlSetData($Timer, GUICtrlRead($Timer) + 1)
EndFunc   ;==>_Timer
Func _Restart()
GUICtrlSetData($X, 198)
GUICtrlSetData($Y, 38)
GUICtrlSetPos($Rabbit, 198, 38)
GUICtrlSetData($Timer, 0)
EndFunc   ;==>_Restart

I Suggest you to download the zip package, coz you will need some image files.

http://www.mediafire.com/?rrs9an791fnm3o0

I need some help and or ideas about how to block user to navigate the Rabbit! over the walls.

I was thinking about it:

1. GetControlPos ( Rabbit )

2. PixelSearch around the Rabbit.

3. Check if it's over the walls.

It's just an idea, i know you will come with better ones.

I don't want to notify the user if he goes over the walls, i just want to prevent him from going over the walls.

You know, prevention is better than cure!

Edited by D4RKON3
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...