'This class represents a single square on a map
Public Class MapElement
Public ElementColor As Color
'more info about elements of a map.
Public Sub New(ByVal sColor As Color)
ElementColor = sColor
End Sub
End Class
'This class represents an entire map made up of MapElements
Public Class Map
'An array of elements within the map
'The array can be resized to any size with ReDim
Private vMapElements(,) As MapElement
Public Sub New(ByVal sSizeX As Integer, ByVal sSizeY As Integer)
ReDim vMapElements(sSizeX, sSizeY)
For i As Integer = 0 To sSizeX - 1
For j As Integer = 0 To sSizeY - 1
vMapElements(i, j) = Nothing
Next
Next
End Sub
'Gets/sets the current element at (X, Y).
'Note that these may be Nothing with the current implementation
Default Public Property Element(ByVal X As Integer, ByVal Y As Integer) As MapElement
Get
Return vMapElements(X, Y)
End Get
Set(ByVal value As MapElement)
vMapElements(X, Y) = value
End Set
End Property
Public ReadOnly Property MapSizeX As Integer
Get
Return vMapElements.GetUpperBound(0)
End Get
End Property
Public ReadOnly Property MapSizeY As Integer
Get
Return vMapElements.GetUpperBound(1)
End Get
End Property
'Draws the current contents of the map into sGraphics using sOffset as
'the upper, left corner.
Public Sub RenderMap(ByVal sGraphics As Graphics, ByVal sOffset As Point, ByVal sSize As Size)
Dim R As Rectangle = New Rectangle
Dim B As New SolidBrush(Color.AliceBlue)
Dim vLocation As Point = sOffset
R.Size = sSize
For i As Integer = 0 To Me.MapSizeX - 1
For j As Integer = 0 To Me.MapSizeY - 1
R.Location = vLocation
'If the element is present then draw it.
If vMapElements(i, j) IsNot Nothing Then
B.Color = vMapElements(i, j).ElementColor
sGraphics.FillRectangle(B, R)
End If
'Update the current location
vLocation.Y += sSize.Height
Next
'Update the current location
vLocation.Y = sOffset.Y
vLocation.X += sSize.Width
Next
End Sub
End Class