view gamelib/equipment.py @ 93:1fd56b625b24

Added ability to handle extracting from zip archives after download, although the code is becoming slightly hairy as a result Added some nicely licensed chicken and rooster samples from OLPC
author David Fraser <davidf@sjsoft.com>
date Wed, 02 Sep 2009 11:19:18 +0000
parents 5494af02a0e8
children f5d56688943b
line wrap: on
line source

"""Stuff for animals to use."""

import random

class Equipment(object):
    is_weapon = False

class Weapon(Equipment):
    is_weapon = True

    def in_range(self, gameboard, wielder, target):
        """Can the lucky wielder hit the potentially unlucky target with this?"""
        return False

    def hit(self, gameboard, wielder, target):
        """Is the potentially unlucky target actually unlucky?"""
        return False

class Rifle(Weapon):
    def in_range(self, gameboard, wielder, target):
        """For now, we ignore terrain and just assume we can hit
        anything that isn't too far away."""
        return wielder.pos.dist(target.pos) <= 3

    def hit(self, gameboard, wielder, target):
        """Closer is more accurate."""
        return random.randint(1, 100) > 60 + 10*wielder.pos.dist(target.pos)