VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsLight"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private mX As Integer               'X position of light
Private mY As Integer               'Y position of light
Private mComplex As Integer         'What type of light: 2-way, etc.
Private mState As Integer           'Current state
Private mDuration As Integer        'Time in green in main direction
Private mLeft As Integer            'Time in left turn green
Private mGState As Integer          'Which state is "go" for simulated cars
Private mCaution As Integer         'Time in yellow
Private mStartTime As Integer       'Time until first state transition
Private mLocation As String         'String of light's position
Private mTime As Integer            'Time remaining before state change


Public Property Let X(ByVal vX As Integer)
    mX = vX
End Property
Public Property Get X() As Integer
    X = mX
End Property
Public Property Let Y(ByVal vY As Integer)
    mY = vY
End Property
Public Property Get Y() As Integer
    Y = mY
End Property
Public Property Let Complex(ByVal vComplex As Integer)
    mComplex = vComplex
End Property
Public Property Get Complex() As Integer
    Complex = mComplex
End Property
Public Property Let State(ByVal vState As Integer)
    mState = vState
End Property
Public Property Get State() As Integer
    State = mState
End Property
Public Property Let duration(ByVal vDuration As Integer)
    mDuration = vDuration
End Property
Public Property Get duration() As Integer
    duration = mDuration
End Property
Public Property Let Left(ByVal vLeft As Integer)
    mLeft = vLeft
End Property
Public Property Get Left() As Integer
    Left = mLeft
End Property
Public Property Let Caution(ByVal vCaution As Integer)
    mCaution = vCaution
End Property
Public Property Get Caution() As Integer
    Caution = mCaution
End Property
Public Property Let GState(ByVal vGState As Integer)
    mGState = vGState
End Property
Public Property Get GState() As Integer
    GState = mGState
End Property
Public Property Let StartTime(ByVal vStartTime As Integer)
    mStartTime = vStartTime
End Property
Public Property Get StartTime() As Integer
    StartTime = mStartTime
End Property
Public Property Let Location(ByVal vLocation As String)
    mLocation = vLocation
End Property
Public Property Get Location() As String
    Location = mLocation
End Property
Public Property Let time(ByVal vTime As Integer)
    mTime = vTime
End Property
Public Property Get time() As Integer
    time = mTime
End Property

