Jump to content

Recommended Posts

Posted (edited)

press tab to switch between green and blue

green marks correct panels

blue marks empty spaces

bold digits on a row or a column means that row or column is filled in correctly

just in case you dont know how to play clicky

appreciate any suggestions and criticisms

press detect(not mine obviously)

http://www.autoitscript.com/forum/index.ph...hl=_pressdetect

#include <Guiconstants.au3>
#include <_PressDetect.au3>
#include <Date.au3>
Opt("MouseCoordMode", 0) 
HotKeySet("{tab}","swap")

GUICreate("Picross Autoit - 00:00:00",571,591,10,10)
GUISetState()

Global $green = 0x33ff66, $blue = 0x0000ff , $bkcolor = 0xe6dad8
Global $Secs, $Mins, $Hour, $Time
Global $hint_label[2][10]
Global $colour = 0x33ff66, $flag = False
Global $answers[10][10];user answer
Global $label_array[10][10];array containing all labels
Global $solution[10][10];array containing solution
Global $hints[2][10];arrat containing hints
Global $size =52    ;size of the label
Global $offset = 50         
Global $x = 0,$y = 0
Global $number_of_controls = 7
Dim $sTime, $timer,$tStart = False,$penalty = 0

;menu
$menu = GUICtrlCreateMenu("Menu")
$newgame = GUICtrlCreateMenuItem("New Game",$menu)
$showsolu = GUICtrlCreateMenuItem("Show Solution",$menu)
$exit = GUICtrlCreateMenuItem("Close",$menu)

;set labels
For $i = 0 to 9
    For $j = 0 To 9
        $answers[$i][$j] = 0    ;initialize answer arrays
        $solution[$i][$j] = Random(0,1,1);generate a solution
        $label_array[$i][$j] = GUICtrlCreateLabel("",$i*$size+$offset,$j*$size+$offset,$size,$size )
        GUICtrlSetBkColor($label_array[$i][$j],$bkcolor)
    Next
Next

$key = guictrlcreatelabel("",0,0,50,50)
GUICtrlSetBkColor($key,$colour)

;lines seperating squares
$offset = 0
For $i = 0 To 9
    GUICtrlCreateGroup("",50+$offset,-10,53,650)
    $offset = $offset + $size
Next
$offset = 0
For $i = 0 To 9
    GUICtrlCreateGroup("",-10,43+$offset,650,59)
    $offset = $offset + $size
Next
GUICtrlCreateGroup("",311,-10,52,650)
GUICtrlCreateGroup("",-10,304,650,58)
;-------------------------------------------------------

;add controls to press detection
For $i = 0 to 9
    For $j = 0 To 9
        _PressDetectAddCtrl($label_array[$i][$j])
    Next
Next

While 1
    $msg = GUIGetMsg()
    
    $pressed = _PressDetect()
    If IsArray($pressed) Then;mouse click on panel
        getcontrol($pressed[1])

;see if its the right answer
        If $colour = $green Then
            If $solution[$x][$y] = 1 Then
                GUICtrlSetBkColor($label_array[$x][$y],$colour)
            Else
                GUICtrlSetData($pressed[1]+$number_of_controls,"WRONG")
                Sleep(500)
                GUICtrlSetData($pressed[1]+$number_of_controls,"+1 minute")
                Sleep(500)
                $penalty = $penalty + 29000
            EndIf
        Else
            GUICtrlSetBkColor($label_array[$x][$y],$colour)
        EndIf
                
;check if the puzzle is finished
        If comparearrays($solution,$answers) = True Then
            $tStart = False
            MsgBox(0,"","You Got It")
        EndIf
        
        If $colour = $green Then 
            $answers[$x][$y] = 1
        Else
            $answers[$x][$y] = 0
        EndIf
    EndIf
    
    If $msg = $GUI_EVENT_CLOSE Or $msg = $exit Then
        Exit
    ElseIf $msg = $newgame Then
        getsolution()
        gethints()
        showhints()
