Map.Vb
Imports System.Windows
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.IO
Imports System.Windows.Forms
Namespace MinotaurPathfinder
Partial Public Class Map
Inherits Form
Private _pathfinder As New Pathfinder()
Public Sub New()
'
' *
' * Do initializations and events.
' *
' *
Me.Font = SystemFonts.MessageBoxFont
InitializeComponent()
boardControl1.MouseClick += New MouseEventHandler(boardControl1_MouseClick)
boardControl1.MouseMoveSpecial += New EventHandler(boardControl1_MouseMoveSpecial)
toolStripStatusLabel1.Text = ""
End Sub
Public Sub boardControl1_MouseMoveSpecial(ByVal sender As Object, ByVal e As EventArgs)
'
' *
' * Called when the mouse moves to a different square.
' *
' *
Dim point As Point = boardControl1.Pos
If point.X = -1 OrElse point.Y = -1 Then
Return
End If
Dim count As Integer = _pathfinder.Squares(point.X, point.Y).DistanceSteps
If count = 10000 Then
toolStripStatusLabel1.Text = "Impossible"
ElseIf count = 1 Then
toolStripStatusLabel1.Text = "1 step"
ElseIf count = 0 Then
toolStripStatusLabel1.Text = "Current"
Else
toolStripStatusLabel1.Text = count.ToString() + " steps"
End If
End Sub
Public Sub boardControl1_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim point As Point = boardControl1.Pos
If point.X = -1 OrElse point.Y = -1 Then
Return
End If
If e.Button = MouseButtons.Right Then
'
' *
' * Right click isn't implemented!
' *
' *
Return
End If
If _pathfinder.Squares(point.X, point.Y).ContentCode = SquareContent.Empty Then
'
' *
' * Turn an empty square into a wall on click.
' *
' *
_pathfinder.Squares(point.X, point.Y).ContentCode = SquareContent.Wall
Recalculate()
ElseIf _pathfinder.Squares(point.X, point.Y).ContentCode = SquareContent.Wall Then
_pathfinder.Squares(point.X, point.Y).ContentCode = SquareContent.Empty
Recalculate()
End If
End Sub
Private Sub Recalculate()
_pathfinder.ClearLogic()
_pathfinder.Pathfind()
_pathfinder.HighlightPath()
_pathfinder.DrawBoard(boardControl1)
End Sub
Private Sub ReadMap(ByVal fileName As String)
'
' *
' * Read in a map file.
' *
' *
Using reader As New StreamReader(fileName)
Dim lineNum As Integer = 0
Dim line As String
While (InlineAssignHelper(line, reader.ReadLine())) IsNot Nothing
Dim parts As Char() = line.ToCharArray()
Dim i As Integer = 0
While i < parts.Length AndAlso i < 15
_pathfinder.Squares(i, lineNum).FromChar(parts(i))
i += 1
End While
lineNum += 1
End While
End Using
End Sub
Private Sub mapButton_Click(ByVal sender As Object, ByVal e As EventArgs)
'
' *
' * Just deals with the UI.
' *
' *
Dim result As DialogResult = openFileDialog1.ShowDialog()
If result = DialogResult.OK Then
_pathfinder.ClearSquares()
_pathfinder.ClearLogic()
Try
ReadMap(openFileDialog1.FileName)
_pathfinder.Pathfind()
_pathfinder.HighlightPath()
Catch
toolStripStatusLabel1.Text = "IO Error"
Finally
_pathfinder.DrawBoard(boardControl1)
End Try
End If
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
End Class
End NamespaceMap.Designer.Vb
Namespace MinotaurPathfinder
Partial Class Map
''' <summary>
''' Required designer variable.
''' </summary>
Private components As System.ComponentModel.IContainer = Nothing
''' <summary>
''' Clean up any resources being used.
''' </summary>
''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso (components IsNot Nothing) Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
#Region "Windows Form Designer generated code"
''' <summary>
''' Required method for Designer support - do not modify
''' the contents of this method with the code editor.
''' </summary>
Private Sub InitializeComponent()
Me.mapButton = New System.Windows.Forms.Button()
Me.tableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
Me.boardControl1 = New MinotaurPathfinder.BoardControl()
Me.openFileDialog1 = New System.Windows.Forms.OpenFileDialog()
Me.statusStrip1 = New System.Windows.Forms.StatusStrip()
Me.toolStripStatusLabel1 = New System.Windows.Forms.ToolStripStatusLabel()
Me.tableLayoutPanel1.SuspendLayout()
Me.statusStrip1.SuspendLayout()
Me.SuspendLayout()
'
' mapButton
'
Me.mapButton.Anchor = System.Windows.Forms.AnchorStyles.Right
Me.mapButton.Location = New System.Drawing.Point(333, 460)
Me.mapButton.Name = "mapButton"
Me.mapButton.Size = New System.Drawing.Size(75, 23)
Me.mapButton.TabIndex = 1
Me.mapButton.Text = "Open Map"
Me.mapButton.UseVisualStyleBackColor = True
Me.mapButton.Click += New System.EventHandler(Me.mapButton_Click)
'
' tableLayoutPanel1
'
Me.tableLayoutPanel1.Anchor = DirectCast((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.tableLayoutPanel1.ColumnCount = 1
Me.tableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100.0F))
Me.tableLayoutPanel1.Controls.Add(Me.mapButton, 0, 1)
Me.tableLayoutPanel1.Controls.Add(Me.boardControl1, 0, 0)
Me.tableLayoutPanel1.Location = New System.Drawing.Point(13, 12)
Me.tableLayoutPanel1.Name = "tableLayoutPanel1"
Me.tableLayoutPanel1.RowCount = 2
Me.tableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100.0F))
Me.tableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 60.0F))
Me.tableLayoutPanel1.Size = New System.Drawing.Size(411, 502)
Me.tableLayoutPanel1.TabIndex = 2
'
' boardControl1
'
Me.boardControl1.Anchor = System.Windows.Forms.AnchorStyles.None
Me.boardControl1.BackColor = System.Drawing.SystemColors.Window
Me.boardControl1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.boardControl1.Location = New System.Drawing.Point(25, 41)
Me.boardControl1.Name = "boardControl1"
Me.boardControl1.Size = New System.Drawing.Size(360, 360)
Me.boardControl1.TabIndex = 0
'
' openFileDialog1
'
Me.openFileDialog1.Title = "Open Map"
'
' statusStrip1
'
Me.statusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.toolStripStatusLabel1})
Me.statusStrip1.Location = New System.Drawing.Point(0, 504)
Me.statusStrip1.Name = "statusStrip1"
Me.statusStrip1.Size = New System.Drawing.Size(436, 22)
Me.statusStrip1.TabIndex = 3
Me.statusStrip1.Text = "statusStrip1"
'
' toolStripStatusLabel1
'
Me.toolStripStatusLabel1.Name = "toolStripStatusLabel1"
Me.toolStripStatusLabel1.Size = New System.Drawing.Size(118, 17)
Me.toolStripStatusLabel1.Text = "toolStripStatusLabel1"
'
' Map
'
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None
Me.ClientSize = New System.Drawing.Size(436, 526)
Me.Controls.Add(Me.statusStrip1)
Me.Controls.Add(Me.tableLayoutPanel1)
Me.MinimumSize = New System.Drawing.Size(450, 530)
Me.Name = "Map"
Me.Text = "Minotaur Pathfinder"
Me.tableLayoutPanel1.ResumeLayout(False)
Me.statusStrip1.ResumeLayout(False)
Me.statusStrip1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
Private boardControl1 As MinotaurPathfinder.BoardControl
Private mapButton As System.Windows.Forms.Button
Private tableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel
Private openFileDialog1 As System.Windows.Forms.OpenFileDialog
Private statusStrip1 As System.Windows.Forms.StatusStrip
Private toolStripStatusLabel1 As System.Windows.Forms.ToolStripStatusLabel
End Class
End NamespaceHatalarError 1' Public Event Click(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\Users\hakan bey\Documents\Visual Studio 2008\Projects\MinotaurPathfinder\MinotaurPathfinder\Map.Designer.vb 46 13 MinotaurPathfinder Error 3 'Public Event MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\Users\hakan bey\Documents\Visual Studio 2008\Projects\MinotaurPathfinder\MinotaurPathfinder\Map.vb 27 13 MinotaurPathfinder Error 5 'Public Event MouseMoveSpecial(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\Users\hakan bey\Documents\Visual Studio 2008\Projects\MinotaurPathfinder\MinotaurPathfinder\Map.vb 28 13 MinotaurPathfinder Error 2 Delegate 'System.EventHandler' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor. C:\Users\hakan bey\Documents\Visual Studio 2008\Projects\MinotaurPathfinder\MinotaurPathfinder\Map.Designer.vb 46 59 MinotaurPathfinder Error 6 Delegate 'System.EventHandler' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor. C:\Users\hakan bey\Documents\Visual Studio 2008\Projects\MinotaurPathfinder\MinotaurPathfinder\Map.vb 28 64 MinotaurPathfinder Error 4 Delegate 'System.Windows.Forms.MouseEventHandler' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor. C:\Users\hakan bey\Documents\Visual Studio 2008\Projects\MinotaurPathfinder\MinotaurPathfinder\Map.vb 27 63 MinotaurPathfinder