我为Actor,location和object创建了一些类。 班级地点:
Public Class AdvLocation
Private m_Name As String
Private m_NameAlias As String
Private m_Description As String
Private m_Dark As Byte '0=Dark,
Private m_ExitN As String
Private m_ExitNE As String
Private m_ExitE As String
Private m_ExitSE As String
Private m_ExitS As String
Private m_ExitSW As String
Private m_ExitW As String
Private m_ExitNW As String
Private m_ExitUp As String
Private m_ExitDown As String
Private m_ExitIn As String
Private m_ExitOut As String
Private m_ExitNHidden As Boolean
Private m_ExitNEHidden As Boolean
Private m_ExitEHidden As Boolean
Private m_ExitSEHidden As Boolean
Private m_ExitSHidden As Boolean
Private m_ExitSWHidden As Boolean
Private m_ExitWHidden As Boolean
Private m_ExitNWHidden As Boolean
Private m_ExitUpHidden As Boolean
Private m_ExitDownHidden As Boolean
Private m_ExitInHidden As Boolean
Private m_ExitOutHidden As Boolean
Private m_ExitNLockObj As String
Private m_ExitNELockObj As String
Private m_ExitELockObj As String
Private m_ExitSELockObj As String
Private m_ExitSLockObj As String
Private m_ExitSWLockObj As String
Private m_ExitWLockObj As String
Private m_ExitNWLockObj As String
Private m_ExitUpLockObj As String
Private m_ExitDownLockObj As String
Private m_ExitInLockObj As String
Private m_ExitOutLockObj As String
Public Property Name As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
Public Property NameAlias As String
Get
Return m_NameAlias
End Get
Set(value As String)
m_NameAlias = value
End Set
End Property
Public Property Description As String
Get
Return m_Description
End Get
Set(value As String)
m_Description = value
End Set
End Property
Public Property Dark As Boolean
Get
Return m_Dark
End Get
Set(value As Boolean)
m_Dark = value
End Set
End Property
Public Property ExitN As String
Get
Return m_ExitN
End Get
Set(value As String)
m_ExitN = value
End Set
End Property
Public Property ExitNE As String
Get
Return m_ExitNE
End Get
Set(value As String)
m_ExitNE = value
End Set
End Property
Public Property ExitE As String
Get
Return m_ExitE
End Get
Set(value As String)
m_ExitE = value
End Set
End Property
Public Property ExitSE As String
Get
Return m_ExitSE
End Get
Set(value As String)
m_ExitSE = value
End Set
End Property
Public Property ExitS As String
Get
Return m_ExitS
End Get
Set(value As String)
m_ExitS = value
End Set
End Property
Public Property ExitSW As String
Get
Return m_ExitSW
End Get
Set(value As String)
m_ExitSW = value
End Set
End Property
Public Property ExitW As String
Get
Return m_ExitW
End Get
Set(value As String)
m_ExitW = value
End Set
End Property
Public Property ExitNW As String
Get
Return m_ExitNW
End Get
Set(value As String)
m_ExitNW = value
End Set
End Property
Public Property ExitUp As String
Get
Return m_ExitUp
End Get
Set(value As String)
m_ExitUp = value
End Set
End Property
Public Property ExitDown As String
Get
Return m_ExitDown
End Get
Set(value As String)
m_ExitDown = value
End Set
End Property
Public Property ExitIn As String
Get
Return m_ExitIn
End Get
Set(value As String)
m_ExitIn = value
End Set
End Property
Public Property ExitOut As String
Get
Return m_ExitOut
End Get
Set(value As String)
m_ExitOut = value
End Set
End Property
Public Property ExitNHidden As Boolean
Get
Return m_ExitNHidden
End Get
Set(value As Boolean)
m_ExitNHidden = value
End Set
End Property
Public Property ExitNEHidden As Boolean
Get
Return m_ExitNEHidden
End Get
Set(value As Boolean)
m_ExitNEHidden = value
End Set
End Property
Public Property ExitEHidden As Boolean
Get
Return m_ExitEHidden
End Get
Set(value As Boolean)
m_ExitE = value
End Set
End Property
Public Property ExitSEHidden As Boolean
Get
Return m_ExitSEHidden
End Get
Set(value As Boolean)
m_ExitSE = value
End Set
End Property
Public Property ExitSHidden As Boolean
Get
Return m_ExitSHidden
End Get
Set(value As Boolean)
m_ExitSHidden = value
End Set
End Property
Public Property ExitSWHidden As Boolean
Get
Return m_ExitSWHidden
End Get
Set(value As Boolean)
m_ExitSWHidden = value
End Set
End Property
Public Property ExitWHidden As Boolean
Get
Return m_ExitWHidden
End Get
Set(value As Boolean)
m_ExitWHidden = value
End Set
End Property
Public Property ExitNWHidden As Boolean
Get
Return m_ExitNWHidden
End Get
Set(value As Boolean)
m_ExitNWHidden = value
End Set
End Property
Public Property ExitUpHidden As Boolean
Get
Return m_ExitUpHidden
End Get
Set(value As Boolean)
m_ExitUpHidden = value
End Set
End Property
Public Property ExitDownHidden As Boolean
Get
Return m_ExitDownHidden
End Get
Set(value As Boolean)
m_ExitDownHidden = value
End Set
End Property
Public Property ExitInHidden As Boolean
Get
Return m_ExitInHidden
End Get
Set(value As Boolean)
m_ExitInHidden = value
End Set
End Property
Public Property ExitOutHidden As Boolean
Get
Return m_ExitOutHidden
End Get
Set(value As Boolean)
m_ExitOutHidden = value
End Set
End Property
Public Property ExitNLockObj As String
Get
Return m_ExitNLockObj
End Get
Set(value As String)
m_ExitNLockObj = value
End Set
End Property
Public Property ExitNELockObj As String
Get
Return m_ExitNELockObj
End Get
Set(value As String)
m_ExitNELockObj = value
End Set
End Property
Public Property ExitELockObj As String
Get
Return m_ExitELockObj
End Get
Set(value As String)
m_ExitELockObj = value
End Set
End Property
Public Property ExitSELockObj As String
Get
Return m_ExitSELockObj
End Get
Set(value As String)
m_ExitSELockObj = value
End Set
End Property
Public Property ExitSLockObj As String
Get
Return m_ExitSLockObj
End Get
Set(value As String)
m_ExitSLockObj = value
End Set
End Property
Public Property ExitSWLockObj As String
Get
Return m_ExitSWLockObj
End Get
Set(value As String)
m_ExitSWLockObj = value
End Set
End Property
Public Property ExitWLockObj As String
Get
Return m_ExitWLockObj
End Get
Set(value As String)
m_ExitWLockObj = value
End Set
End Property
Public Property ExitNWLockObj As String
Get
Return m_ExitNWLockObj
End Get
Set(value As String)
m_ExitNWLockObj = value
End Set
End Property
Public Property ExitUpLockObj As String
Get
Return m_ExitUpLockObj
End Get
Set(value As String)
m_ExitUpLockObj = value
End Set
End Property
Public Property ExitDownLockObj As String
Get
Return m_ExitDownLockObj
End Get
Set(value As String)
m_ExitDownLockObj = value
End Set
End Property
Public Property ExitInLockObj As String
Get
Return m_ExitInLockObj
End Get
Set(value As String)
m_ExitInLockObj = value
End Set
End Property
Public Property ExitOutLockObj As String
Get
Return m_ExitOutLockObj
End Get
Set(value As String)
m_ExitOutLockObj = value
End Set
End Property
Public Sub New(ByVal m_Name As String,
ByVal m_NameAlias As String,
ByVal m_Description As String,
ByVal m_Dark As Boolean,
ByVal m_ExitN As String,
ByVal m_ExitNE As String,
ByVal m_ExitE As String,
ByVal m_ExitSE As String,
ByVal m_ExitS As String,
ByVal m_ExitSW As String,
ByVal m_ExitW As String,
ByVal m_ExitNW As String,
ByVal m_ExitUp As String,
ByVal m_ExitDown As String,
ByVal m_ExitIn As String,
ByVal m_ExitOut As String,
ByVal m_ExitNHidden As Boolean,
ByVal m_ExitNEHidden As Boolean,
ByVal m_ExitEHidden As Boolean,
ByVal m_ExitSEHidden As Boolean,
ByVal m_ExitSHidden As Boolean,
ByVal m_ExitSWHidden As Boolean,
ByVal m_ExitWHidden As Boolean,
ByVal m_ExitNWHidden As Boolean,
ByVal m_ExitUpHidden As Boolean,
ByVal m_ExitDownHidden As Boolean,
ByVal m_ExitInHidden As Boolean,
ByVal m_ExitOutHidden As Boolean,
ByVal m_ExitNLockObj As String,
ByVal m_ExitNELockObj As String,
ByVal m_ExitELockObj As String,
ByVal m_ExitSELockObj As String,
ByVal m_ExitSLockObj As String,
ByVal m_ExitSWLockObj As String,
ByVal m_ExitWLockObj As String,
ByVal m_ExitNWLockObj As String,
ByVal m_ExitUpLockObj As String,
ByVal m_ExitDownLockObj As String,
ByVal m_ExitInLockObj As String,
ByVal m_ExitOutLockObj As String)
Name = m_Name
NameAlias = m_NameAlias
Description = m_Description
Dark = m_Dark
ExitN = m_ExitN
ExitNE = m_ExitNE
ExitE = m_ExitE
ExitSE = m_ExitSE
ExitS = m_ExitS
ExitSW = m_ExitSW
ExitW = m_ExitW
ExitNW = m_ExitNW
ExitUp = m_ExitUp
ExitDown = m_ExitDown
ExitIn = m_ExitIn
ExitOut = m_ExitOut
ExitNHidden = m_ExitNHidden
ExitNEHidden = m_ExitNEHidden
ExitEHidden = m_ExitEHidden
ExitSEHidden = m_ExitSEHidden
ExitSHidden = m_ExitSHidden
ExitSWHidden = m_ExitSWHidden
ExitWHidden = m_ExitWHidden
ExitNWHidden = m_ExitNWHidden
ExitUpHidden = m_ExitUpHidden
ExitDownHidden = m_ExitDownHidden
ExitInHidden = m_ExitInHidden
ExitOutHidden = m_ExitOutHidden
ExitNLockObj = m_ExitNLockObj
ExitNELockObj = m_ExitNELockObj
ExitELockObj = m_ExitELockObj
ExitSELockObj = m_ExitSELockObj
ExitSLockObj = m_ExitSLockObj
ExitSWLockObj = m_ExitSWLockObj
ExitWLockObj = m_ExitWLockObj
ExitNWLockObj = m_ExitNWLockObj
End Sub
End Class
在主窗体中声明List(of T):
Public Class frmMain
'Declare variables and lists
Public Shared lngScore As Long = 0
Public Shared MaxScore = 100
Public Shared strScreen As String = ""
Public Shared blnSave As Boolean = True
Public Shared strCurLocation As String
Public Shared Locations As New List(Of AdvLocation)
Public Shared Actors As New List(Of AdvActor)
Public Shared Objs As New List(Of AdvObject)
在子InitLoc中,位置将添加到列表中:
'Locations
Public Sub InitLoc()
Locations.Add(New AdvLocation("doorstep1", "Cindy's house", "You are in front of your girlfriends house.", False, _
"hallway1", "", "", "", "", "", "", "", "", "", "", "", _
False, False, False, False, False, False, False, False, False, False, False, False, _
"", "", "", "", "", "", "", "", "", "", "", ""))
Locations.Add(New AdvLocation("hallway1", "Hallway", "You are standing in the hallway.", False, _
"", "", "", "", "", "", "", "", "", "", "", "", _
False, False, False, False, "doorstep1", False, False, False, False, False, False, False, _
"", "", "", "", "", "", "", "", "", "", "", ""))
End Sub
这就出现了问题:第一个位置会按原样添加到列表中,但第二个位置不会被添加,也不会覆盖第一个位置。我也没有得到任何错误,要么它没有执行第二次添加,要么它会生成一个未显示的错误。
代码应该是正确的,但也许不是。 要完成,还没有错误陷阱。 我希望有人可以帮助我。
答案 0 :(得分:0)
我不确定您为什么不将变量声明为公共属性而不是底部的所有方法。 get和set方法包含在属性数据类型中。
其次,您可以创建两个数组来保存这些对象以避免列表。
我猜这一路上,变量或类型正在混淆。如plutonix所说的严格转向选项应该揭示任何问题。