Quick Guestion about Types in Types
BlitzMax Forums/BlitzMax Programming/Quick Guestion about Types in Types
| ||
Im Working on adding different game modes to my program. During a game all logic is handled by TmyLogic Type TmyLogic Field GameLogic 'Type Field Compare 'Type Field Conditions 'Type End Type These are following types are the logic types I dont want to extend as the variatons are to great they only share 1-2 out of 30 methods or functions Type FallLogic End Type Type PlaceLogic End Type Type DynamicLogic End Type My question is how set up Types Field to Hold any of the LogicTypes ie Type TmyLogic Field GameLogic 'Type Field Compare 'Type Field Conditions 'Type Method Create_Classic() GameLogic = New FallLogic End Method Method Create_Puzzel() GameLogic = New PlaceLogic End Method Method Create_DynamicLogic() Gamelogic = New DynamicLogic End Method End Type |
| ||
Make them share the same base type, and cast the appropiate type to get the appropiate logic.Type BaseLogic Function ObjType:Int() abstract End Type Type FallLogic extends BaseLogic Function ObjType:Int() Return 1 End Function End Type Type PlaceLogic extends BaseLogic Function ObjType:Int() Return 2 End Function End Type Type DynamicLogic extends BaseLogic Function ObjType:Int() Return 3 End Function End Type Type TmyLogic Field GameLogic:BaseLogic 'Type Field Compare 'Type Field Conditions 'Type Method Create_Classic() GameLogic = New FallLogic End Method Method Create_Puzzel() GameLogic = New PlaceLogic End Method Method Create_DynamicLogic() Gamelogic = New DynamicLogic End Method End Type You Can always do: If MyTMyLogic.GameLogic.ObjType = 1 then FallLogic(MyTMyLogic.GameLogic).FallLogicSpefficMethod(Params) ElseifMyTMyLogic.GameLogic.ObjType = 2 then PlaceLogic(MyTMyLogic.GameLogic).PlaceLogicSpefficMethod(Params) End If |