import abc
class AbstractEnemyFactory( object ):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def createNinja( self, name ):
pass
@abc.abstractmethod
def createSwordsman( self, name ):
pass
class LowLevelEnemyFactory( AbstractEnemyFactory ):
def createNinja( self, name ):
return LowLevelEnemyNinja( name = name )
def createSwordsman( self, name ):
return LowLevelEnemySwordsman( name = name )
class HighLevelEnemyFactory( AbstractEnemyFactory ):
def createNinja( self, name ):
return HighLevelEnemyNinja( name )
def createSwordsman( self, name ):
return HighLevelEnemySwordsman( name )
class EnemyNinja( object ):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def ninjutsu_attack( self ):
pass
class LowLevelEnemyNinja( EnemyNinja ):
def __init__( self, name = 'LowLevelEnemyNinja' ):
self._name = name
self._chakra = 100
self._attack_power = 5
self._speed = 10
def ninjutsu_attack( self ):
print 'Ninja use ninjutsu.'
print '[%s]: my chakra is %s and the power of attack is %s'\
%( self._name, self._chakra, self._attack_power )
class HighLevelEnemyNinja( EnemyNinja ):
def __init__( self, name = 'HighLevelEnemyNinja' ):
self._name = name
self._chakra = 300
self._attack_power = 15
self._speed = 20
def ninjutsu_attack( self ):
print 'Ninja use ninjutsu.'
print '[%s]: my chakra is %s and the power of attack is %s'\
%( self._name, self._chakra, self._attack_power )
def special_effect( self ):
print '[%s]: special effect!'%( self._name )
class EnemySwordsman( object ):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def swords_attack( self ):
pass
class LowLevelEnemySwordsman( EnemySwordsman ):
def __init__( self, name = 'LowLevelEnemySwordsman' ):
self._name = name
self._blood = 100
self._attack_power = 5
self._speed = 10
def swords_attack( self ):
print 'Swordsman use swords.'
print '[%s]: my blood is %s and the power of attack is %s'\
%( self._name, self._blood, self._attack_power )
class HighLevelEnemySwordsman( EnemySwordsman ):
def __init__( self, name = 'HighLevelEnemySwordsman' ):
self._name = name
self._blood = 300
self._attack_power = 30
self._speed = 30
def swords_attack( self ):
print 'Swordsman use swords.'
print '[%s]: my blood is %s and the power of attack is %s'\
%( self._name, self._blood, self._attack_power )
def special_effect( self ):
print '[%s]: special effect!'%( self._name )
if __name__ == '__main__':
h = HighLevelEnemyFactory()
ninja = h.createNinja( name = 'Scheme' )
ninja.ninjutsu_attack()
ninja.special_effect()
swordsman = h.createSwordsman( name = 'Lambda' )
swordsman.swords_attack()
swordsman.special_effect()