-
Notifications
You must be signed in to change notification settings - Fork 0
/
home_world.py
119 lines (87 loc) · 3.24 KB
/
home_world.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# -*- coding: utf-8 -*-
import directions
import items
import rooms
import universe
# Define items
class BookOnIthkuil(items.Item):
names = set(["book"])
description = "A book titled 'Ithkuil: A Philosophical Design for a " \
"Hypothetical Language'"
def __init__(self):
super(BookOnIthkuil, self).__init__()
self.add_action(self.read)
def read(self, universe):
universe.print(
"Ithkuil: Tram-mļöi hhâsmařpţuktôx.\n\n"
"English: On the contrary, I think it may turn out that this "
"rugged mountain range trails off at some point.\n\n"
"As you read the book your mind briefly lingers on the memories of "
"your childhood learning the intricacies of a language designed "
"to make you think faster. The thinking was that if you learned at "
"a young age it would be become the default language you would "
"think in, enabling you to think faster.")
class Box(items.Item, items.Container):
names = set(["box"])
def __init__(self):
super(Box, self).__init__()
self.is_open = False
self.add_action(self.open)
self.add_action(self.close)
self.add_item(BookOnIthkuil())
@property
def description(self):
if self.is_open:
return "The box has a book inside."
else:
return "A brown cardboard box."
def open(self, universe):
self.is_open = True
universe.print("You open the box.")
def close(self, universe):
self.is_open = False
universe.print("You close the box.")
class Bread(items.Item):
def __init__(self):
super(Bread, self).__init__()
self.add_action(self.eat)
def eat(self, universe):
universe.print("You eat the loaf of bread.")
# Define rooms
class Kitchen(rooms.Room):
title = "The Kitchen"
def __init__(self):
super(Kitchen, self).__init__()
self.light_is_on = False
@property
def description(self):
return "You are in the kitchen. " + self.light() + " There is a pantry east."
def light(self):
if self.light_is_on:
return "The room is brightly lit. You see a candlestick."
else:
return "The lights are off."
class LivingRoom(rooms.Room):
title = "Living Room"
description = "You are in a living room. There isn't much here. On the " \
"floor is a box. In a corner is an aquarium. To the north is a kitchen."
def __init__(self):
super(LivingRoom, self).__init__()
self.add_items([Box()])
class Pantry(rooms.Room):
title = "The Pantry"
description = "You stumble through the darkness and trip over a stale loaf of " \
"bread. As you fall you grab for something to stable yourself. Your hand falls " \
"on the stovetop and is burnt. In a panic you knock over a rack of knives and " \
"they soar into the air before plunging into your back. They puncture your " \
"lungs. In your last moments, you cut yourself a slice of bread."
# Connect rooms
living_room = LivingRoom()
kitchen = Kitchen()
pantry = Pantry()
rooms.connect(living_room, kitchen, directions.NORTH)
rooms.connect(kitchen, pantry, directions.EAST)
def start():
u = universe.Universe(living_room)
while(True):
u.tick()