Following this thread, I'm making a card game. Currently for my card I just have:
and to hold it in my player class I have:
Which is fine. But now I've decided to add a different type of card, a support card. That looks like this:
My question is, what should I do to store a card? Take this: A monster is a card and a support is a card, but a card isn't necessarily a monster or a card isn't necessarily a support. My issue will come with saving the player because I need to keep serialization in mind.
My initial thought would be to create a structure:
But then, how would that card represent a monster/support? I'm at a loss with this one. I hope I've made my question and point clearly, my mind is a little jumbled right now.
Code:
Option Strict On
Option Explicit On
Public Class Monster
#Region "Properties"
''' <summary>
''' Gets/Sets the name of the monster
''' </summary>
Private _name As String = String.Empty
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
''' <summary>
''' Gets/Sets the health of our monster
''' </summary>
Private hp As Integer = 0
Public Property Health() As Integer
Get
Return hp
End Get
Set(ByVal value As Integer)
hp = value
End Set
End Property
''' <summary>
''' Gets/Sets the attack of our monster
''' </summary>
Private atk As Integer = 0
Public Property Attack() As Integer
Get
Return atk
End Get
Set(ByVal value As Integer)
atk = value
End Set
End Property
''' <summary>
''' Gets/Sets the defence of our monster
''' </summary>
Private def As Integer = 0
Public Property Defence() As Integer
Get
Return def
End Get
Set(ByVal value As Integer)
def = value
End Set
End Property
''' <summary>
''' Gets the true/false value if our monster is in defence mode
''' </summary>
''' <remarks>If the monster is in defence mode, it cannot attack</remarks>
Private in_def As Boolean
Public ReadOnly Property IsInDefence() As Boolean
Get
Return in_def
End Get
End Property
''' <summary>
''' Gets the true/false value if our monster is hidden or not
''' </summary>
''' <remarks>If the monster is hidden, it can neither attack nor can it change from defence or attack mode</remarks>
Private is_hidden As Boolean
Public ReadOnly Property IsHidden() As Boolean
Get
Return is_hidden
End Get
End Property
#End Region
#Region "Methods/Functions"
''' <summary>
''' Attacks an opponent monster
''' </summary>
''' <param name="opponent">The opponents monster</param>
''' <remarks>The fight scene!</remarks>
Public Sub AttackMonster(ByVal opponent As Monster)
If opponent.IsInDefence AndAlso Not (is_hidden) AndAlso Not (in_def) Then
Dim our_atk As Integer = atk - opponent.Defence
If our_atk > 0 Then
opponent.Health -= our_atk
End If
ElseIf Not (is_hidden) AndAlso Not (in_def) Then
opponent.Health -= atk
End If
End Sub
''' <summary>
''' Changes if our monster is in attack or defence mode
''' </summary>
''' <remarks>Cannot change if monster hidden</remarks>
Public Sub ChangeDefenceMode()
If Not (is_hidden) Then
in_def = Not (in_def)
Else
Throw New Exception("Monster is currently hidden, cannot change the IsInDefence property.")
End If
End Sub
''' <summary>
''' Changes if our monster is hidden or not
''' </summary>
Public Sub ChangeHiddenMode()
is_hidden = Not (is_hidden)
End Sub
#End Region
#Region "Initialization"
'The different ways to initialize a monster
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal name_ As String)
_name = name_
End Sub
Public Sub New(ByVal name_ As String, ByVal _hp As Integer)
_name = name_
hp = _hp
End Sub
Public Sub New(ByVal name_ As String, ByVal _hp As Integer, ByVal _atk As Integer)
_name = name_
hp = _hp
atk = _atk
End Sub
Public Sub New(ByVal name_ As String, ByVal _hp As Integer, ByVal _atk As Integer, ByVal _def As Integer)
_name = name_
hp = _hp
atk = _atk
def = _def
End Sub
Public Sub New(ByVal name_ As String, ByVal _hp As Integer, ByVal _atk As Integer, ByVal _def As Integer, ByVal def_mod As Boolean)
_name = name_
hp = _hp
atk = _atk
def = _def
in_def = def_mod
End Sub
Public Sub New(ByVal name_ As String, ByVal _hp As Integer, ByVal _atk As Integer, ByVal _def As Integer, ByVal def_mod As Boolean, ByVal hidden As Boolean)
_name = name_
hp = _hp
atk = _atk
def = _def
in_def = def_mod
is_hidden = hidden
End Sub
#End Region
End Class
Code:
Private _deck As List(Of Monster)
Public Property Deck() As List(Of Monster)
Get
Return _deck
End Get
Set(ByVal value As List(Of Monster))
_deck = value
End Set
End Property
Code:
Option Strict On
Option Explicit On
Public Class Support
#Region "Properties/Enums"
''' <summary>
''' Gets/Sets the name of the support
''' </summary>
Private _name As String = String.Empty
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
''' <summary>
''' The vocation enumerator
''' </summary>
Public Enum Type
Healer
Reviver
AttackRaiser
DefenceRaiser
End Enum
''' <summary>
''' Gets/Sets the type of vocation the supporter is
''' </summary>
Private voc As Type = Type.Healer
Public Property Vocation() As Type
Get
Return voc
End Get
Set(ByVal value As Type)
voc = value
End Set
End Property
''' <summary>
''' Gets/Sets the value
''' </summary>
''' <remarks>The value determines how much will heal or raise a stat</remarks>
Private _val As Integer
Public Property Value() As Integer
Get
Return _val
End Get
Set(ByVal value As Integer)
_val = value
End Set
End Property
#End Region
#Region "Methods"
Public Sub Heal(ByVal monster As Monster)
If monster.Health > 0 AndAlso voc = Type.Healer Then
monster.Health += _val
End If
End Sub
Public Sub Revive(ByVal monster As Monster)
If monster.Health <= 0 AndAlso voc = Type.Reviver Then
monster.Health += _val
End If
End Sub
Public Sub RaiseAttack(ByVal monster As Monster)
If voc = Type.AttackRaiser Then
monster.Attack += _val
End If
End Sub
Public Sub RaiseDefence(ByVal monster As Monster)
If voc = Type.DefenceRaiser Then
monster.Defence += _val
End If
End Sub
#End Region
#Region "Initialization"
'The different ways to initialize a supporter
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal name_ As String)
_name = name_
End Sub
Public Sub New(ByVal name_ As String, ByVal _voc As Type)
_name = name_
voc = _voc
End Sub
Public Sub New(ByVal name_ As String, ByVal _voc As Type, ByVal val_ As Integer)
_name = name_
voc = _voc
_val = val_
End Sub
#End Region
End Class
My initial thought would be to create a structure:
Code:
Public Structure Card
Public Enum Type
Monster
Support
End Enum
Property CardType As Type
End Structure