frmGame.vb

 Imports System.Drawing.Drawing2D

Public Class QuensBoard
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub


    Private components As System.ComponentModel.IContainer

    Friend WithEvents pieceBox As System.Windows.Forms.PictureBox
    Friend WithEvents btnNewGame As System.Windows.Forms.Button
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents lblTimer As System.Windows.Forms.Label
    Friend WithEvents btnHelp As System.Windows.Forms.Button
    Friend WithEvents btnNext As System.Windows.Forms.Button
    Friend WithEvents btnPrevious As System.Windows.Forms.Button
    Friend WithEvents PicBxQueen As System.Windows.Forms.PictureBox
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
    Friend WithEvents PicBxMark As System.Windows.Forms.PictureBox
    Friend WithEvents PicBxCross As System.Windows.Forms.PictureBox
    Friend WithEvents PicBxLightTileb As System.Windows.Forms.PictureBox
    Friend WithEvents PicBxLightTile2b As System.Windows.Forms.PictureBox
    Friend WithEvents PicBxDarkTile1 As System.Windows.Forms.PictureBox
    Friend WithEvents PicBxDarkTile2 As System.Windows.Forms.PictureBox
    Friend WithEvents PicBxOk As System.Windows.Forms.PictureBox
    Friend WithEvents Sol As System.Windows.Forms.Label
    Friend WithEvents dgo As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(QuensBoard))
        Me.pieceBox = New System.Windows.Forms.PictureBox
        Me.btnNewGame = New System.Windows.Forms.Button
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.lblTimer = New System.Windows.Forms.Label
        Me.btnHelp = New System.Windows.Forms.Button
        Me.btnNext = New System.Windows.Forms.Button
        Me.btnPrevious = New System.Windows.Forms.Button
        Me.PicBxQueen = New System.Windows.Forms.PictureBox
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.MenuItem5 = New System.Windows.Forms.MenuItem
        Me.PicBxMark = New System.Windows.Forms.PictureBox
        Me.PicBxCross = New System.Windows.Forms.PictureBox
        Me.PicBxLightTileb = New System.Windows.Forms.PictureBox
        Me.PicBxLightTile2b = New System.Windows.Forms.PictureBox
        Me.PicBxDarkTile1 = New System.Windows.Forms.PictureBox
        Me.PicBxDarkTile2 = New System.Windows.Forms.PictureBox
        Me.PicBxOk = New System.Windows.Forms.PictureBox
        Me.Sol = New System.Windows.Forms.Label
        Me.dgo = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.SuspendLayout()
        '
        'pieceBox
        '
        Me.pieceBox.BackColor = System.Drawing.Color.Transparent
        Me.pieceBox.Location = New System.Drawing.Point(0, 0)
        Me.pieceBox.Name = "pieceBox"
        Me.pieceBox.Size = New System.Drawing.Size(405, 360)
        Me.pieceBox.TabIndex = 3
        Me.pieceBox.TabStop = False
        '
        'btnNewGame
        '
        Me.btnNewGame.BackColor = System.Drawing.Color.AliceBlue
        Me.btnNewGame.Cursor = System.Windows.Forms.Cursors.Hand
        Me.btnNewGame.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.btnNewGame.Location = New System.Drawing.Point(56, 368)
        Me.btnNewGame.Name = "btnNewGame"
        Me.btnNewGame.Size = New System.Drawing.Size(68, 23)
        Me.btnNewGame.TabIndex = 4
        Me.btnNewGame.Text = "New"
        '
        'Timer1
        '
        Me.Timer1.Interval = 1000
        '
        'lblTimer
        '
        Me.lblTimer.AutoSize = True
        Me.lblTimer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblTimer.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblTimer.ForeColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(128, Byte), CType(255, Byte))
        Me.lblTimer.Location = New System.Drawing.Point(4, 368)
        Me.lblTimer.Name = "lblTimer"
        Me.lblTimer.Size = New System.Drawing.Size(48, 23)
        Me.lblTimer.TabIndex = 5
        Me.lblTimer.Text = "00:00"
        '
        'btnHelp
        '
        Me.btnHelp.BackColor = System.Drawing.Color.AliceBlue
        Me.btnHelp.Cursor = System.Windows.Forms.Cursors.Hand
        Me.btnHelp.Location = New System.Drawing.Point(128, 368)
        Me.btnHelp.Name = "btnHelp"
        Me.btnHelp.Size = New System.Drawing.Size(68, 23)
        Me.btnHelp.TabIndex = 6
        Me.btnHelp.Text = "Show me!"
        '
        'btnNext
        '
        Me.btnNext.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnNext.Cursor = System.Windows.Forms.Cursors.Hand
        Me.btnNext.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnNext.ForeColor = System.Drawing.Color.White
        Me.btnNext.Location = New System.Drawing.Point(224, 368)
        Me.btnNext.Name = "btnNext"
        Me.btnNext.Size = New System.Drawing.Size(20, 23)
        Me.btnNext.TabIndex = 8
        Me.btnNext.Text = ">"
        Me.btnNext.Visible = False
        '
        'btnPrevious
        '
        Me.btnPrevious.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnPrevious.Cursor = System.Windows.Forms.Cursors.Hand
        Me.btnPrevious.Enabled = False
        Me.btnPrevious.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnPrevious.ForeColor = System.Drawing.Color.White
        Me.btnPrevious.Location = New System.Drawing.Point(200, 368)
        Me.btnPrevious.Name = "btnPrevious"
        Me.btnPrevious.Size = New System.Drawing.Size(20, 23)
        Me.btnPrevious.TabIndex = 7
        Me.btnPrevious.Text = "<"
        Me.btnPrevious.Visible = False
        '
        'PicBxQueen
        '
        Me.PicBxQueen.Image = CType(resources.GetObject("PicBxQueen.Image"), System.Drawing.Image)
        Me.PicBxQueen.Location = New System.Drawing.Point(320, 412)
        Me.PicBxQueen.Name = "PicBxQueen"
        Me.PicBxQueen.Size = New System.Drawing.Size(35, 35)
        Me.PicBxQueen.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.PicBxQueen.TabIndex = 9
        Me.PicBxQueen.TabStop = False
        Me.PicBxQueen.Visible = False
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem5})
        Me.MenuItem1.Text = "&File"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 0
        Me.MenuItem2.Shortcut = System.Windows.Forms.Shortcut.F2
        Me.MenuItem2.Text = "&New Game"
        '
        'MenuItem5
        '
        Me.MenuItem5.Index = 1
        Me.MenuItem5.Shortcut = System.Windows.Forms.Shortcut.AltF4
        Me.MenuItem5.Text = "E&xit"
        '
        'PicBxMark
        '
        Me.PicBxMark.Image = CType(resources.GetObject("PicBxMark.Image"), System.Drawing.Image)
        Me.PicBxMark.Location = New System.Drawing.Point(276, 412)
        Me.PicBxMark.Name = "PicBxMark"
        Me.PicBxMark.Size = New System.Drawing.Size(35, 35)
        Me.PicBxMark.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.PicBxMark.TabIndex = 10
        Me.PicBxMark.TabStop = False
        Me.PicBxMark.Visible = False
        '
        'PicBxCross
        '
        Me.PicBxCross.Image = CType(resources.GetObject("PicBxCross.Image"), System.Drawing.Image)
        Me.PicBxCross.Location = New System.Drawing.Point(240, 412)
        Me.PicBxCross.Name = "PicBxCross"
        Me.PicBxCross.Size = New System.Drawing.Size(35, 35)
        Me.PicBxCross.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.PicBxCross.TabIndex = 11
        Me.PicBxCross.TabStop = False
        Me.PicBxCross.Visible = False
        '
        'PicBxLightTileb
        '
        Me.PicBxLightTileb.Image = CType(resources.GetObject("PicBxLightTileb.Image"), System.Drawing.Image)
        Me.PicBxLightTileb.Location = New System.Drawing.Point(192, 408)
        Me.PicBxLightTileb.Name = "PicBxLightTileb"
        Me.PicBxLightTileb.Size = New System.Drawing.Size(35, 35)
        Me.PicBxLightTileb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.PicBxLightTileb.TabIndex = 12
        Me.PicBxLightTileb.TabStop = False
        Me.PicBxLightTileb.Visible = False
        '
        'PicBxLightTile2b
        '
        Me.PicBxLightTile2b.Image = CType(resources.GetObject("PicBxLightTile2b.Image"), System.Drawing.Image)
        Me.PicBxLightTile2b.Location = New System.Drawing.Point(140, 412)
        Me.PicBxLightTile2b.Name = "PicBxLightTile2b"
        Me.PicBxLightTile2b.Size = New System.Drawing.Size(35, 35)
        Me.PicBxLightTile2b.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.PicBxLightTile2b.TabIndex = 13
        Me.PicBxLightTile2b.TabStop = False
        Me.PicBxLightTile2b.Visible = False
        '
        'PicBxDarkTile1
        '
        Me.PicBxDarkTile1.Image = CType(resources.GetObject("PicBxDarkTile1.Image"), System.Drawing.Image)
        Me.PicBxDarkTile1.Location = New System.Drawing.Point(100, 408)
        Me.PicBxDarkTile1.Name = "PicBxDarkTile1"
        Me.PicBxDarkTile1.Size = New System.Drawing.Size(35, 35)
        Me.PicBxDarkTile1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.PicBxDarkTile1.TabIndex = 14
        Me.PicBxDarkTile1.TabStop = False
        Me.PicBxDarkTile1.Visible = False
        '
        'PicBxDarkTile2
        '
        Me.PicBxDarkTile2.Image = CType(resources.GetObject("PicBxDarkTile2.Image"), System.Drawing.Image)
        Me.PicBxDarkTile2.Location = New System.Drawing.Point(56, 408)
        Me.PicBxDarkTile2.Name = "PicBxDarkTile2"
        Me.PicBxDarkTile2.Size = New System.Drawing.Size(35, 35)
        Me.PicBxDarkTile2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.PicBxDarkTile2.TabIndex = 15
        Me.PicBxDarkTile2.TabStop = False
        Me.PicBxDarkTile2.Visible = False
        '
        'PicBxOk
        '
        Me.PicBxOk.Image = CType(resources.GetObject("PicBxOk.Image"), System.Drawing.Image)
        Me.PicBxOk.Location = New System.Drawing.Point(12, 408)
        Me.PicBxOk.Name = "PicBxOk"
        Me.PicBxOk.Size = New System.Drawing.Size(35, 35)
        Me.PicBxOk.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Me.PicBxOk.TabIndex = 16
        Me.PicBxOk.TabStop = False
        Me.PicBxOk.Visible = False
        '
        'Sol
        '
        Me.Sol.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Sol.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(178, Byte))
        Me.Sol.ForeColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(128, Byte), CType(255, Byte))
        Me.Sol.Location = New System.Drawing.Point(248, 368)
        Me.Sol.Name = "Sol"
        Me.Sol.Size = New System.Drawing.Size(128, 24)
        Me.Sol.TabIndex = 17
        Me.Sol.Visible = False
        '
        'dgo
        '
        Me.dgo.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(178, Byte))
        Me.dgo.Location = New System.Drawing.Point(380, 368)
        Me.dgo.Name = "dgo"
        Me.dgo.Size = New System.Drawing.Size(24, 24)
        Me.dgo.TabIndex = 19
        Me.dgo.Text = ""
        Me.dgo.Visible = False
        '
        'Button1
        '
        Me.Button1.BackColor = System.Drawing.Color.LightSteelBlue
        Me.Button1.Location = New System.Drawing.Point(408, 368)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(28, 24)
        Me.Button1.TabIndex = 20
        Me.Button1.Text = "Go"
        Me.Button1.Visible = False
        '
        'PictureBox1
        '
        Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
        Me.PictureBox1.Location = New System.Drawing.Point(408, 0)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(32, 360)
        Me.PictureBox1.TabIndex = 21
        Me.PictureBox1.TabStop = False
        '
        'QuensBoard
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.Lavender
        Me.ClientSize = New System.Drawing.Size(438, 395)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.dgo)
        Me.Controls.Add(Me.Sol)
        Me.Controls.Add(Me.PicBxOk)
        Me.Controls.Add(Me.PicBxDarkTile2)
        Me.Controls.Add(Me.PicBxDarkTile1)
        Me.Controls.Add(Me.PicBxLightTile2b)
        Me.Controls.Add(Me.PicBxLightTileb)
        Me.Controls.Add(Me.PicBxCross)
        Me.Controls.Add(Me.PicBxMark)
        Me.Controls.Add(Me.PicBxQueen)
        Me.Controls.Add(Me.btnPrevious)
        Me.Controls.Add(Me.btnNext)
        Me.Controls.Add(Me.btnHelp)
        Me.Controls.Add(Me.lblTimer)
        Me.Controls.Add(Me.btnNewGame)
        Me.Controls.Add(Me.pieceBox)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.MaximizeBox = False
        Me.Menu = Me.MainMenu1
        Me.Name = "QuensBoard"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "8-Queens solutions"
        Me.ResumeLayout(False)

    End Sub

