dimanche 3 septembre 2023

How to pass information to Action class?

So I am trying to build a Roguelike game in Java.

I have a Game class, which holds information about the game like the current map, GUI, Player information, and more.

Entity class, Has a list of Actions it can perform among other fields.

The action needs to check that it can be performed, for this it sometimes needs the current map the entity is in, sometimes some fields of the Entity it is part of, and perhaps in the future some other unknown Class or a field. the player and every other class shouldn't know what the action needs for the checking. They only check if it can be performed and if so perform the action.

My problem is that I don't think I want to couple the instances of sub-classes of action with various elements of the game. I have tried thinking of an elegant solution for passing information to action. I thought perhaps a Mediator pattern but I think I only want the checking to be in the action so it only needs to get information from somewhere, and the type of information may vary wildly from action to action. feel free to ask for clarifications I usually respond quickly.

Aucun commentaire:

Enregistrer un commentaire