;~      showsolution()
;timer starts
        $timer = TimerInit()
        $tStart = True
        $penalty = 0
    ElseIf $msg = $showsolu Then
        showsolution()
        $tStart = False
        WinSetTitle("Picross Autoit","","Picross Autoit - 99:99:99")
    EndIf
    
;timer------------------------------------------------------------------------
    If $tStart = True Then
        _TicksToTime(Int(TimerDiff($timer)+$penalty), $Hour, $Mins, $Secs )
        Local $sTime = $Time 
        $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
        If $sTime <> $Time Then 
            WinSetTitle("Picross Autoit","","Picross Autoit - "&$Time)
        EndIf
    EndIf
WEnd

Func swap()
    If $flag = True Then
        $colour = 0x33ff66;green
        $flag = False
    Else
        $colour = 0x0000ff;blue
        $flag = True
    EndIf
    GUICtrlSetBkColor($key,$colour)
EndFunc

;check b against a
Func comparearrays(ByRef $a,ByRef $b)
    Local $correct = 0, $target = 10
    For $i = 0 to 9
        For $j = 0 to 9
            If $a[$i][$j] = $b[$i][$j] Then
                $correct += 1
            EndIf
        Next
        If $correct = $target Then
            GUICtrlSetFont($hint_label[0][$i],9,600)
        EndIf
        $target = $correct + 10
    Next
    
    For $i = 0 to 9
        For $j = 0 to 9
            If $a[$j][$i] = $b[$j][$i] Then
                $correct += 1
            EndIf
        Next
        If $correct = $target Then
            GUICtrlSetFont($hint_label[1][$i],9,600)
        EndIf
        $target = $correct + 10
    Next
    
    If $correct = 200 Then Return True
    Return False
EndFunc
        
Func getcontrol(ByRef $controlID)
    $controlID = $controlID - $number_of_controls
    $str = String($controlID)
    If $controlID < 10 Then
        $x = 0
        $y = Int($str)
    Else
         $x = Number(StringLeft($str,1))
         $y = Number(StringRight($str,1))
    EndIf
EndFunc

Func getsolution()
    For $i = 0 to 9
        For $j = 0 to 9
            $solution[$i][$j] = Random(0,1,1)
            $answers[$i][$j] = 0
            GUICtrlSetBkColor($label_array[$i][$j],0xe6dad8)
            GUICtrlSetData($label_array[$i][$j],"")
        Next
    Next
EndFunc

Func showsolution()
    For $i = 0 to 9
        For $j = 0 to 9
            If $solution[$i][$j] = 1 Then
                GUICtrlSetBkColor($label_array[$i][$j],$green)
            EndIf
        Next
    Next
EndFunc

Func gethints()
    $string = ""
    $number = 0
    For $k = 0 to 9
        For $i = 0 to 9 
            If $solution[$k][$i] = 1 Then
                $number = $number + 1
            Else
                If $number <> 0 Then 
                    $string = $string&$number&" "
                EndIf
                $number = 0
            EndIf
        Next
        If $number <> 0 Then 
                    $string = $string&$number&" "
        EndIf
        $hints[0][$k] = $string
        $string = ""
        $number = 0
    Next
    
    $string = ""
    $number = 0
    For $k = 0 to 9
        For $i = 0 to 9
            If $solution[$i][$k] = True Then
                $number = $number + 1
            Else
                If $number <> 0 Then 
                    $string = $string&$number&" "
                EndIf
                $number = 0
            EndIf
        Next
        If $number <> 0 Then 
            $string = $string&$number&" "
        EndIf
        $hints[1][$k] = $string
        $string = ""
        $number = 0
    Next
EndFunc

Func showhints()
    For $i = 1 to 10
        $hint_label[0][$i-1] = GUICtrlCreateLabel($hints[0][$i-1],$i*52,10,45,20)
    Next
    For $i = 1 to 10
        $hint_label[1][$i-1] = GUICtrlCreateLabel($hints[1][$i-1],1,54*$i,45,20)
    Next
EndFunc
Edited by dexxa

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
×
×
  • Create New...