#End Region
#Region "Variables"
    Dim mChessTile As ArrayList = New ArrayList
    Dim mChessPieces As ArrayList = New ArrayList
    Dim mHelpPieces As ArrayList = New ArrayList
    Dim mSelectedIndex As Integer = -1
    Dim mBoard As Integer(,) = New Integer(7, 7) {}
    Private HW_Cursor As Boolean = False
    Private r As Point
    Private crossPoint As Point
    Private crossFlag As Boolean = False
    Private movedQueen As Boolean = False
    Private second, minute As Integer
    Private Const TILESIZE As Integer = 45
#End Region
#Region "Game"
#Region "Paint"


    Protected Overrides Sub OnPaint(ByVal paintEvent _
       As PaintEventArgs)

        Dim graphicsObject As Graphics = paintEvent.Graphics
        Dim brush As SolidBrush = New SolidBrush(Color.Lavender)
        Dim row, column As Integer

        For row = 0 To mBoard.GetUpperBound(0)

            For column = 0 To mBoard.GetUpperBound(1)


                graphicsObject.DrawImage( _
                   CType(mChessTile(mBoard(row, column)), _
                   Image), New Point(TILESIZE * column, _
                   TILESIZE * row))
            Next

        Next
        graphicsObject.FillRectangle(brush, 362, 0, 50, 362)

    End Sub

    Private Sub pieceBox_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pieceBox.Paint

        Dim i As Integer
        Dim cross As Bitmap = PicBxCross.Image
        Dim grObj As Graphics = e.Graphics

        Dim Mark As Bitmap = PicBxMark.Image


        For i = 0 To mChessPieces.Count - 1
            Getpiece(i).Draw(e.Graphics)
        Next

        For i = 0 To mHelpPieces.Count - 1
            GetHelpPiece(i).Draw(e.Graphics)
        Next


        If crossFlag Then
            grObj.DrawImage(cross, crossPoint)
            crossFlag = False
        End If
        For i = 0 To 5
            If MarkedQueensArr(i, 2) <> 0 Then
                Dim Markpoint As Point = New _
                Point(MarkedQueensArr(i, 1) * 45, MarkedQueensArr(i, 0) * 45)
                grObj.DrawImage(Mark, Markpoint)
            End If
        Next
        MarkedQueensArr = New Integer(5, 2) {}

    End Sub
