VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMain 
   AutoRedraw      =   -1  'True
   Caption         =   "Picture Puzzle"
   ClientHeight    =   7320
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   6840
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmMain.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   488
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   456
   StartUpPosition =   2  'CenterScreen
   Begin VB.PictureBox picDisplay 
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   4950
      Left            =   120
      Picture         =   "frmMain.frx":0442
      ScaleHeight     =   330
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   440
      TabIndex        =   10
      Top             =   1680
      Width           =   6600
   End
   Begin VB.CommandButton cmdReset 
      Caption         =   "&Reset"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   5520
      TabIndex        =   9
      Top             =   1080
      Width           =   1215
   End
   Begin VB.CommandButton cmdPlay 
      Caption         =   "&Play"
      Default         =   -1  'True
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4200
      TabIndex        =   8
      Top             =   1080
      Width           =   1215
   End
   Begin MSComctlLib.Slider colSlider 
      Height          =   255
      Left            =   4920
      TabIndex        =   4
      Top             =   120
      Width           =   1815
      _ExtentX        =   3201
      _ExtentY        =   450
      _Version        =   393216
      Min             =   2
      SelectRange     =   -1  'True
      SelStart        =   2
      Value           =   2
   End
   Begin VB.CommandButton cmdClose 
      Cancel          =   -1  'True
      Caption         =   "Cl&ose"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   5640
      TabIndex        =   3
      Top             =   6840
      Width           =   1095
   End
   Begin VB.PictureBox picBuffer 
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BackColor       =   &H00800080&
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      ScaleHeight     =   25
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   24
      TabIndex        =   2
      Top             =   1680
      Visible         =   0   'False
      Width           =   360
   End
   Begin VB.PictureBox picThumbnail 
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1410
      Index           =   1
      Left            =   2160
      Picture         =   "frmMain.frx":6AA14
      ScaleHeight     =   94
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   130
      TabIndex        =   1
      Top             =   120
      Width           =   1950
   End
   Begin VB.PictureBox picThumbnail 
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1410
      Index           =   0
      Left            =   120
      Picture         =   "frmMain.frx":73A46
      ScaleHeight     =   94
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   130
      TabIndex        =   0
      Top             =   120
      Width           =   1950
   End
   Begin MSComctlLib.Slider rowSlider 
      Height          =   255
      Left            =   4920
      TabIndex        =   6
      Top             =   480
      Width           =   1815
      _ExtentX        =   3201
      _ExtentY        =   450
      _Version        =   393216
      Min             =   2
      SelectRange     =   -1  'True
      SelStart        =   2
      Value           =   2
   End
   Begin VB.PictureBox picMark 
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BackColor       =   &H00800000&
      BorderStyle     =   0  'None
      FillStyle       =   0  'Solid
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   600
      ScaleHeight     =   25
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   23
      TabIndex        =   11
      Top             =   1680
      Visible         =   0   'False
      Width           =   345
   End
   Begin VB.Image Image1 
      Height          =   375
      Left            =   120
      Picture         =   "frmMain.frx":7CA78
      Stretch         =   -1  'True
      Top             =   6840
      Width           =   375
   End
   Begin VB.Label Label3 
      Caption         =   "A simple picture swaping puzzle for beginner programming enthusiasts."
      Height          =   375
      Left            =   600
      TabIndex        =   12
      Top             =   6840
      Width           =   4095
   End
   Begin VB.Shape Shape2 
      BorderColor     =   &H00808080&
      FillColor       =   &H00C0C0C0&
      FillStyle       =   0  'Solid
      Height          =   60
      Left            =   120
      Top             =   6720
      Width           =   6615
   End
   Begin VB.Shape Shape1 
      BorderColor     =   &H00808080&
      FillColor       =   &H00C0C0C0&
      FillStyle       =   0  'Solid
      Height          =   60
      Left            =   4200
      Top             =   840
      Width           =   2535
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "Row:"
      Height          =   255
      Left            =   4200
      TabIndex        =   7
      Top             =   480
      Width           =   735
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "Column:"
      Height          =   255
      Left            =   4200
      TabIndex        =   5
      Top             =   120
      Width           =   735
   End
   Begin VB.Shape shpSelector 
      BorderColor     =   &H00C00000&
      BorderWidth     =   3
      Height          =   1440
      Left            =   105
      Top             =   105
      Width           =   1980
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdClose_Click()
    Unload Me
End Sub

Private Sub cmdPlay_Click()
    puzzle.shuffleCells
    puzzle.setMark(0) = False
    resetButtonState False
End Sub

Private Sub cmdReset_Click()
    puzzle.loadImages
    resetButtonState
End Sub

Private Sub colSlider_Change()
    puzzle.setColSize = colSlider.Value
End Sub

Private Sub colSlider_Click()
    puzzle.setColSize = colSlider.Value
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Set puzzle = Nothing
End Sub

Private Sub picDisplay_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    
    If Not puzzle.onPlay Then Exit Sub
    
    Dim index   As Integer
    index = CInt(GetPixel(picMark.hdc, x, y) And HIGH_BYTE)
    
    If Not puzzle.getMark Then
        puzzle.setMark(index) = True
    Else
        puzzle.setMark(index) = False
        If puzzle.solved Then
            MsgBox PROMPT, vbExclamation, App.Title
            resetButtonState
        End If
    End If
    
End Sub

Private Sub rowSlider_Change()
    puzzle.setRowSize = rowSlider.Value
End Sub

Private Sub rowSlider_Click()
    puzzle.setRowSize = rowSlider.Value
End Sub

Private Sub resetButtonState(Optional ByVal bVal As Boolean = True)
    cmdPlay.Enabled = bVal
    cmdReset.Enabled = Not bVal
    colSlider.Enabled = bVal
    rowSlider.Enabled = bVal
    puzzle.onPlay = Not bVal
End Sub

Private Sub Form_Load()
    Set puzzle = New clsPuzzle
    puzzle.initialize picDisplay, picBuffer, picMark
    positionThumbnailSelector puzzle.getPictureSelection
End Sub

Private Sub picThumbnail_Click(index As Integer)
    If puzzle.onPlay Then Exit Sub
    positionThumbnailSelector index
    puzzle.setPictureSelection = index
    puzzle.loadImages
End Sub

Private Sub positionThumbnailSelector(ByVal picSelection As PictureConstants)
    shpSelector.left = picThumbnail(picSelection).left - 1
    shpSelector.top = picThumbnail(picSelection).top - 1
End Sub

