git @ Cat's Eye Technologies The-Swallows / 82dfcba
Add two example stories which are, arguably, different stories. Cat's Eye Technologies 9 years ago
4 changed file(s) with 116 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
0 #!/usr/bin/env python
1
2 #
3 # Example of using _The Swallows_ engine, but not its world,
4 # to produce a different story.
5 #
6
7 from os.path import realpath, dirname, join
8 import sys
9
10 # get the ../src/ directory onto the Python module search path
11 sys.path.insert(0, join(dirname(realpath(sys.argv[0])), '..', 'src'))
12
13 # now we can:
14 from swallows.events import LegacyPublisher
15 from swallows.objects import Location, ProperLocation, Male, Female
16
17 ### world ###
18
19 main_street = ProperLocation("Main Street")
20 butchers = Location("butcher's")
21 bakery = Location("bakery")
22 candlestick_factory = Location("candlestick factory")
23
24 main_street.set_exits(butchers, bakery, candlestick_factory)
25 butchers.set_exits(main_street)
26 bakery.set_exits(main_street)
27 candlestick_factory.set_exits(main_street)
28
29 downtown = (main_street, butchers, bakery, candlestick_factory)
30
31 tweedledee = Male('Tweedledee')
32 tweedledum = Male('Tweedledum')
33
34 ### main ###
35
36 publisher = LegacyPublisher(
37 characters=(
38 tweedledee,
39 tweedledum,
40 ),
41 setting=downtown,
42 title="TERRIBLE EXAMPLE STORY",
43 #debug=True,
44 )
45 publisher.publish()
0 #!/usr/bin/env python
1
2 #
3 # Example of extending _The Swallows_ world to produce a different story.
4 #
5
6 from os.path import realpath, dirname, join
7 import sys
8
9 # get the ../src/ directory onto the Python module search path
10 sys.path.insert(0, join(dirname(realpath(sys.argv[0])), '..', 'src'))
11
12 # now we can:
13 from swallows.events import LegacyPublisher
14 from swallows.objects import Male
15
16 # the following is not good. but it works.
17 # better options would be:
18 # - define the world-specific behaviour of the characters in swallows.world
19 # - (less better) have alice & bob take these objects as dependency injections
20 import swallows.objects
21 import swallows.world
22 swallows.objects.revolver = swallows.world.revolver
23 swallows.objects.brandy = swallows.world.brandy
24 swallows.objects.dead_body = swallows.world.dead_body
25
26 # we extend it by adding a new character
27 fred = Male('Fred')
28
29 ### main ###
30
31 publisher = LegacyPublisher(
32 characters=(
33 swallows.world.alice,
34 swallows.world.bob,
35 fred
36 ),
37 setting=swallows.world.house,
38 title="My _The Swallows_ Fanfic",
39 #debug=True,
40 )
41 publisher.publish()
2727 # pistol instead, as those can jam more easily)
2828 # dear me, someone might actually get shot. then what? another dead body?
2929
30
31 # this will get filled in later
32 ALL_ITEMS = []
33
34 # items that the mechanics need to know about; they will be defined later
35 revolver = None
36 brandy = None
37 dead_body = None
38
3930 ### TOPICS ###
4031
4132 # a "topic" is just what a character has recently had addressed to
8879 ### ACTORS (objects in the world) ###
8980
9081 class Actor(object):
91 def __init__(self, name, location, collector=None):
82 def __init__(self, name, location=None, collector=None):
9283 self.name = name
9384 self.collector = collector
94 self.location = None
9585 self.contents = []
9686 self.enter = ""
9787 self.location = None
178168 print "knowledge of others' decisions:", repr(self.other_decision_about)
179169
180170
171 ### unfortunate externals ###
172
173 # items that the mechanics need to know about; they are defined "for reals"
174 # in swallows.world, which may not even be used, so for now we make stand-in
175 # dummy objects for them
176 revolver = Actor('non-existent revolver')
177 brandy = Actor('non-existent brandy')
178 dead_body = Actor('non-existent dead body')
179
180
181181 ### some mixins for Actors ###
182182
183183 class ProperMixin(object):
231231 ### ANIMATE OBJECTS ###
232232
233233 class Animate(Actor):
234 def __init__(self, name, location, collector=None):
235 Actor.__init__(self, name, location, collector=None)
234 def __init__(self, name, location=None, collector=None):
235 Actor.__init__(self, name, location=location, collector=None)
236236 self.topic = None
237237 # hash of actor object to Memory object
238238 self.memories = {}
761761 return self.noun_
762762
763763 def set_exits(self, *exits):
764 for exit in exits:
765 assert isinstance(exit, Location)
764766 self.exits = exits
765767
766768
2121 # an unspeakable thing in the basement! (don't they have enough excitement
2222 # in their lives?)
2323 # bullets for the revolver
24
25 # this will get filled in later
26 ALL_ITEMS = []
27
28 # items that the mechanics need to know about; they will be defined later
29 revolver = None
30 brandy = None
31 dead_body = None
3224
3325 ### world ###
3426
6456 upstairs_hall, bobs_bedroom, alices_bedroom, study, bathroom,
6557 path_by_the_shed, shed)
6658
67 falcon = Treasure('golden falcon', dining_room)
68 jewels = PluralTreasure('stolen jewels', garage)
59 falcon = Treasure('golden falcon', location=dining_room)
60 jewels = PluralTreasure('stolen jewels', location=garage)
6961
70 cupboards = Container('cupboards', kitchen)
71 liquor_cabinet = Container('liquor cabinet', dining_room)
72 mailbox = Container('mailbox', driveway)
62 cupboards = Container('cupboards', location=kitchen)
63 liquor_cabinet = Container('liquor cabinet', location=dining_room)
64 mailbox = Container('mailbox', location=driveway)
7365
74 bobs_bed = ProperContainer("Bob's bed", bobs_bedroom)
75 alices_bed = ProperContainer("Alice's bed", alices_bedroom)
66 bobs_bed = ProperContainer("Bob's bed", location=bobs_bedroom)
67 alices_bed = ProperContainer("Alice's bed", location=alices_bedroom)
7668
77 brandy = Item('bottle of brandy', liquor_cabinet)
78 revolver = Weapon('revolver', pick([bobs_bed, alices_bed]))
79 dead_body = Horror('dead body', bathroom)
69 brandy = Item('bottle of brandy', location=liquor_cabinet)
70 revolver = Weapon('revolver', location=pick([bobs_bed, alices_bed]))
71 dead_body = Horror('dead body', location=bathroom)
8072
81 alice = Female('Alice', None)
82 bob = Male('Bob', None)
73 alice = Female('Alice')
74 bob = Male('Bob')
8375
84 ALL_ITEMS.extend([falcon, jewels, revolver, brandy])
76 ALL_ITEMS = (falcon, jewels, revolver, brandy)