#End Region

    Private Sub FrmGame_Load(ByVal sender _
       As System.Object, ByVal e As System.EventArgs) _
       Handles MyBase.Load
        MainForm = Me


        mChessTile.Add(PicBxLightTileb.Image)
        mChessTile.Add(PicBxLightTile2b.Image)
        mChessTile.Add(PicBxDarkTile1.Image)
        mChessTile.Add(PicBxDarkTile2.Image)

        ResetBoard()
        Invalidate()
    End Sub

    Private Sub ResetBoard()
        Dim column As Integer = 0
        Dim row As Integer = 0
        Dim current As Integer
        Dim piece As CGamePiece
        Dim random As Random = New Random
        Dim light As Boolean = False
        Dim type As Integer

        Dim Queen As Bitmap = PicBxQueen.Image

        For row = 0 To mBoard.GetUpperBound(0)

            For column = 0 To mBoard.GetUpperBound(1)

                type = random.Next(0, 2)

                If light Then
                    mBoard(row, column) = type
                    light = False
                Else
                    mBoard(row, column) = type + 2
                    light = True
                End If

            Next

            piece = New CGamePiece( _
            column * TILESIZE, row * TILESIZE, Queen)
            mChessPieces.Add(piece)


            light = Not light
        Next

    End Sub

    Private Function CheckBounds(ByVal point As Point, _
       Optional ByVal exclude As Integer = -1) As Integer

        Dim rectangle As Rectangle
        Dim i As Integer

        For i = 0 To mChessPieces.Count - 1

            rectangle = Getpiece(i).LocationRectangle()

            If (rectangle.Contains(point) AndAlso i <> exclude) Then
                Return i
            End If

        Next

        Return -1
    End Function

    Private Sub returnQueen()
        Getpiece(mSelectedIndex).SetLocation(r.X, _
          r.Y)
        mSelectedIndex = -1
        pieceBox.Invalidate()
    End Sub


    Private Function Getpiece(ByVal i As Integer) _
       As CGamePiece

        Return CType(mChessPieces(i), CGamePiece)
    End Function


    Private Sub newGame()
        pieceBox.Enabled = True
        Timer1.Enabled = False
        minute = 0
        second = 0
        lblTimer.Text = "00:00"
        reset()
        mChessPieces = New ArrayList
        ResetBoard()
        Invalidate()
    End Sub

    Private Sub btnNewGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewGame.Click
        newGame()
    End Sub


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim i, j, placedQueens As Integer
        If second = 59 Then
            second = -1
            minute += 1
        End If
        If minute = 99 Then
            second = -1
            minute = 0
            Timer1.Enabled = False
            newGame()
        End If
        second += 1
        lblTimer.Text = String.Format("{0:d2}:{1:d2}", minute, second)
        On Error Resume Next
        'On Error GoTo Handler


        For i = 0 To 7
            For j = 0 To 7
                If b1(i, j) = 1 Then placedQueens += 1
            Next
        Next

   
