diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc index 0d4ce48..f8f3cd6 100644 --- a/src/__pycache__/place.cpython-34.pyc +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc index 0d4ce48..f8f3cd6 100644 --- a/src/__pycache__/place.cpython-34.pyc +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b5f6f5..72cdf70 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc index 0d4ce48..f8f3cd6 100644 --- a/src/__pycache__/place.cpython-34.pyc +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b5f6f5..72cdf70 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index daad88e..7e57b15 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc index 0d4ce48..f8f3cd6 100644 --- a/src/__pycache__/place.cpython-34.pyc +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b5f6f5..72cdf70 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index daad88e..7e57b15 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/interpreter.py b/src/interpreter.py index 04ce2fc..69d7fc1 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -9,6 +9,7 @@ # date: 02/05/2015 # +import os from world import World from define import DefineCommand, define_command_registry @@ -23,13 +24,14 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() + self.world_file_name = world_file_name def load(self, world_file_name): ''' Load a world file and pass it on to the interpreter ''' try: - world_file = open(world_file_name, 'r') + world_file = open(self.world_file_name, 'r') atl_text = world_file.readlines() world_file.close() print("Loaded "+world_file_name) @@ -46,7 +48,7 @@ their key-value to the method to be called when their key appears in an ATL source file. ''' - self.line_command_registry["load"] = self.load + #self.line_command_registry["load"] = self.secondary_load self.line_command_registry["start-place"] = self.world.set_starting_place def interpret_atl(self, atl_source): @@ -96,3 +98,15 @@ # syntax error, or something else? print("Unrecognized syntax in line "+str(line_no)+"!") + def secondary_load(self, atl_file_name): + ''' + --- DO NOT USE --- + + The function that prepares everything before loading in another ATL file + when the 'load' command is called. + + Currently leads to an endless recursion loop. + ''' + world_directory = os.path.split(self.world_file_name)[0] + load_file_name = os.path.join(world_directory, atl_file_name) + self.load(load_file_name) diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc index 0d4ce48..f8f3cd6 100644 --- a/src/__pycache__/place.cpython-34.pyc +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b5f6f5..72cdf70 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index daad88e..7e57b15 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/interpreter.py b/src/interpreter.py index 04ce2fc..69d7fc1 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -9,6 +9,7 @@ # date: 02/05/2015 # +import os from world import World from define import DefineCommand, define_command_registry @@ -23,13 +24,14 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() + self.world_file_name = world_file_name def load(self, world_file_name): ''' Load a world file and pass it on to the interpreter ''' try: - world_file = open(world_file_name, 'r') + world_file = open(self.world_file_name, 'r') atl_text = world_file.readlines() world_file.close() print("Loaded "+world_file_name) @@ -46,7 +48,7 @@ their key-value to the method to be called when their key appears in an ATL source file. ''' - self.line_command_registry["load"] = self.load + #self.line_command_registry["load"] = self.secondary_load self.line_command_registry["start-place"] = self.world.set_starting_place def interpret_atl(self, atl_source): @@ -96,3 +98,15 @@ # syntax error, or something else? print("Unrecognized syntax in line "+str(line_no)+"!") + def secondary_load(self, atl_file_name): + ''' + --- DO NOT USE --- + + The function that prepares everything before loading in another ATL file + when the 'load' command is called. + + Currently leads to an endless recursion loop. + ''' + world_directory = os.path.split(self.world_file_name)[0] + load_file_name = os.path.join(world_directory, atl_file_name) + self.load(load_file_name) diff --git a/src/place.py b/src/place.py index 470332e..5e89425 100644 --- a/src/place.py +++ b/src/place.py @@ -18,12 +18,10 @@ players, monsters, items, NPCs, and links to other places. ''' - def __init__(self, name, description="", - neighbours=[], monsters=[], - npc=[], items=[]): + def __init__(self, name): ''' The constructor for a new place. - Arguments: + Instance variables: name: the name of this place (compulsory) description: a description string neighbours: a list of place names of places bordering on this one @@ -32,11 +30,11 @@ items: a list of instances of items ''' self.name = name - self.description = description - self.neighbours = neighbours - self.monsters = monsters - self.npc = npc - self.items = items + self.description = "" + self.neighbours = [] + self.monsters = [] + self.npc = [] + self.items = [] def set_description(self, description): self.description = description @@ -57,6 +55,9 @@ def remove_neighbour(self, place_name): self.neighbours.remove(place_name) + # XXX The following methods might cause problems if one attempts to + # remove just one instance of a list that contains several similar + # instances. def remove_monster(self, monster): self.monsters.remove(monster) diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc index 0d4ce48..f8f3cd6 100644 --- a/src/__pycache__/place.cpython-34.pyc +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b5f6f5..72cdf70 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index daad88e..7e57b15 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/interpreter.py b/src/interpreter.py index 04ce2fc..69d7fc1 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -9,6 +9,7 @@ # date: 02/05/2015 # +import os from world import World from define import DefineCommand, define_command_registry @@ -23,13 +24,14 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() + self.world_file_name = world_file_name def load(self, world_file_name): ''' Load a world file and pass it on to the interpreter ''' try: - world_file = open(world_file_name, 'r') + world_file = open(self.world_file_name, 'r') atl_text = world_file.readlines() world_file.close() print("Loaded "+world_file_name) @@ -46,7 +48,7 @@ their key-value to the method to be called when their key appears in an ATL source file. ''' - self.line_command_registry["load"] = self.load + #self.line_command_registry["load"] = self.secondary_load self.line_command_registry["start-place"] = self.world.set_starting_place def interpret_atl(self, atl_source): @@ -96,3 +98,15 @@ # syntax error, or something else? print("Unrecognized syntax in line "+str(line_no)+"!") + def secondary_load(self, atl_file_name): + ''' + --- DO NOT USE --- + + The function that prepares everything before loading in another ATL file + when the 'load' command is called. + + Currently leads to an endless recursion loop. + ''' + world_directory = os.path.split(self.world_file_name)[0] + load_file_name = os.path.join(world_directory, atl_file_name) + self.load(load_file_name) diff --git a/src/place.py b/src/place.py index 470332e..5e89425 100644 --- a/src/place.py +++ b/src/place.py @@ -18,12 +18,10 @@ players, monsters, items, NPCs, and links to other places. ''' - def __init__(self, name, description="", - neighbours=[], monsters=[], - npc=[], items=[]): + def __init__(self, name): ''' The constructor for a new place. - Arguments: + Instance variables: name: the name of this place (compulsory) description: a description string neighbours: a list of place names of places bordering on this one @@ -32,11 +30,11 @@ items: a list of instances of items ''' self.name = name - self.description = description - self.neighbours = neighbours - self.monsters = monsters - self.npc = npc - self.items = items + self.description = "" + self.neighbours = [] + self.monsters = [] + self.npc = [] + self.items = [] def set_description(self, description): self.description = description @@ -57,6 +55,9 @@ def remove_neighbour(self, place_name): self.neighbours.remove(place_name) + # XXX The following methods might cause problems if one attempts to + # remove just one instance of a list that contains several similar + # instances. def remove_monster(self, monster): self.monsters.remove(monster) diff --git a/src/player.py b/src/player.py index 9ef72ad..4416ec8 100644 --- a/src/player.py +++ b/src/player.py @@ -14,5 +14,22 @@ The Player class represents a game character. ''' - def __init__(self): - pass + def __init__(self, name, start_health, + character_race, character_class, + start_attributes): + ''' + Create a player. Arguments: + name - The name of the character + start_health - The initial max HP + character_race - a race instance the character belongs to + character_class - a class instance that the character belongs to + start_attributes - A dict containing the player attributes + ('strength', 'constitution', 'dexterity', 'intelligence') + ''' + self.name = name + self.location = "" + self.health = start_health + self.attributes = start_attributes + self.weapons = [] + self.items = [] + diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc index 0d4ce48..f8f3cd6 100644 --- a/src/__pycache__/place.cpython-34.pyc +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b5f6f5..72cdf70 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index daad88e..7e57b15 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/interpreter.py b/src/interpreter.py index 04ce2fc..69d7fc1 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -9,6 +9,7 @@ # date: 02/05/2015 # +import os from world import World from define import DefineCommand, define_command_registry @@ -23,13 +24,14 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() + self.world_file_name = world_file_name def load(self, world_file_name): ''' Load a world file and pass it on to the interpreter ''' try: - world_file = open(world_file_name, 'r') + world_file = open(self.world_file_name, 'r') atl_text = world_file.readlines() world_file.close() print("Loaded "+world_file_name) @@ -46,7 +48,7 @@ their key-value to the method to be called when their key appears in an ATL source file. ''' - self.line_command_registry["load"] = self.load + #self.line_command_registry["load"] = self.secondary_load self.line_command_registry["start-place"] = self.world.set_starting_place def interpret_atl(self, atl_source): @@ -96,3 +98,15 @@ # syntax error, or something else? print("Unrecognized syntax in line "+str(line_no)+"!") + def secondary_load(self, atl_file_name): + ''' + --- DO NOT USE --- + + The function that prepares everything before loading in another ATL file + when the 'load' command is called. + + Currently leads to an endless recursion loop. + ''' + world_directory = os.path.split(self.world_file_name)[0] + load_file_name = os.path.join(world_directory, atl_file_name) + self.load(load_file_name) diff --git a/src/place.py b/src/place.py index 470332e..5e89425 100644 --- a/src/place.py +++ b/src/place.py @@ -18,12 +18,10 @@ players, monsters, items, NPCs, and links to other places. ''' - def __init__(self, name, description="", - neighbours=[], monsters=[], - npc=[], items=[]): + def __init__(self, name): ''' The constructor for a new place. - Arguments: + Instance variables: name: the name of this place (compulsory) description: a description string neighbours: a list of place names of places bordering on this one @@ -32,11 +30,11 @@ items: a list of instances of items ''' self.name = name - self.description = description - self.neighbours = neighbours - self.monsters = monsters - self.npc = npc - self.items = items + self.description = "" + self.neighbours = [] + self.monsters = [] + self.npc = [] + self.items = [] def set_description(self, description): self.description = description @@ -57,6 +55,9 @@ def remove_neighbour(self, place_name): self.neighbours.remove(place_name) + # XXX The following methods might cause problems if one attempts to + # remove just one instance of a list that contains several similar + # instances. def remove_monster(self, monster): self.monsters.remove(monster) diff --git a/src/player.py b/src/player.py index 9ef72ad..4416ec8 100644 --- a/src/player.py +++ b/src/player.py @@ -14,5 +14,22 @@ The Player class represents a game character. ''' - def __init__(self): - pass + def __init__(self, name, start_health, + character_race, character_class, + start_attributes): + ''' + Create a player. Arguments: + name - The name of the character + start_health - The initial max HP + character_race - a race instance the character belongs to + character_class - a class instance that the character belongs to + start_attributes - A dict containing the player attributes + ('strength', 'constitution', 'dexterity', 'intelligence') + ''' + self.name = name + self.location = "" + self.health = start_health + self.attributes = start_attributes + self.weapons = [] + self.items = [] + diff --git a/src/server.py b/src/server.py index 3720a61..2c1ce87 100644 --- a/src/server.py +++ b/src/server.py @@ -31,6 +31,7 @@ print("World loaded. Details:") places = self.world.places.keys() for p in places: - print("Place: "+self.world.get_place(p).name) + print("\nPlace: "+self.world.get_place(p).name) + print("Description: "+self.world.get_place(p).description) print("Neighbours: "+str(self.world.get_place(p).neighbours)) print("Starting place: "+self.world.starting_place) diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc index 0d4ce48..f8f3cd6 100644 --- a/src/__pycache__/place.cpython-34.pyc +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b5f6f5..72cdf70 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index daad88e..7e57b15 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/interpreter.py b/src/interpreter.py index 04ce2fc..69d7fc1 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -9,6 +9,7 @@ # date: 02/05/2015 # +import os from world import World from define import DefineCommand, define_command_registry @@ -23,13 +24,14 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() + self.world_file_name = world_file_name def load(self, world_file_name): ''' Load a world file and pass it on to the interpreter ''' try: - world_file = open(world_file_name, 'r') + world_file = open(self.world_file_name, 'r') atl_text = world_file.readlines() world_file.close() print("Loaded "+world_file_name) @@ -46,7 +48,7 @@ their key-value to the method to be called when their key appears in an ATL source file. ''' - self.line_command_registry["load"] = self.load + #self.line_command_registry["load"] = self.secondary_load self.line_command_registry["start-place"] = self.world.set_starting_place def interpret_atl(self, atl_source): @@ -96,3 +98,15 @@ # syntax error, or something else? print("Unrecognized syntax in line "+str(line_no)+"!") + def secondary_load(self, atl_file_name): + ''' + --- DO NOT USE --- + + The function that prepares everything before loading in another ATL file + when the 'load' command is called. + + Currently leads to an endless recursion loop. + ''' + world_directory = os.path.split(self.world_file_name)[0] + load_file_name = os.path.join(world_directory, atl_file_name) + self.load(load_file_name) diff --git a/src/place.py b/src/place.py index 470332e..5e89425 100644 --- a/src/place.py +++ b/src/place.py @@ -18,12 +18,10 @@ players, monsters, items, NPCs, and links to other places. ''' - def __init__(self, name, description="", - neighbours=[], monsters=[], - npc=[], items=[]): + def __init__(self, name): ''' The constructor for a new place. - Arguments: + Instance variables: name: the name of this place (compulsory) description: a description string neighbours: a list of place names of places bordering on this one @@ -32,11 +30,11 @@ items: a list of instances of items ''' self.name = name - self.description = description - self.neighbours = neighbours - self.monsters = monsters - self.npc = npc - self.items = items + self.description = "" + self.neighbours = [] + self.monsters = [] + self.npc = [] + self.items = [] def set_description(self, description): self.description = description @@ -57,6 +55,9 @@ def remove_neighbour(self, place_name): self.neighbours.remove(place_name) + # XXX The following methods might cause problems if one attempts to + # remove just one instance of a list that contains several similar + # instances. def remove_monster(self, monster): self.monsters.remove(monster) diff --git a/src/player.py b/src/player.py index 9ef72ad..4416ec8 100644 --- a/src/player.py +++ b/src/player.py @@ -14,5 +14,22 @@ The Player class represents a game character. ''' - def __init__(self): - pass + def __init__(self, name, start_health, + character_race, character_class, + start_attributes): + ''' + Create a player. Arguments: + name - The name of the character + start_health - The initial max HP + character_race - a race instance the character belongs to + character_class - a class instance that the character belongs to + start_attributes - A dict containing the player attributes + ('strength', 'constitution', 'dexterity', 'intelligence') + ''' + self.name = name + self.location = "" + self.health = start_health + self.attributes = start_attributes + self.weapons = [] + self.items = [] + diff --git a/src/server.py b/src/server.py index 3720a61..2c1ce87 100644 --- a/src/server.py +++ b/src/server.py @@ -31,6 +31,7 @@ print("World loaded. Details:") places = self.world.places.keys() for p in places: - print("Place: "+self.world.get_place(p).name) + print("\nPlace: "+self.world.get_place(p).name) + print("Description: "+self.world.get_place(p).description) print("Neighbours: "+str(self.world.get_place(p).neighbours)) print("Starting place: "+self.world.starting_place) diff --git a/test b/test new file mode 100644 index 0000000..8a1ec21 --- /dev/null +++ b/test @@ -0,0 +1 @@ +src/atlantis.py --server 88 --world worlds/Example/test.atl diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc index 0d4ce48..f8f3cd6 100644 --- a/src/__pycache__/place.cpython-34.pyc +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b5f6f5..72cdf70 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index daad88e..7e57b15 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/interpreter.py b/src/interpreter.py index 04ce2fc..69d7fc1 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -9,6 +9,7 @@ # date: 02/05/2015 # +import os from world import World from define import DefineCommand, define_command_registry @@ -23,13 +24,14 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() + self.world_file_name = world_file_name def load(self, world_file_name): ''' Load a world file and pass it on to the interpreter ''' try: - world_file = open(world_file_name, 'r') + world_file = open(self.world_file_name, 'r') atl_text = world_file.readlines() world_file.close() print("Loaded "+world_file_name) @@ -46,7 +48,7 @@ their key-value to the method to be called when their key appears in an ATL source file. ''' - self.line_command_registry["load"] = self.load + #self.line_command_registry["load"] = self.secondary_load self.line_command_registry["start-place"] = self.world.set_starting_place def interpret_atl(self, atl_source): @@ -96,3 +98,15 @@ # syntax error, or something else? print("Unrecognized syntax in line "+str(line_no)+"!") + def secondary_load(self, atl_file_name): + ''' + --- DO NOT USE --- + + The function that prepares everything before loading in another ATL file + when the 'load' command is called. + + Currently leads to an endless recursion loop. + ''' + world_directory = os.path.split(self.world_file_name)[0] + load_file_name = os.path.join(world_directory, atl_file_name) + self.load(load_file_name) diff --git a/src/place.py b/src/place.py index 470332e..5e89425 100644 --- a/src/place.py +++ b/src/place.py @@ -18,12 +18,10 @@ players, monsters, items, NPCs, and links to other places. ''' - def __init__(self, name, description="", - neighbours=[], monsters=[], - npc=[], items=[]): + def __init__(self, name): ''' The constructor for a new place. - Arguments: + Instance variables: name: the name of this place (compulsory) description: a description string neighbours: a list of place names of places bordering on this one @@ -32,11 +30,11 @@ items: a list of instances of items ''' self.name = name - self.description = description - self.neighbours = neighbours - self.monsters = monsters - self.npc = npc - self.items = items + self.description = "" + self.neighbours = [] + self.monsters = [] + self.npc = [] + self.items = [] def set_description(self, description): self.description = description @@ -57,6 +55,9 @@ def remove_neighbour(self, place_name): self.neighbours.remove(place_name) + # XXX The following methods might cause problems if one attempts to + # remove just one instance of a list that contains several similar + # instances. def remove_monster(self, monster): self.monsters.remove(monster) diff --git a/src/player.py b/src/player.py index 9ef72ad..4416ec8 100644 --- a/src/player.py +++ b/src/player.py @@ -14,5 +14,22 @@ The Player class represents a game character. ''' - def __init__(self): - pass + def __init__(self, name, start_health, + character_race, character_class, + start_attributes): + ''' + Create a player. Arguments: + name - The name of the character + start_health - The initial max HP + character_race - a race instance the character belongs to + character_class - a class instance that the character belongs to + start_attributes - A dict containing the player attributes + ('strength', 'constitution', 'dexterity', 'intelligence') + ''' + self.name = name + self.location = "" + self.health = start_health + self.attributes = start_attributes + self.weapons = [] + self.items = [] + diff --git a/src/server.py b/src/server.py index 3720a61..2c1ce87 100644 --- a/src/server.py +++ b/src/server.py @@ -31,6 +31,7 @@ print("World loaded. Details:") places = self.world.places.keys() for p in places: - print("Place: "+self.world.get_place(p).name) + print("\nPlace: "+self.world.get_place(p).name) + print("Description: "+self.world.get_place(p).description) print("Neighbours: "+str(self.world.get_place(p).neighbours)) print("Starting place: "+self.world.starting_place) diff --git a/test b/test new file mode 100644 index 0000000..8a1ec21 --- /dev/null +++ b/test @@ -0,0 +1 @@ +src/atlantis.py --server 88 --world worlds/Example/test.atl diff --git a/worlds/Example/test.atl b/worlds/Example/test.atl index 93e5ed5..7c112b8 100644 --- a/worlds/Example/test.atl +++ b/worlds/Example/test.atl @@ -13,4 +13,6 @@ description This is where you want to be when you are six feet under... neighbour Nowhere +load test2.atl + start-place Nowhere \ No newline at end of file diff --git a/src/__pycache__/define.cpython-34.pyc b/src/__pycache__/define.cpython-34.pyc index 5a76759..35ab663 100644 --- a/src/__pycache__/define.cpython-34.pyc +++ b/src/__pycache__/define.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index d1c119d..5f79b87 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc index 0d4ce48..f8f3cd6 100644 --- a/src/__pycache__/place.cpython-34.pyc +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b5f6f5..72cdf70 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index daad88e..7e57b15 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/interpreter.py b/src/interpreter.py index 04ce2fc..69d7fc1 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -9,6 +9,7 @@ # date: 02/05/2015 # +import os from world import World from define import DefineCommand, define_command_registry @@ -23,13 +24,14 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() + self.world_file_name = world_file_name def load(self, world_file_name): ''' Load a world file and pass it on to the interpreter ''' try: - world_file = open(world_file_name, 'r') + world_file = open(self.world_file_name, 'r') atl_text = world_file.readlines() world_file.close() print("Loaded "+world_file_name) @@ -46,7 +48,7 @@ their key-value to the method to be called when their key appears in an ATL source file. ''' - self.line_command_registry["load"] = self.load + #self.line_command_registry["load"] = self.secondary_load self.line_command_registry["start-place"] = self.world.set_starting_place def interpret_atl(self, atl_source): @@ -96,3 +98,15 @@ # syntax error, or something else? print("Unrecognized syntax in line "+str(line_no)+"!") + def secondary_load(self, atl_file_name): + ''' + --- DO NOT USE --- + + The function that prepares everything before loading in another ATL file + when the 'load' command is called. + + Currently leads to an endless recursion loop. + ''' + world_directory = os.path.split(self.world_file_name)[0] + load_file_name = os.path.join(world_directory, atl_file_name) + self.load(load_file_name) diff --git a/src/place.py b/src/place.py index 470332e..5e89425 100644 --- a/src/place.py +++ b/src/place.py @@ -18,12 +18,10 @@ players, monsters, items, NPCs, and links to other places. ''' - def __init__(self, name, description="", - neighbours=[], monsters=[], - npc=[], items=[]): + def __init__(self, name): ''' The constructor for a new place. - Arguments: + Instance variables: name: the name of this place (compulsory) description: a description string neighbours: a list of place names of places bordering on this one @@ -32,11 +30,11 @@ items: a list of instances of items ''' self.name = name - self.description = description - self.neighbours = neighbours - self.monsters = monsters - self.npc = npc - self.items = items + self.description = "" + self.neighbours = [] + self.monsters = [] + self.npc = [] + self.items = [] def set_description(self, description): self.description = description @@ -57,6 +55,9 @@ def remove_neighbour(self, place_name): self.neighbours.remove(place_name) + # XXX The following methods might cause problems if one attempts to + # remove just one instance of a list that contains several similar + # instances. def remove_monster(self, monster): self.monsters.remove(monster) diff --git a/src/player.py b/src/player.py index 9ef72ad..4416ec8 100644 --- a/src/player.py +++ b/src/player.py @@ -14,5 +14,22 @@ The Player class represents a game character. ''' - def __init__(self): - pass + def __init__(self, name, start_health, + character_race, character_class, + start_attributes): + ''' + Create a player. Arguments: + name - The name of the character + start_health - The initial max HP + character_race - a race instance the character belongs to + character_class - a class instance that the character belongs to + start_attributes - A dict containing the player attributes + ('strength', 'constitution', 'dexterity', 'intelligence') + ''' + self.name = name + self.location = "" + self.health = start_health + self.attributes = start_attributes + self.weapons = [] + self.items = [] + diff --git a/src/server.py b/src/server.py index 3720a61..2c1ce87 100644 --- a/src/server.py +++ b/src/server.py @@ -31,6 +31,7 @@ print("World loaded. Details:") places = self.world.places.keys() for p in places: - print("Place: "+self.world.get_place(p).name) + print("\nPlace: "+self.world.get_place(p).name) + print("Description: "+self.world.get_place(p).description) print("Neighbours: "+str(self.world.get_place(p).neighbours)) print("Starting place: "+self.world.starting_place) diff --git a/test b/test new file mode 100644 index 0000000..8a1ec21 --- /dev/null +++ b/test @@ -0,0 +1 @@ +src/atlantis.py --server 88 --world worlds/Example/test.atl diff --git a/worlds/Example/test.atl b/worlds/Example/test.atl index 93e5ed5..7c112b8 100644 --- a/worlds/Example/test.atl +++ b/worlds/Example/test.atl @@ -13,4 +13,6 @@ description This is where you want to be when you are six feet under... neighbour Nowhere +load test2.atl + start-place Nowhere \ No newline at end of file diff --git a/worlds/Example/test2.atl b/worlds/Example/test2.atl new file mode 100644 index 0000000..41dda7a --- /dev/null +++ b/worlds/Example/test2.atl @@ -0,0 +1,6 @@ +# This file is used to test the load command + +define-place Fields of Punishment + description You really, really don't want to be here! + neighbour Nowhere + neighbour Elysium \ No newline at end of file