#Include "window9.bi"

Dim shared tic(36) As Byte

Dim Shared As Integer IMA1, IMA2
IMA1=Load_image("skull.ico")
IMA2=Load_image("null.bmp")
Function IMAGE_(number As Integer) As Integer

   If number=1 Then 
      Return IMA1
   Else 
      Return IMA2
   EndIf
End Function

Sub Open_Window_0()
  CenterWindow(OpenWindow("Черепа", 216, 0, 445, 490 ))
  Dim As Integer d,e,f,b,a
      d=1 : e=10 : f=10

      For b=1 To 6

        For a=1 To 6

            ButtonImageGadget(d,e,f,60,60,IMA1)
            tic(d)=1

            d+=1 : e+=70

        Next

        e=10 : f+=70

      Next 
  ButtonGadget(37,350,428,75,20,"Сгенерить")
End Sub

Sub  OPRED(a As Integer)
  Dim As Integer v
  If a-6>=1 Then

      v= tic(a-6) Xor 1

      tic(a-6)=v
      SetImageGadget(a-6, IMAGE_(v))
  EndIf 
  If a+6<=36 Then

      v= tic(a+6) Xor 1

      tic(a+6)=v
      SetImageGadget(a+6, IMAGE_(v))
  EndIf
  If a-1>=1 And a-1<>6 And a-1<>12 And a-1<>18 And a-1<>24 And a-1<>30 Then

      v= tic(a-1) Xor 1

      tic(a-1)=v
      SetImageGadget(a-1,IMAGE_(v))
  EndIf  
  If a+1<=36 And a+1<>7 And a+1<>13 And a+1<>19 And a+1<>25 And a+1<>31 Then

      v= tic(a+1)  Xor 1

      tic(a+1)=v
      SetImageGadget(a+1, IMAGE_(v))
  EndIf
  tic(a)=tic(a) Xor 1

  SetImageGadget(a, ( IMAGE_(tic(a))))
End Sub

Sub GENER()
Dim c As Integer

  Do

      OPRED(Int(Rnd*35+1))
      c+=1  
  Loop Until c=100

End Sub

Open_Window_0()
GENER()
Do  
  Var ev=WindowEvent()
  If ev=EventGadget Then

      Select Case EventNumber()
        Case 1 To 36

            OPRED(EventNumber())
        Case 37

            GENER()
      End Select

  ElseIf  ev=EventClose then

      End

  EndIf 
Loop