[2005] Game character 'classes'
so I thought making a parent mustinherit type character and having it's subclasses handle the differences in classes would work out well. However I'm having a hard time figuring out a dynamic way to create an instance of the class.
If I write a new subclass of character such as mage or warrior or rogue I would manually have to go back and fill in that possibility at character creation, perhaps miss it or make mistakes.
I'm attempting to use reflection to create the list of classes and instantiate them.
The new call for each of the classes is the same
I was hoping to do something like this and bind it to a datagridview to allow class selection:
Code:
Public Shared Function ClassList() As List(Of System.Collections.Generic.KeyValuePair(Of Type, String))
ClassList = New List(Of KeyValuePair(Of Type, String))
Dim assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim types() As Type = assembly.GetTypes()
For Each item As Type In types
If item.BaseType Is GetType(Character) AndAlso item.DeclaringType IsNot GetType(Character) Then
Stop
' ClassList.Add(item, DirectCast(item, Character).ClassDescription)
Dim methods() As Reflection.MethodInfo = item.GetMethods(Reflection.BindingFlags.Static)
End If
Next
End Function
But even if I managed this I'm not sure how I would go about making a reflected instance creator if that class is selected.
Warrior new for example:
Code:
Public Sub New(ByVal pName As String, ByVal pStrength As Single, ByVal pDexterity As Single _
, ByVal pConstitution As Single, ByVal pIntelligence As Single, ByVal pWisdom As Single _
, ByVal pCharisma As Single, ByVal pLevel As UShort, ByVal pXp As Long _
, ByVal pCreate As Nullable(Of Date), ByVal pMoney As Single)
MyBase.New(pName, pStrength, pDexterity, pConstitution, pIntelligence _
, pWisdom, pCharisma, pLevel, pXp, pCreate, pMoney)
End Sub
so Far all my classes use this same new Code. I thought it best to force all attributes to be present on creation. so there aren't cases where I create a new and forget to set some critical stat or value for the object to function.