Handler:
        If Err.Number <> 0 Then
            Timer1.Enabled = False
            ErrMsg(Err.Source.ToString)
        End If
    End Sub

    Private Sub FrmGameSurface_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

    End Sub
#End Region
#Region "Help"

    Private Sub ResetHelpBoard()
        Dim column As Integer = 0
        Dim row As Integer = 0
        Dim piece As CGamePiece

        mHelpPieces = New ArrayList
        Dim Ok As Bitmap = PicBxOk.Image


        For row = 0 To b2.GetUpperBound(0)


            For column = 0 To b2.GetUpperBound(1)

                piece = New CGamePiece(column * TILESIZE, row * TILESIZE, Ok)

                If b2(row, column) = 1 Then
                    mHelpPieces.Add(piece)
                End If

            Next

        Next
    End Sub
    Private Sub btnHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHelp.Click
        If Not HelpIsOn Then

            index = 0
            PutQueens()
            ResetHelpBoard()
            Invalidate()

            btnHelp.ForeColor = Color.Red
            btnHelp.Text = "Cancel"
            btnNext.Visible = True
            btnPrevious.Visible = True
            btnNext.Enabled = True
            btnPrevious.Enabled = False
            Sol.Visible = True
            Sol.Text = "Solution No. 1"
            HelpIsOn = True
            dgo.Visible = True
            dgo.Enabled = True
            Button1.Visible = True
            Button1.Enabled = True


        Else
            mHelpPieces = New ArrayList
            HelpIsOn = False
            Sol.Visible = False
            btnHelp.ForeColor = Color.Black
            btnHelp.Text = "Show me!"
            btnNext.Visible = False
            btnPrevious.Visible = False
            dgo.Visible = False
            Button1.Visible = False

            Invalidate()
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If index + 2 = 92 Then
            btnNext.Enabled = False
        Else
            btnNext.Enabled = True
        End If
        If Pssblts.Count <> 0 Then
            btnPrevious.Enabled = True
        End If


        index += 1
        Sol.Text = "Solution No. " & index + 1
        If Pssblts.Count <> 0 And Pssblts.Count \ 8 > index Then
            Dim i As Integer
            b2 = New Integer(7, 7) {}
            For i = index * 8 To (index * 8) + 7
                Dim h, k As Integer
                h = Mid(Pssblts(i), 1, 1)
                k = Mid(Pssblts(i), 3, 1)
                b2(h, k) = 1
            Next
            ResetHelpBoard()
            Invalidate()
        Else
            PutQueens()
            ResetHelpBoard()
            Invalidate()
        End If

    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If index + 1 = 2 Then
            btnPrevious.Enabled = False
        End If
        If index + 1 = 92 Then
            btnNext.Enabled = True
        End If


        index -= 1
        Sol.Text = "Solution No. " & index + 1
        Dim i As Integer
        b2 = New Integer(7, 7) {}
        For i = index * 8 To (index * 8) + 7
            Dim h, k As Integer
            h = Mid(Pssblts(i), 1, 1)
            k = Mid(Pssblts(i), 3, 1)
            b2(h, k) = 1
        Next
        ResetHelpBoard()
        Invalidate()

       
    End Sub
    Private Function GetHelpPiece(ByVal i As Integer) As CGamePiece
        Return CType(mHelpPieces(i), CGamePiece)
    End Function
