标签云

微信群

扫码加入我们

WeChat QR Code

I'm currently working on implementing some form of the game Arkham Horror, and I'm starting to struggle with the vast amount of unique items and events in the game. For example, there are dozens of location events in the game, each of which has a more or less unique implementation. So my reaction would be to solve this with OOP, define a class for all events, and subclass/interface as needed. I've ended up defining classes for objects which will only ever have one instance, leading to over a hundred almost empty classes except for an overridden method. The methods that I'm overriding are also increasing generic: revealLocationEvent: has 20+ different implementations because some reward players, some kill players, some cause the entire game to change state dependent on many variables, some trigger user interaction required events (on a separate UI thread or with an event queue + loop game state machine), some cause the event deck to be reshuffled and drawn from, and some just do nothing.I can't do any sort of dynamic programming in Objective-C, so I can't inject functionality on the fly, which would be my obvious solution. I was wondering what sort of approach you'd take so solve this issue. I also conceptualized a few other solutions, but they all seem more fragile than the next (having gigantic switch-cases inside the non-overridden function based on eventID, etc)


How about using blocks to implement the distinct actions, with a block property in your class?

2019年04月18日33分25秒

That seems like a violation of OOP, members of the same class having different functionality. I'm trying to rethink this from a high level approach. Maybe having each base class having much more capacity and subclasses/implementations dialing unneeded functionality back to 0

2019年04月19日33分25秒

Don't let yourself be hampered in by misguided principles.

2019年04月18日33分25秒

I ended up using something like this approach, but it only slightly helps - for example, in the case of Item Cards, each PlainItem object has about 10 flags which help determine which kind of logic it performs when used.

2019年04月19日33分25秒