Should I use multiple classes for game?

前端 未结 5 1426
悲&欢浪女
悲&欢浪女 2020-12-14 23:24

I\'m considering making a text-based RPG-type program in PHP as both a holiday project and a chance to learn more about PHP and OOP. (Maybe not the best choice in language,

5条回答
  •  忘掉有多难
    2020-12-14 23:37

    Classes are about behaviour, so if different types of monsters in your game behave differently, then model them as different objects. If all monsters basically share the same behaviour (e.g. all having a shared set of properties, all can attack or defend and move), then you can save yourself lots of work if you model them as a single monster class. You can always extend the monster class into specialized classes for monsters that can, e.g., talk.

提交回复
热议问题