#End Region
#Region "Mouse behavior"

    Private Sub pieceBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pieceBox.MouseDown
        'On Error GoTo Handler
        On Error Resume Next
        pieceBox.Invalidate()
        mSelectedIndex = CheckBounds(New Point(e.X, e.Y))
        r = New Point(e.X - _
          e.X Mod TILESIZE, e.Y - _
          e.Y Mod TILESIZE)

        Dim container As Rectangle = New Rectangle(0, 0, 360, 360)
        Dim i, j As Integer
        If mSelectedIndex > -1 Then
            Cursor.Current = New Cursor("H_NW.CUR")
            HW_Cursor = True
            If container.Contains(e.X, e.Y) Then

                b1(r.Y / 45, r.X / 45) = 0


                a1 = New Integer(7, 7) {}
                cntr1 = 0
                cntr2 = 0
                For i = 0 To 7
                    For j = 0 To 7
                        If b1(i, j) = 1 Then PutQueens(i, j)
                    Next
                Next


                movedQueen = True
            Else
                movedQueen = False
            End If
        Else
            Cursor.Current = New Cursor("H_MOVE.CUR")
        End If
Handler:
        If Err.Number <> 0 Then
            If Err.Number = 53 Then
                MessageBox.Show("Can not find application files, reinstalling the application may fix this problem.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End If

    End Sub


    Private Sub pieceBox_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pieceBox.MouseMove
        'On Error GoTo Handler
        On Error Resume Next

        Dim changeCursor As Integer = -1
        changeCursor = CheckBounds(New Point(e.X, e.Y))

        If changeCursor > -1 And Not HW_Cursor Then
            pieceBox.Cursor = New Cursor("H_MOVE.CUR")
            Cursor.Current = New Cursor("H_MOVE.CUR")
            HW_Cursor = False
        ElseIf changeCursor = -1 Then
            pieceBox.Cursor = Cursors.Default
        End If

        If mSelectedIndex > -1 Then

            Dim region As Rectangle = New Rectangle(e.X - _
               TILESIZE * 2, e.Y - TILESIZE * 2, TILESIZE * 4, _
               TILESIZE * 4)


            Getpiece(mSelectedIndex).SetLocation(e.X - _
               TILESIZE / 2, e.Y - TILESIZE / 2)


            pieceBox.Invalidate(region)
        End If
Handler:
        If Err.Number <> 0 Then
            If Err.Number = 53 Then
                MessageBox.Show("Can not find application files, reinstalling the application may fix this problem.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End If

    End Sub


    Private Sub pieceBox_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pieceBox.MouseUp
        'On Error GoTo Handler
        On Error Resume Next
        HW_Cursor = False


        Dim remove As Integer = -1
        Static firstGame As Boolean = True

        If mSelectedIndex > -1 Then
            Dim current As Point = New Point(e.X, e.Y)
            Dim newPoint As Point = New Point(current.X - _
               current.X Mod TILESIZE, current.Y - _
               current.Y Mod TILESIZE)
            Dim container As Rectangle = New Rectangle( _
            0, 0, 405, 360)
           
            Dim response As Integer


            remove = CheckBounds(current, mSelectedIndex)

            If (remove > -1) Or (Not (container.Contains( _
            e.X, e.Y))) Then
                If movedQueen Then
                    PutQueens(r.Y / 45, r.X / 45)
                    movedQueen = False
                End If
                returnQueen()
                Exit Sub
            End If
            container.Width = 360
            If container.Contains(e.X, e.Y) Then
                response = PutQueens(newPoint.Y / 45, newPoint.X / 45)
                Select Case response
                    Case 0
                        crossFlag = True
                        crossPoint = New Point(newPoint.X, newPoint.Y)
                        setMarkedQueens(newPoint.Y / 45, newPoint.X / 45)
                        pieceBox.Invalidate()
                        If movedQueen Then
                            PutQueens(r.Y / 45, r.X / 45)
                            movedQueen = False
                        End If
                        saySth(0)
                        returnQueen()
                        Exit Sub
                    Case 1
                        Dim msg As String

                        If firstGame Then
                            msg = "Your time:" & lblTimer.Text & vbCrLf & vbCrLf & "thanks for playing, you may find more possibilities in the ""Show me!""." & vbCrLf & "Enjoy!"
                        Else
                            msg = "Your time:" & lblTimer.Text & vbCrLf & vbCrLf & vbCrLf & "thanks for playing, enjoy!"
                        End If
                        Me.TopMost = False

                        firstGame = False
                        Timer1.Enabled = False

                        pieceBox.Enabled = False
                    Case 2
                        Me.TopMost = False

                        Timer1.Enabled = False

                        newGame()
                        returnQueen()
                        Exit Sub
                End Select
                If Timer1.Enabled = False And response <> 1 Then
                    Timer1.Enabled = True
                End If
            End If

            Getpiece(mSelectedIndex).SetLocation(newPoint.X, _
               newPoint.Y)

            mSelectedIndex = -1

        End If


        pieceBox.Invalidate()
Handler:
        If Err.Number <> 0 Then
            If Err.Number = 53 Then
                MessageBox.Show("Can not find application files, reinstalling the application may fix this problem.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End If
    End Sub

    Private Sub saySth(ByVal messageNo As Integer)
        'On Error GoTo Handler
        On Error Resume Next
        Select Case messageNo
            'Case 0 : Check.Characters("check").Speak("Thats impossible!")
            'Case 1 : Check.Characters("check").MoveTo(Me.Width \ 2 + 220, Me.Height \ 2 - 40)
        End Select
Handler:
        If Err.Number <> 0 Then
            Timer1.Enabled = False
            ErrMsg(Err.Source.ToString)
        End If
    End Sub
#End Region
#Region "Button response to mouse"
    Private Sub btnHelp_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHelp.MouseEnter
        btnHelp.BackColor = Color.LightSteelBlue
        btnHelp.FlatStyle = FlatStyle.Flat
    End Sub

    Private Sub btnHelp_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHelp.MouseLeave
        btnHelp.BackColor = Color.AliceBlue
        btnHelp.FlatStyle = FlatStyle.Standard
    End Sub

    Private Sub btnNewGame_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewGame.MouseEnter
        btnNewGame.BackColor = Color.LightSteelBlue
        btnNewGame.FlatStyle = FlatStyle.Flat
    End Sub

    Private Sub btnNewGame_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewGame.MouseLeave
        btnNewGame.BackColor = Color.AliceBlue
        btnNewGame.FlatStyle = FlatStyle.Standard
    End Sub
#End Region
#Region "MenuItem"
    Private Character As Boolean = True
    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        newGame()
    End Sub

    Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
        Application.Exit()
    End Sub

#End Region

   
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If dgo.Text >= 1 And dgo.Text <= 92 Then
            index = dgo.Text - 1
            Sol.Text = "Solution No. " & index + 1
            If index = 91 Then
                btnNext.Enabled = False
                btnPrevious.Enabled = True
            Else
                If index <> 0 Then
                    btnNext.Enabled = True
                    btnPrevious.Enabled = True
                Else
                    btnPrevious.Enabled = False
                    btnNext.Enabled = True
                End If
            End If
            'If Pssblts.Count <> 0 Then
            'btnPrevious.Enabled = True
            'End If
        Dim z As Integer
        For z = 0 To index
            If Pssblts.Count <> 0 And Pssblts.Count \ 8 > index Then
                Dim i As Integer
                b2 = New Integer(7, 7) {}
                For i = index * 8 To (index * 8) + 7
                    Dim h, k As Integer
                    h = Mid(Pssblts(i), 1, 1)
                    k = Mid(Pssblts(i), 3, 1)
                    b2(h, k) = 1
                Next
                ResetHelpBoard()
                Invalidate()
            Else
                PutQueens()
                ResetHelpBoard()
                Invalidate()
            End If
        Next
        Else
        MsgBox("Solution No not in range Plase!!!! " & Chr(13) & "try again With 1..92", MsgBoxStyle.DefaultButton1 = MsgBoxStyle.Information, "Stop")
        End If
    End Sub
End Class

Project Homepage: