~divmod-dev/divmod.org/trunk

« back to all changes in this revision

Viewing changes to Imaginary/ExampleGame/examplegame/squeaky.py

  • Committer: Jean-Paul Calderone
  • Date: 2014-06-07 13:26:27 UTC
  • mfrom: (2741.2.2 1320678-remove-imaginary)
  • Revision ID: exarkun@twistedmatrix.com-20140607132627-jz2zhbk9jajamk43
Remove Imaginary.  Find it at <https://github.com/twisted/imaginary>.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- test-case-name: examplegame.test.test_squeaky -*-
2
 
 
3
 
"""
4
 
This module implements an L{ILinkAnnotator} which causes an object to squeak
5
 
when it is moved.  It should serve as a simple example for overriding what
6
 
happens when an action is executed (in this case, 'take' and 'drop').
7
 
"""
8
 
 
9
 
from zope.interface import implements
10
 
 
11
 
from axiom.item import Item
12
 
from axiom.attributes import reference
13
 
 
14
 
from imaginary.iimaginary import IMovementRestriction, IConcept
15
 
from imaginary.events import Success
16
 
from imaginary.enhancement import Enhancement
17
 
from imaginary.objects import Thing
18
 
 
19
 
 
20
 
class Squeaker(Item, Enhancement):
21
 
    """
22
 
    This is an L{Enhancement} which, when installed on a L{Thing}, causes that
23
 
    L{Thing} to squeak when you pick it up.
24
 
    """
25
 
 
26
 
    implements(IMovementRestriction)
27
 
 
28
 
    powerupInterfaces = [IMovementRestriction]
29
 
 
30
 
    thing = reference(allowNone=False,
31
 
                      whenDeleted=reference.CASCADE,
32
 
                      reftype=Thing)
33
 
 
34
 
 
35
 
    def movementImminent(self, movee, destination):
36
 
        """
37
 
        The object enhanced by this L{Squeaker} is about to move - emit a
38
 
        L{Success} event which describes its squeak.
39
 
        """
40
 
        Success(otherMessage=(IConcept(self.thing).capitalizeConcept(),
41
 
                              " emits a faint squeak."),
42
 
                location=self.thing.location).broadcast()