473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Design some shared classes that have only constant values

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

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------
Nov 20 '05 #1
3 1872
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?

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Crirus" <Cr****@datagroup.ro> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

Nov 20 '05 #2
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
"Crirus" <Cr****@datagroup.ro> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

Nov 20 '05 #3
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

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
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
"Crirus" <Cr****@datagroup.ro> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------


Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Frank | last post by:
Hi everyone, I have a general class design question. I come from a VB5-6 background where I made applications that used an active x dll to access the database. In the VB world each class was in a...
2
by: Matthew Hood | last post by:
My company has expressed a desire to convert an existing MS Access application to a full VB.NET application. My experience is with VB6 so I want to ask a few questions and get some input on the...
7
by: Iain Mcleod | last post by:
Hi This must be an often encountered problem. I want to declare an abstract class or an interface with nothing but several static constants so that I can use polymorphism when I call each of them...
9
by: Grizlyk | last post by:
Somebody have offered std colors to C++ in the msg here: http://groups.google.com/group/comp.lang.c++/browse_frm/thread/2e5bb3d36ece543b/1acf6cd7e3ebdbcd#1acf6cd7e3ebdbcd The main objection to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.