'myを接頭語とした内部メンバと対応するように '外部公開用プロパティがあると仮定してご覧ください 'キャラ、弾、エフェクト、アイテム Class Charactor 'メンバ Private mySpeed As Integer Private myGrip As Integer Private myHP As Integer Private myLifeSpan As Integer = -1 Private myLocation As Point Private myAI As IAI Private myAnimation As IAnimation Private myDeathEffect As IEffect Private myDamagedEffect As IEffect Private myWeapon As IWeapon Overridable ReadOnly Property IsDied() As Boolean Get Return (myHP <= 0) Or (myLifeSpan = 0) End Get End Property Sub Calc(ByVal Data As IBattleData) With Me If Not .myAI Is Nothing Then .myAI.Calc(Me,Data) If Not .myAnimation Is Nothing Then .myAnimation.Calc(Me,Data) If Not .myWeapon Is Nothing Then .myWeapon.Calc(Me,Data) End With If myLifeSpan > 0 Then myLifeSpan -= 1 End Sub Sub Draw(ByVal g As Graphics) '割愛 End Sub '以降割愛 End Class Interface IAI Sub Calc(ByVal Sender As Charactor, ByVal Data As IBattleData) '以降割愛 End Interface Interface IAnimation Sub Calc(ByVal Sender As Charactor, ByVal Data As IBattleData) Sub Draw(ByVal g As Graphics) '以降割愛 End Interface Interface IEffect Sub Invoke(ByVal Sender As Charactor, ByVal Data As IBattleData) '以降割愛 End Interface Interface IWeapon Sub Calc(ByVal Sender As Charactor,ByVal Data As IBattleData) '以降割愛 End Interface Interface IPhase ReadOnly Property Keys As ReadOnlyCollection(Of System.Windows.Forms.Keys) ReadOnly Property Random As Random Sub Calc() Sub Draw(ByVal g As Graphics) Sub KeyDown(ByVal sender As Object , e As KeyEventArges) Sub KeyUp(ByVal sender As Object , e As KeyEventArges) '以降割愛 End Interface Interface IBattlePhase Inherits IPhase ReadOnly Property Enemies As List(Of Charactor) ReadOnly Property EnemiesAtacks As 同上 ReadOnly Property Players As 同上 ReadOnly Property PlayersAtacks As 同上 ReadOnly Property BackEffects As 同上 ReadOnly Property FrontEffects As 同上 '以降割愛 End Interface '読み取りデータとしてCalcが行われている最中に '全てのオブジェクトが閲覧できるデータ。 'オブジェクトの追加は、列挙操作中のコレクションの変更を回避することを目的とし 'このインターフェイス内のAddを用いる。 'このインターフェイスを実装するクラスは 'Calcが終了した後で、Addで追加されたオブジェクトを '実際のコレクションに反映する。 Interface IBattleData ReadOnly Property Keys As ReadOnlyCollection(Of System.Windows.Forms.Keys) ReadOnly Property Random As Random ReadOnly Property Enemies As ReadOnlyCollection(Of Charactor) ReadOnly Property EnemiesAtacks As 同上 ReadOnly Property Players As 同上 ReadOnly Property PlayersAtacks 同上 ReadOnly Property BackEffects As 同上 ReadOnly Property FrontEffects As 同上 Sub AddEnemy (ByVal Enemy As Charactor) Sub AddPlayer(同上) Sub AddEnemiesAtack (同上) Sub AddPlayersAtack (同上) Sub AddBackEffect (同上) Sub AddFrontEffect (同上) Sub RemoveEnemy(ByVal Enemy As Charactor) '以降リムーブもAddと同じように続く。 '実際は、Add、Remove、ReadOnlyCollectionをまとめた 'コレクションを自作する。 'このコードは説明用です。 '以降割愛 End Interface Class BattlePhase Implements IBattlePhase Implements IBattleData '以降割愛 End Class Class HomingAction Implements IAI '以降割愛 End Class Class UserAction Implements IAI '以降割愛 End Class Module BattleFactory Function Stage1() As IBattlePhase Dim Result As New BattlePhase '主人公 Dim Player As New Charactor With Player .HP = 200 .AI = New UserAction End With '敵 Dim SampleEnemy As New Charactor With SampleEnemy .HP = 10 .AI = New HomingAction End With With Result .Players.Add(Player) .Enemies.Add(SampleEnemy) End With Return Result End Function End Module