015 Visual Basic 备忘录之游戏进度


1.游戏角色类

Public Class 游戏角色
    '生命力
    Private vit As Integer
    Public Property Vitality
        Get
            Return vit
        End Get
        Set(ByVal value)
            vit = value
        End Set
    End Property
    '攻击力
    Private atk As Integer
    Public Property Attack
        Get
            Return atk
        End Get
        Set(ByVal value)
            atk = value
        End Set
    End Property
    '防御力
    Private def As Integer
    Public Property Defense As Integer
        Get
            Return def
        End Get
        Set(ByVal value As Integer)
            def = value
        End Set
    End Property
    '状态显示
    Public Sub StateDisplay()
        Console.WriteLine("角色当前状态:")
        Console.WriteLine("体力:{0}", Me.vit)
        Console.WriteLine("攻击力:{0}", Me.atk)
        Console.WriteLine("防御力:{0}", Me.def)
        Console.WriteLine()
    End Sub
    '获取初始状态
    Public Sub GetInitState()
        Me.vit = 100
        Me.atk = 100
        Me.def = 100
    End Sub
    '战斗
    Public Sub Fight()
        Me.vit = 0
        Me.atk = 0
        Me.def = 0
    End Sub
    Public Function SaveState() As 角色状态存储箱
        Return New 角色状态存储箱(vit, atk, def)
    End Function

    Public Sub RecoveryState(ByVal memento As 角色状态存储箱)
        Me.vit = memento.vit
        Me.atk = memento.atk
        Me.def = memento.def
    End Sub

End Class

2.角色状态存储箱类

Public Class 角色状态存储箱
    Private _vit As Integer
    Public ReadOnly Property vit As Integer
        Get
            Return _vit
        End Get
    End Property
    Private _atk As Integer
    Public ReadOnly Property atk As Integer
        Get
            Return _atk
        End Get
    End Property
    Private _def As Integer
    Public ReadOnly Property def As Integer
        Get
            Return _def
        End Get
    End Property

    Public Sub New(ByVal v As Integer, ByVal a As Integer, ByVal d As Integer)
        Me._vit = v
        Me._atk = a
        Me._def = d
    End Sub
End Class

3.角色状态管理者类

Public Class 角色状态管理者
    Private _memento As 角色状态存储箱
    Public Property memnto As 角色状态存储箱
        Get
            Return _memento
        End Get
        Set(ByVal value As 角色状态存储箱)
            _memento = value
        End Set
    End Property
End Class

4.客户端

Module Module1

    Sub Main()
        Dim lixiaoyao As New 游戏角色
        Console.WriteLine("战前")
        lixiaoyao.GetInitState()
        lixiaoyao.StateDisplay()

        Dim stateAdmin As 角色状态管理者 = New 角色状态管理者
        stateAdmin.memnto = lixiaoyao.SaveState

        Console.WriteLine("战后")
        lixiaoyao.Fight()
        lixiaoyao.StateDisplay()

        Console.WriteLine("恢复")
        lixiaoyao.RecoveryState(stateAdmin.memnto)
        lixiaoyao.StateDisplay()

        Console.Read()
    End Sub

End Module

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ngbshzhn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值