How best to manage "global" data - Static Class?

C

Chu

I've got a small problem I want to get some input on. I'm trying to
determine the best way to access a set of values. I've decided that I
should do it as either a Static class or as an actual object that I can
pass into each object. Let me attempt to describe the scenario:

During a battle, each player will be in control of X units. Each unit
has a set of values, such as Hitpoints, Shield Points, etc.

G-Man has 10 units. Chu has 10 units and Apep has 10 units.

Chu and Apep both attack G-man. The battle scenario runs Chu's attack
first, then Apep. Both players are attacking the same units belonging
to G-man so those Unit values need to somehow be shared between each of
the "attack objects" belonging to Apep and Chu. What's the best way to
share those unit values?

1- Make a Units class that pre-loads every unit object, then pass a
reference to that object into each of the attack objects and every
other object that uses it?

or

2- Use a static class that pre-loads each unit object, then have each
attack object simply reference the static unit class?


Suggestions? Pro's/con's of each method?

Thanks in advance.

Ry/Chu
 
S

steepyirl

Well, since the units in question belong to "G-man", they're not really
global, are they? What if there is another player in the game who also
has such units?
You should probably just expose the units using getter/setter methods
in the "Player" object - that way anyone else can access them.
 
C

Chu

This particular piece of the program doesn't care who the owner is.
This is the logic part that goes through and processes each turn. All
it cares is that "group of X units" attacks "group of Y units."
 
K

knightowl

Chu and Apep both attack G-man. The battle scenario runs Chu's attack
first, then Apep. Both players are attacking the same units belonging
to G-man so those Unit values need to somehow be shared between each of
the "attack objects" belonging to Apep and Chu. What's the best way to
share those unit values?

Actually the values of Chu and Apep do not need to be shared, or
collected. As the battle insues setter and getter methods can be used.
Moreover a hit method could be developed that is used in an interface
for all the battle objects. As it gets hit it's points far based on
sheild, and other attributes. When the object is dead it can return
false to the attacker attack method.

Bottomline, this does not need to be global. Each object should manage
it's own attack, and dammage points.

HFC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,088
Latest member
JeremyMedl

Latest Threads

Top