Continuing with unit tests

In the previous step we added Cast method to Character class in order to make spellcasting possible. While the method itself works, the actual SpellCastingFactory does not do anything useful. As you can see, I decided that MagicFactory is a poor choice of name in this case and changed it to SpellCastingFactory.

First we need to make the SpellCastingFactory to create us an Action. Following test shows how I envision it working:

def test_creating_action(self):
    Test that action can be created
    action_factory = (ActionFactoryBuilder()
    action = action_factory.get_action(
                                                              direction = 1, 
                                                              spell_name = 'healing wind'))
    assert_that(action, is_not(None))

Nothing too fancy. I’m using ActionFactoryBuilder to create me a configured ActionFactory that has a real implementation of SpellCastingFactory. Code for that is simple and not really interesting.

Following code in SpellCastingFactory makes the test pass:

def get_action(self, parameters):
    Create a spell casting action

    :param parameters: parameters used to control creation
    :type parameters: SpellCastingParameters
    return SpellCastingAction(caster = parameters.caster, 
                                        direction = parameters.direction,
                                        spell = None)

Very simple again, with no checks or constraints. I’m focusing on developing the simplest and easiest case of spellcasting first. After that has been done, I can go back and start adding the complexity.

SpellCastingAction has an instance attribute spell that I’m setting to None. This attribute will hold the actual Spell that is cast. Most likely I’m going to use the effects subsystem for implementing effects of spells. Next step in implementing the magic system is probably going to deal with spell attribute, so that we can have something else than None in place there.

Code in this step can be found in commit:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s