Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDinko Galetic <dgaletic@everflame.(none)>2010-06-09 00:48:05 (GMT)
committer Dinko Galetic <dgaletic@everflame.(none)>2010-06-09 00:48:05 (GMT)
commitffc08d7632905e12e6df4aa32a665affdf44be26 (patch)
treed41ca51dd03319f2163fe37ac35e99c3e89f88a7
parent7ff92bdf14596c9f808fc5c13bb1364b18265d3c (diff)
Some minor renaming and comment modifications. Added some newlines.
-rw-r--r--library/pippy/scholar/scholar.py49
1 files changed, 29 insertions, 20 deletions
diff --git a/library/pippy/scholar/scholar.py b/library/pippy/scholar/scholar.py
index 3012021..881912e 100644
--- a/library/pippy/scholar/scholar.py
+++ b/library/pippy/scholar/scholar.py
@@ -2,33 +2,34 @@
### classes
-class Game_object(object):
+class GameObject(object):
def __init__(self):
self.description = "Enter this for every object"
self.methods = ["examine", "look"]
self.aliases = []
#self.ID = get_ID.next()
-class Direction(Game_object):
+class Direction(GameObject):
def __init__(self, name):
- Game_object.__init__(self)
+ GameObject.__init__(self)
self.methods.append("go")
self.name = name
-class Player(Game_object):
+class Player(GameObject):
def __init__(self, name):
- Game_object.__init__(self)
+ GameObject.__init__(self)
self.name = name
self.position = "A room object goes here!"
self.known_commands = ["examine", "go"]
-class Room(Game_object):
+class Room(GameObject):
def __init__(self):
- Game_object.__init__(self)
+ GameObject.__init__(self)
self.contains = []
self.exits = {}
self.methods.append("go")
self.aliases = ["room"]
+
# TODO: Think about the case when two rooms share one object
# (such as a door)
def add_exit(self, through, to, two_way = True):
@@ -50,23 +51,23 @@ def login():
player = Player(name)
return player
-def load():
+def load_game():
pass
-def save():
+def save_game():
pass
# For testing purposes only. Needs some serious design thinking
# about how rooms will behave (how to store the instances).
def create_some_rooms():
starting = Room()
+ balcony = Room()
+
# TODO: exits shouldn't be hardcoded in room descriptions!
starting.description = "Though rather small, this room looks quite cozy, mostly due to an inviting bed. There is a desk by the north wall, with a painting hung low on the wall so that one can easily glance at it while working at the desk. The door and windows keep most of the noise out. There is an exit to the west."
starting.contains = [starting_painting, starting_bed]
- balcony = Room()
- balcony.description = "This is a balcony overlooking the large waterfalls over which this mansion was built. Enormous amounts of water spill over it each second and fall hundreds of meters before hitting the ground. It is no wonder many artists choose this particular room when staying here. There is an exit to the east."
starting.add_exit(West, balcony)
-
+ balcony.description = "This is a balcony overlooking the large waterfalls over which this mansion was built. Enormous amounts of water spill over it each second and fall hundreds of meters before hitting the ground. It is no wonder many artists choose this particular room when staying here. There is an exit to the east."
return [starting, balcony]
def opposite_exit(side):
@@ -114,9 +115,11 @@ def go(player, side):
def unalias(player, player_input):
if player_input == "here" or player_input == "room":
return player.position
+
for exit in player.position.exits:
if exit.name == player_input:
return exit
+
for item in player.position.contains:
if player_input in item.aliases:
return item
@@ -126,27 +129,33 @@ def unalias(player, player_input):
def game_loop():
rooms = create_some_rooms()
player = login()
+
print "Welcome,", player.name
print
- load()
+
+ load_game()
+
player.position = rooms[0]
- command = ""
examine(player, player.position)
+
while True:
command = raw_input("> ")
+ command = command.rstrip()
if command == "quit":
break
command = command.split(" ")
+
# Currently, only two word inputs supported.
- # This will need some major reworking.
+ # This will need some major reworking (a proper parser)
if len(command) < 2 or len(command) > 2:
print "What?"
continue
+
verb = command[0]
obj = command[1]
- # if an item is in the room, you can do it.
- # TODO: also, if it's in the inventory.
+ # if an item is in the room, you can <verb>
+ # TODO: also, if it's in the inventory.
if verb in player.known_commands:
real_obj = unalias(player, obj)
if real_obj == None:
@@ -159,7 +168,7 @@ def game_loop():
else:
print "You don't know how to \"" + verb + "\""
- save()
+ save_game()
print "Goodbye!"
@@ -178,10 +187,10 @@ Down = Direction("down")
####
# Create some objects. They are placed in rooms when rooms are created
# in create_some_rooms() (called from game_loop()).
-starting_painting = Game_object()
+starting_painting = GameObject()
starting_painting.description = "This is a painting of a young couple lying on the grass and hugging. Their eyes are of an extraordinary blue colour. The artist has really managed to capture the look of love on their faces. Oddly, the painting seems to be hanging upside down. On a more careful look, however, you realise that it was painted like this."
starting_painting.aliases = ["painting"]
-starting_bed = Game_object()
+starting_bed = GameObject()
starting_bed.description = "A cozy bed. The maids make it and put fresh sheets each morning."
starting_bed.aliases = ["bed"]