Public Sub DrawLight(Canvas As Object)
Dim colorA, colorB, colorC, colorD As Integer

   Canvas.FillStyle = 0
   Select Case mComplex
   Case 0                   ' A simple 4way light
      Select Case mState
      Case 0
        colorA = 12  'red
        colorB = 10  'green
      Case 1
        colorA = 12  'red
        colorB = 14  'yellow
      Case 2
        colorA = 10  'green
        colorB = 12  'red
      Case 3
        colorA = 14  'yellow
        colorB = 12  'red
      End Select
      Canvas.FillColor = QBColor(colorA) 'N/S lights
      Canvas.Circle (mX + 100, mY), 50
      Canvas.Circle (mX - 100, mY), 50
      Canvas.FillColor = QBColor(colorB) 'E/W lights
      Canvas.Circle (mX, mY - 100), 50
      Canvas.Circle (mX, mY + 100), 50
      
    Case 1                      ' 4Way light with LeftTurn E/W
      Select Case mState
      Case 0
        colorA = 12  'red
        colorB = 10  'green
        colorC = 12  'red
      Case 1
        colorA = 12  'red
        colorB = 14  'yellow
        colorC = 12  'red
      Case 2
        colorA = 12  'red
        colorB = 12  'red
        colorC = 10  'green
      Case 3
        colorA = 12  'red
        colorB = 12  'red
        colorC = 14  'yellow
      Case 4
        colorA = 10  'green
        colorB = 12  'red
        colorC = 12  'red
      Case 5
        colorA = 14  'yellow
        colorB = 12  'red
        colorC = 12  'red
      End Select
      Canvas.FillColor = QBColor(colorA) 'E/W
      Canvas.Circle (mX + 125, mY - 50), 50
      Canvas.Circle (mX - 125, mY + 50), 50
      Canvas.FillColor = QBColor(colorB) 'N/S
      Canvas.Circle (mX, mY - 100), 50
      Canvas.Circle (mX, mY + 100), 50
      Canvas.FillColor = QBColor(colorC) 'E/W Left
      Canvas.Circle (mX + 125, mY + 50), 50
      Canvas.Circle (mX - 125, mY - 50), 50
    Case 2
      Select Case mState
      Case 0
        colorA = 12  'red
        colorB = 10  'green
        colorC = 12  'red
        colorD = 12  'red
      Case 1
        colorA = 12  'red
        colorB = 14  'yellow
        colorC = 12  'red
        colorD = 12  'red
      Case 2
        colorA = 12  'red
        colorB = 12  'red
        colorC = 10  'green
        colorD = 12  'red
      Case 3
        colorA = 12  'red
        colorB = 12  'red
        colorC = 14  'yellow
        colorD = 12  'red
      Case 4
        colorA = 10  'green
        colorB = 12  'red
        colorC = 12  'red
        colorD = 12  'red
      Case 5
        colorA = 14  'yellow
        colorB = 12  'red
        colorC = 12  'red
        colorD = 12  'red
      Case 6
        colorA = 12  'red
        colorB = 12  'red
        colorC = 12  'red
        colorD = 10  'green
      Case 7
        colorA = 12  'red
        colorB = 12  'red
        colorC = 12  'red
        colorD = 14  'yellow
      End Select

      Canvas.FillColor = QBColor(colorA) 'red
      Canvas.Circle (mX + 125, mY - 50), 50
      Canvas.Circle (mX - 125, mY + 50), 50
      Canvas.FillColor = QBColor(colorB) 'green
      Canvas.Circle (mX - 50, mY - 125), 50
      Canvas.Circle (mX + 50, mY + 125), 50
      Canvas.FillColor = QBColor(colorC)
      Canvas.Circle (mX + 125, mY + 50), 50
      Canvas.Circle (mX - 125, mY - 50), 50
      Canvas.FillColor = QBColor(colorD)
      Canvas.Circle (mX + 50, mY - 125), 50
      Canvas.Circle (mX - 50, mY + 125), 50

    End Select
End Sub
Public Sub AdvanceLight(Canvas As Object)
    mTime = mTime - 1
    If mTime = 0 Then
    Select Case mComplex
    Case 0                  ' simple light
      Select Case mState
      Case 0
        mTime = mCaution
        mState = 1
        DrawLight Canvas
      Case 1
        mTime = mDuration
        mState = 2
        DrawLight Canvas
      Case 2
        mTime = mCaution
        mState = 3
        DrawLight Canvas
      Case 3
        mTime = mDuration
        mState = 0
        DrawLight Canvas
      End Select
    Case 1                  ' complex light, 2 lefts
      Select Case mState
      Case 0
        mTime = mCaution
        mState = 1
        DrawLight Canvas
      Case 1
        mTime = mLeft
        mState = 2
        DrawLight Canvas
      Case 2
        mTime = mCaution
        mState = 3
        DrawLight Canvas
      Case 3
        mTime = mDuration
        mState = 4
        DrawLight Canvas
      Case 4
        mTime = mCaution
        mState = 5
        DrawLight Canvas
      Case 5
        mTime = mDuration
        mState = 0
        DrawLight Canvas
      End Select

    Case 2                  'complex light, 4 lefts
      Select Case mState
      Case 0
        mTime = mCaution
        mState = 1
        DrawLight Canvas
      Case 1
        mTime = mLeft
        mState = 2
        DrawLight Canvas
      Case 2
        mTime = mCaution
        mState = 3
        DrawLight Canvas
      Case 3
        mTime = mDuration
        mState = 4
        DrawLight Canvas
      Case 4
        mTime = mCaution
        mState = 5
        DrawLight Canvas
      Case 5
        mTime = mLeft
        mState = 6
        DrawLight Canvas
      Case 6
        mTime = mCaution
        mState = 7
        DrawLight Canvas
      Case 7
        mTime = mDuration
        mState = 0
        DrawLight Canvas
      End Select
    End Select
    End If

End Sub

Public Sub ClearLight(Canvas As Object)
    Canvas.FillStyle = 0
    Canvas.FillColor = Canvas.BackColor
    Canvas.Line (mX - 180, mY - 180)-(mX + 180, mY + 180), Canvas.BackColor, B
End Sub
