Wednesday, 22 January 2014

Trying to connect OOP to the design of a game...

As I'm quite interested in game design and development (but am also a newbie in programming), each time I hear a new concept I almost automatically start to think about how it can be applied to a game program.

Each type of game element can be defined as a class. For example, a monster can be initialized in a class:

class Monster:
    """A monster in the game."""

    def __init__(self: 'Monster', hp: int, sp: int, str: int, def: int):
        """A monster which has the given hp, sp, str and def values."""
        self.hp = hp
        self.sp = sp
        self.str = str
        self.def = def

While applying object orientation it makes the code easier to understand. One can define a class of Monster and just create Monster objects which are more apparent than functions explaining what quality each monster has.

Speaking of inheritance of classes, e.g. one can have a class Monster and a subclass BeastMonster which is a Monster which is more vulnerable against some specific spells and tough against some others.

1 comment:

  1. You know... that actually makes a lot of sense. When I had contemplated video games (drawing on my limited programming knowledge), I had more thought about things like decision structures and stuff, and not like thinking about objects and stuff.

    I guess, if we've got classes in this game, we can have a basic class for 'Characters', with a subclass for each Class in the same, and then each player is an instance of that object. (And if we have races in this hypothetical game, we can make those their own classes, and use multiple inheritance!)

    ReplyDelete