Saludos Mundo libre.
Te encuentra aburrido y quieres programas algo pero no quieres empesar desde cero pues aqui y con la hayuda de google podras empesar un programa o incluso reprogramar sin tanto esfuezo hay tedejo la liga:
http://www.google.com/codesearch
Encontraras cualquier codigo y si te digo cualquier codigo es porque ya he explorado la web en su totalidad.
Una provadita:
virus.py
import decorator
import states
import creature
import mapgrid
def decorator_factory(decfac): # partial is functools.partial
"decorator_factory(decfac) returns a one-parameter family of decorators"
return decorator.partial(lambda df, param:
decorator.decorator(decorator.partial(df, param)),
decfac)
@decorator_factory
def viral_override(attr, func, obj, *args, **kwargs):
active_virus = obj.virus_active
if not active_virus:
return func(obj, *args, **kwargs)
else:
override_method = getattr(active_virus, attr, func)
return override_method(obj, *args, **kwargs)
class Virus(object):
_states = [states.IdleState(), states.WanderingState(),]
def character(self, obj):
return 'v'
def name(self, obj):
return '%s (viral)' % obj._name
def states(self, obj):
return self._states
def target(self, obj):
if obj._target:
return obj._target
else:
for map_obj in obj.visible_objects:
if isinstance(map_obj, creature.Creature) \
and not map_obj.virus_active:
obj._target = map_obj
return obj._target
return
class ZombieVirus(Virus):
_states = [states.IdleState(), states.WanderingState(),
states.PursuitState(), states.AttackState()]
def character(self, obj):
return 'z'
class BrainVirus(Virus):
_states = [states.IdleState(), states.CommandState(),]
def character(self, obj):
return 'b'
class HoundVirus(Virus):
_states = [states.IdleState(), states.WanderingState(),
states.PursuitState(), states.AttackState()]
def character(self, obj):
return 'c'
def los_range(self, obj):
return obj._los_range / 5
def scent_range(self, obj):
return obj._scent_range * 5
def scent_sensitivity(self, obj):
return obj._scent_sensitivity / 4.0
def target(self, obj):
from_los = Virus.target(self, obj)
if from_los:
return from_los
# From scent
top_left_x = max(obj.position.x - obj.scent_range, 0)
top_left_y = max(obj.position.y - obj.scent_range, 0)
top_left = (top_left_x, top_left_y)
bottom_right_x = min(obj.position.x + obj.scent_range,
obj.position.map.width)
bottom_right_y = min(obj.position.y + obj.scent_range,
obj.position.map.height)
width = bottom_right_x - top_left_x
height = bottom_right_y - top_left_y
maximum_scent = 0.0
maximum_tile = None
for tile in obj.position.map.rect(top_left, width, height):
reduction_factor = mapgrid.distance(tile, obj.position) / obj.scent_range
tile_scent = tile.scent * reduction_factor
if tile_scent > maximum_scent:
maximum_tile = tile
maximum_scent = tile_scent
if maximum_scent > obj.scent_sensitivity:
from_scent = iter(maximum_tile.contents).next()
return from_scent
Saludos Mundo Libre.
No hay comentarios:
Publicar un comentario