P
P
Philip2013-11-13 11:57:57
C++ / C#
Philip, 2013-11-13 11:57:57

Passing values ​​from object class to handler class

Hello. There was a need to transfer to make the transfer of information from one class to another.

The 'Character' class has variables: Double Health Double Strength.

The task is to pass objects of this class (in our case, two objects) to the Event class, process them there, and return them back. Requires this for the same attack class/function.

The option with the Attack(Character & obj) function seemed to me not very flexible (most likely, Event will process more events than one attack)

Thank you in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BuccapuoH, 2013-11-13
@RussDragon

If the Event class is your own and you are going to build game mechanics on events in general, then if I were you, I would create several event classes for different actions (AttackEvent, MovementEvent, TradeEvent, etc.) and add a field in each ( or a set of fields - for example std::map) in which the data for the event will be stored. In your case - strength and health.

It is better to inherit events from the base Event class so as not to bother with processing.

N
niosus, 2013-11-13
@niosus

I may have misunderstood something, but why don't you just pass these same values ​​for health and strength as attack function parameters?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question