VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
Begin VB.Form frmMain 
   BorderStyle     =   0  'None
   Caption         =   "Собери кубики и увидишь океан"
   ClientHeight    =   4770
   ClientLeft      =   150
   ClientTop       =   720
   ClientWidth     =   6015
   Icon            =   "frmMain.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   4770
   ScaleWidth      =   6015
   StartUpPosition =   3  'Windows Default
   Begin ComctlLib.StatusBar StatusBar1 
      Align           =   2  'Align Bottom
      Height          =   375
      Left            =   0
      TabIndex        =   0
      Top             =   4395
      Width           =   6015
      _ExtentX        =   10610
      _ExtentY        =   661
      Style           =   1
      SimpleText      =   ""
      _Version        =   327682
      BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7} 
         NumPanels       =   1
         BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
            Object.Width           =   3598
            MinWidth        =   3598
            Object.Tag             =   ""
         EndProperty
      EndProperty
   End
   Begin VB.Image im 
      Appearance      =   0  'Flat
      Height          =   885
      Index           =   0
      Left            =   480
      Picture         =   "frmMain.frx":0442
      Top             =   360
      Width           =   1020
   End
   Begin VB.Menu About 
      Caption         =   "О программе"
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public First As Boolean, imFirst As Integer
Dim Matrix(20) As Integer, Step As Integer, i As Integer
Dim Place1 As Integer, Place2 As Integer, Tmp As Integer

Private Sub About_Click()
frmAbout.Show 1
End Sub

Private Sub Form_load()
    Dim x As Integer, y As Integer, Count As Integer, Num As Integer
    For y = 0 To 3
        For x = 0 To 4
            i = y * 5 + x
            If i <> 0 Then
                Load im(i)
                im(i).Left = im(0).Left + (im(i).Width - 35) * x
                im(i).Top = im(0).Top + (im(i).Height - 35) * y
                im(i).Visible = True
            End If
        Next x
    Next y
    Load im(25)
    For i = 0 To 19
        Matrix(i) = i
    Next i
    Call InitPuzzle
End Sub

Private Sub InitPuzzle()
    Dim Str As String
    Randomize
    For i = 1 To 70
        Place1 = Int(Rnd * 19)
        Place2 = Int(Rnd * 19)
        Tmp = Matrix(Place1)
        Matrix(Place1) = Matrix(Place2)
        Matrix(Place2) = Tmp
    Next i
    For i = 0 To 19
        Str = "im" + Chr(48 + Int(Matrix(i) / 5)) + Chr(48 + Matrix(i) - 5 * (Int(Matrix(i) / 5))) + ".jpg"
        im(i).Picture = LoadPicture(Str)
    Next i
    First = True
    StatusBar1.SimpleText = "Число ходов: 0"
End Sub

Private Sub im_Click(Index As Integer)
    Dim Status As Boolean
    If First Then
        imFirst = Index
        First = False
        frmMain.MousePointer = vbSizePointer
    Else
        StatusBar1.SimpleText = "Число ходов: " & Step + 1
        im(25).Picture = im(imFirst).Picture
        im(imFirst).Picture = im(Index).Picture
        im(Index).Picture = im(25).Picture
        frmMain.MousePointer = 0
        Tmp = Matrix(imFirst)
        Matrix(imFirst) = Matrix(Index)
        Matrix(Index) = Tmp
        Step = Step + 1
        First = True
        Status = True
        For i = 0 To 19
            If Matrix(i) <> i Then Status = False
        Next i
        If Status Then
            If MsgBox("Вы собрали картинку за " & Step & " ход(ов)." & vbCr & "Хотите сыграть еще раз?", vbYesNo + vbInformation, "Поздравляю!") = vbYes Then
                Call InitPuzzle
            Else
                For i = 0 To 19
                    im(i).Enabled = False
                Next i
            End If
        End If
    End If
End Sub


