There is a game, many characters. Everyone has their own unique tricks, for example
Бутылка шампанского 1. метнуть пробкой сквозь противника перекручиваясь через себя 2. залить пол алкоголем, заставив противника подскользнуться упасть or
Варвар 1. Кинуть топор вверх, через секунду топор прилетит в голову сопернику 2. Усыпить соперника рогом шляпы в глаз For each character for custom techniques there is a class in which there are three methods: beforeAttack , afterAttack , UpdateAttack . Where beforeAttack and afterAttack are called only once before receiving and after, and UpdateAttack updated 1 time per frame (that is, many). These classes are inherited from the main, which controls the process, something like this:
abstract class CommonCustom { public virtual void beforeAttack() {} public virtual void afterAttack() {} public virtual void UpdateAttack() {} public virtual void ApplyAll() { // тут некое условие, чтоб этот метод вызывался лишь раз! beforeAttack(); // вызывается много раз пока идет прием UpdateAttack(); // тут некое условие, чтоб этот метод вызывался лишь раз! afterAttack(); } } The essence of the problem: I have three methods and each character can have several tricks, it turns out that in each method I write switch/case , for example:
class Test : CommonCustom { public virtual void beforeAttack() { switch attackType { case beerAttack: //do smth break; case capAttack: //do smth break; // и т.д. } } public virtual void afterAttack() { switch attackType { case beerAttack: //do smth break; case capAttack: //do smth break; // и т.д. } } public virtual void UpdateAttack() { switch attackType { case beerAttack: //do smth break; case capAttack: //do smth break; // и т.д. } } } Is it possible to do something in order not to write in every method of swith, but somehow to make the whole thing uniform? Maybe somehow add more classes that need to be implemented or something else.
UpdateAllmethod that is called once per frame. (i.e., 60 times per second) ... it calls theApplyAll()method of the object (player), which is just a character with the classTest. Because Inherited fromCommonCustomApplyAll()also works on it and makes these three methods work. - user221013