Design some shared classes that have only constant values

  • Thread starter Thread starter Crirus
  • Start date Start date
C

Crirus

Hello again

I have this issue.
I need to design a game weapon. I made a base class Weapon
Each weapon have:
- range(max 1-16),
- ToHit array of values that gives percent that should be returned by a
random in order to apply damage to enemy
-Power ... the damage to apply to a hitted target

Now, I need some derived classes from this with specific values

Ex: LightGun:
Range={1,2,3,4,5,6}
ToHit={90,80,70,60,50,40} 'percents needed in order to hit target
Power={10,9,8,7,6,5}
Range can be only the bound of ToHit array, no need to specify it as values

Any gun is applyed to a unit.

I need some ideeas how to implement this

Thanks
 
In addition,
I only need to store particular values for each weapon type, but sometime to
reffer to any of them as weapon

Something like... thisUnit.MyWeapon.toHit and get a specific value as it is
a Light Gun
becasue avery LightGun have the same values for any unit, I dont need
particular instance of LightGun for each unit... but a global object from
wich to extract value toHit for a LigtGun at x range... make any sense?
 
Crirus,
First I would consider making Range, ToHit, and Power a structure or class
itself.

Whether you do the above or not, have you considered passing the values into
the constructor of the base?

Something like:

Public MustInherit Class Weapon

Private ReadOnly m_range() As Integer
Private ReadOnly m_toHit() As Integer
Private ReadOnly m_power() As Single

Protected Sub New(ByVal range() As Integer, ByVal toHit() As
Integer, ByVal power() As Single)
m_range = range
m_toHit = toHit
m_power = power
End Sub

End Class

Public Class LightGun
Inherits Weapon

Public Sub New()
MyBase.New(New Integer() {1, 2, 3, 4, 5, 6}, New Integer() {90,
80, 70, 60, 50, 40}, New Single() {10, 9, 8, 7, 6, 5})
End Sub

End Class

Of course the constructor above, should ensure that all three arrays are the
correct size.

Another option is to make Range, ToHit, & Power MustOverridable in Weapon,
then LightGun would implement it and return the array of values. I would
consider a Template Method for these.

Hope this helps
Jay
 
Ideea is that every particular gun is the same for any unit that use it.. so
I whould like better to have them shared so when I need a LightGun, just
call Lightgun.GetPower(range) or something...

Hey, this give me an ideea :) ... gone to implement

regatds
 
Back
Top