diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc new file mode 100644 index 0000000..57d9260 --- /dev/null +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc new file mode 100644 index 0000000..57d9260 --- /dev/null +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc new file mode 100644 index 0000000..2b63657 --- /dev/null +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc new file mode 100644 index 0000000..57d9260 --- /dev/null +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc new file mode 100644 index 0000000..2b63657 --- /dev/null +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 7b79720..68761e2 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,10 +7,11 @@ # date: 02/05/2015 # -VERSION = (0, 0, 1) #release, major revision, minor revision +VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys -from parser import Parser +from server import Server +from client import Client def print_version(): @@ -19,17 +20,35 @@ print("Licensed under the terms of the GNU General Public License v3.") def print_help(): + help_text = """ +Usage: atlantis [options] + + --help -h Print this help text and exit + --version -v Print the version number and exit + --server -s Start an Atlantis server + --world Use as the world file (implies --server) + --client : Connect as a client to the server at : + +By default, atlantis starts a client instance and asks for all necessary input. +""" print_version() - print("\nHelp text not yet available.") + print(help_text) def main(): if "--version" in sys.argv or "-v" in sys.argv: print_version() elif "--help" in sys.argv or "-h" in sys.argv: print_help() elif "--world" in sys.argv: world_file = sys.argv[sys.argv.index("--world")+1] - Parser(world_file) + Server(world_file) + elif "--server" in sys.argv or "-s" in sys.argv: + Server() + elif "--client" in sys.argv: + server_address = sys.argv[sys.argv.index("--client")+1] + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) else: - print("Interactive mode not yet available!") + Client() if __name__ == "__main__": main() diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc new file mode 100644 index 0000000..57d9260 --- /dev/null +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc new file mode 100644 index 0000000..2b63657 --- /dev/null +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 7b79720..68761e2 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,10 +7,11 @@ # date: 02/05/2015 # -VERSION = (0, 0, 1) #release, major revision, minor revision +VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys -from parser import Parser +from server import Server +from client import Client def print_version(): @@ -19,17 +20,35 @@ print("Licensed under the terms of the GNU General Public License v3.") def print_help(): + help_text = """ +Usage: atlantis [options] + + --help -h Print this help text and exit + --version -v Print the version number and exit + --server -s Start an Atlantis server + --world Use as the world file (implies --server) + --client : Connect as a client to the server at : + +By default, atlantis starts a client instance and asks for all necessary input. +""" print_version() - print("\nHelp text not yet available.") + print(help_text) def main(): if "--version" in sys.argv or "-v" in sys.argv: print_version() elif "--help" in sys.argv or "-h" in sys.argv: print_help() elif "--world" in sys.argv: world_file = sys.argv[sys.argv.index("--world")+1] - Parser(world_file) + Server(world_file) + elif "--server" in sys.argv or "-s" in sys.argv: + Server() + elif "--client" in sys.argv: + server_address = sys.argv[sys.argv.index("--client")+1] + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) else: - print("Interactive mode not yet available!") + Client() if __name__ == "__main__": main() diff --git a/src/client.py b/src/client.py new file mode 100644 index 0000000..93a18e3 --- /dev/null +++ b/src/client.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This is the client module that the player interacts with. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Client(object): + ''' + The client is the interface between the player and the server. + ''' + + def __init__(self, server_ip=None, server_port=None): + if not (server_ip and server_port): + print("What server IP do you want to connect to?") + server_ip = input(">> ") + print("What port are you using?") + server_port = input(">> ") + print("The client would connect to "+server_ip+":"+server_port) diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc new file mode 100644 index 0000000..57d9260 --- /dev/null +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc new file mode 100644 index 0000000..2b63657 --- /dev/null +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 7b79720..68761e2 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,10 +7,11 @@ # date: 02/05/2015 # -VERSION = (0, 0, 1) #release, major revision, minor revision +VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys -from parser import Parser +from server import Server +from client import Client def print_version(): @@ -19,17 +20,35 @@ print("Licensed under the terms of the GNU General Public License v3.") def print_help(): + help_text = """ +Usage: atlantis [options] + + --help -h Print this help text and exit + --version -v Print the version number and exit + --server -s Start an Atlantis server + --world Use as the world file (implies --server) + --client : Connect as a client to the server at : + +By default, atlantis starts a client instance and asks for all necessary input. +""" print_version() - print("\nHelp text not yet available.") + print(help_text) def main(): if "--version" in sys.argv or "-v" in sys.argv: print_version() elif "--help" in sys.argv or "-h" in sys.argv: print_help() elif "--world" in sys.argv: world_file = sys.argv[sys.argv.index("--world")+1] - Parser(world_file) + Server(world_file) + elif "--server" in sys.argv or "-s" in sys.argv: + Server() + elif "--client" in sys.argv: + server_address = sys.argv[sys.argv.index("--client")+1] + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) else: - print("Interactive mode not yet available!") + Client() if __name__ == "__main__": main() diff --git a/src/client.py b/src/client.py new file mode 100644 index 0000000..93a18e3 --- /dev/null +++ b/src/client.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This is the client module that the player interacts with. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Client(object): + ''' + The client is the interface between the player and the server. + ''' + + def __init__(self, server_ip=None, server_port=None): + if not (server_ip and server_port): + print("What server IP do you want to connect to?") + server_ip = input(">> ") + print("What port are you using?") + server_port = input(">> ") + print("The client would connect to "+server_ip+":"+server_port) diff --git a/src/parser.py b/src/parser.py index d17135e..002790f 100644 --- a/src/parser.py +++ b/src/parser.py @@ -1,21 +1,48 @@ #!/usr/bin/python3 # # Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. +# This module reads in a world file and parses it. This is where the +# structure of the Atlantis language is defined. # # Licensed under the terms of the GPLv3 # author: Daniel Vedder # date: 02/05/2015 # +from world import World + + +class OptionCommand(object): + ''' + This is the super class for all option commands. (A define command + includes one or more option commands.) + ''' + + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + + def act(self, arg): + ''' + Carry out this option commands action with argument arg. + Has to be extended by subclasses! + ''' + raise NotImplementedError + + class DefineCommand(object): ''' This is the super class for all define commands. It should be extended for each individual command, like define-place, define-monster, etc. ''' - def __init__(self): - pass + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + self.option_registry = [] + + def add_option(self, option_command): + self.option_registry.append(option_command) class Parser(object): @@ -25,4 +52,7 @@ ''' def __init__(self, world_file): - print("Loading world file '"+world_file+"'...") + self.world_file = world_file + + def generate_world(self): + return World() diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc new file mode 100644 index 0000000..57d9260 --- /dev/null +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc new file mode 100644 index 0000000..2b63657 --- /dev/null +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 7b79720..68761e2 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,10 +7,11 @@ # date: 02/05/2015 # -VERSION = (0, 0, 1) #release, major revision, minor revision +VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys -from parser import Parser +from server import Server +from client import Client def print_version(): @@ -19,17 +20,35 @@ print("Licensed under the terms of the GNU General Public License v3.") def print_help(): + help_text = """ +Usage: atlantis [options] + + --help -h Print this help text and exit + --version -v Print the version number and exit + --server -s Start an Atlantis server + --world Use as the world file (implies --server) + --client : Connect as a client to the server at : + +By default, atlantis starts a client instance and asks for all necessary input. +""" print_version() - print("\nHelp text not yet available.") + print(help_text) def main(): if "--version" in sys.argv or "-v" in sys.argv: print_version() elif "--help" in sys.argv or "-h" in sys.argv: print_help() elif "--world" in sys.argv: world_file = sys.argv[sys.argv.index("--world")+1] - Parser(world_file) + Server(world_file) + elif "--server" in sys.argv or "-s" in sys.argv: + Server() + elif "--client" in sys.argv: + server_address = sys.argv[sys.argv.index("--client")+1] + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) else: - print("Interactive mode not yet available!") + Client() if __name__ == "__main__": main() diff --git a/src/client.py b/src/client.py new file mode 100644 index 0000000..93a18e3 --- /dev/null +++ b/src/client.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This is the client module that the player interacts with. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Client(object): + ''' + The client is the interface between the player and the server. + ''' + + def __init__(self, server_ip=None, server_port=None): + if not (server_ip and server_port): + print("What server IP do you want to connect to?") + server_ip = input(">> ") + print("What port are you using?") + server_port = input(">> ") + print("The client would connect to "+server_ip+":"+server_port) diff --git a/src/parser.py b/src/parser.py index d17135e..002790f 100644 --- a/src/parser.py +++ b/src/parser.py @@ -1,21 +1,48 @@ #!/usr/bin/python3 # # Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. +# This module reads in a world file and parses it. This is where the +# structure of the Atlantis language is defined. # # Licensed under the terms of the GPLv3 # author: Daniel Vedder # date: 02/05/2015 # +from world import World + + +class OptionCommand(object): + ''' + This is the super class for all option commands. (A define command + includes one or more option commands.) + ''' + + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + + def act(self, arg): + ''' + Carry out this option commands action with argument arg. + Has to be extended by subclasses! + ''' + raise NotImplementedError + + class DefineCommand(object): ''' This is the super class for all define commands. It should be extended for each individual command, like define-place, define-monster, etc. ''' - def __init__(self): - pass + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + self.option_registry = [] + + def add_option(self, option_command): + self.option_registry.append(option_command) class Parser(object): @@ -25,4 +52,7 @@ ''' def __init__(self, world_file): - print("Loading world file '"+world_file+"'...") + self.world_file = world_file + + def generate_world(self): + return World() diff --git a/src/place.py b/src/place.py new file mode 100644 index 0000000..05fe873 --- /dev/null +++ b/src/place.py @@ -0,0 +1,91 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This module contains the code for a place (a delimited location +# in the world). +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +from parser import DefineCommand + + +class Place(object): + ''' + A Place is one discrete location in the game world, which can contain + players, monsters, items, NPCs, and links to other places. + ''' + + def __init__(self, name, description, + neighbours=[], monsters=[], + npc=[], items=[]): + ''' + The constructor for a new place. + Arguments: + name: the name of this place + description: a description string + neighbours: a list of place names of places bordering on this one + monsters: a list of instances of monsters + npc: a list of instances of NPCs + 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 + + def add_neighbour(self, place_name): + if place_name not in self.neighbours: + self.neighbours.append(place_name) + + def add_monster(self, monster): + self.monsters.append(monster) + + def add_npc(self, npc): + self.npc.append(npc) + + def add_item(self, item): + self.items.append(item) + + def remove_neighbour(self, place_name): + self.neighbours.remove(place_name) + + def remove_monster(self, monster): + self.monsters.remove(monster) + + def remove_npc(self, npc): + self.npc.remove(npc) + + def remove_item(self, item): + self.items.remove(item) + + +class NeighbourOption(OptionCommand): + ''' + Add a new neighbour to the current place + ''' + + def __init__(self, place): + OptionCommand.__init__("neighbour", + "Add the place given in the argument as a neighbour") + self.place = place + + def act(self, arg): + self.place.add_neighbour(arg) + + +class DefinePlace(DefineCommand): + ''' + The Atlantis language construct to create a place. + ''' + + def __init__(self, place): + DefineCommand.__init__("define-place", + "Describe a new location in the game world") + self.place = place + self.add_option(NeighbourOption(self.place)) + diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc new file mode 100644 index 0000000..57d9260 --- /dev/null +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc new file mode 100644 index 0000000..2b63657 --- /dev/null +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 7b79720..68761e2 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,10 +7,11 @@ # date: 02/05/2015 # -VERSION = (0, 0, 1) #release, major revision, minor revision +VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys -from parser import Parser +from server import Server +from client import Client def print_version(): @@ -19,17 +20,35 @@ print("Licensed under the terms of the GNU General Public License v3.") def print_help(): + help_text = """ +Usage: atlantis [options] + + --help -h Print this help text and exit + --version -v Print the version number and exit + --server -s Start an Atlantis server + --world Use as the world file (implies --server) + --client : Connect as a client to the server at : + +By default, atlantis starts a client instance and asks for all necessary input. +""" print_version() - print("\nHelp text not yet available.") + print(help_text) def main(): if "--version" in sys.argv or "-v" in sys.argv: print_version() elif "--help" in sys.argv or "-h" in sys.argv: print_help() elif "--world" in sys.argv: world_file = sys.argv[sys.argv.index("--world")+1] - Parser(world_file) + Server(world_file) + elif "--server" in sys.argv or "-s" in sys.argv: + Server() + elif "--client" in sys.argv: + server_address = sys.argv[sys.argv.index("--client")+1] + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) else: - print("Interactive mode not yet available!") + Client() if __name__ == "__main__": main() diff --git a/src/client.py b/src/client.py new file mode 100644 index 0000000..93a18e3 --- /dev/null +++ b/src/client.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This is the client module that the player interacts with. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Client(object): + ''' + The client is the interface between the player and the server. + ''' + + def __init__(self, server_ip=None, server_port=None): + if not (server_ip and server_port): + print("What server IP do you want to connect to?") + server_ip = input(">> ") + print("What port are you using?") + server_port = input(">> ") + print("The client would connect to "+server_ip+":"+server_port) diff --git a/src/parser.py b/src/parser.py index d17135e..002790f 100644 --- a/src/parser.py +++ b/src/parser.py @@ -1,21 +1,48 @@ #!/usr/bin/python3 # # Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. +# This module reads in a world file and parses it. This is where the +# structure of the Atlantis language is defined. # # Licensed under the terms of the GPLv3 # author: Daniel Vedder # date: 02/05/2015 # +from world import World + + +class OptionCommand(object): + ''' + This is the super class for all option commands. (A define command + includes one or more option commands.) + ''' + + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + + def act(self, arg): + ''' + Carry out this option commands action with argument arg. + Has to be extended by subclasses! + ''' + raise NotImplementedError + + class DefineCommand(object): ''' This is the super class for all define commands. It should be extended for each individual command, like define-place, define-monster, etc. ''' - def __init__(self): - pass + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + self.option_registry = [] + + def add_option(self, option_command): + self.option_registry.append(option_command) class Parser(object): @@ -25,4 +52,7 @@ ''' def __init__(self, world_file): - print("Loading world file '"+world_file+"'...") + self.world_file = world_file + + def generate_world(self): + return World() diff --git a/src/place.py b/src/place.py new file mode 100644 index 0000000..05fe873 --- /dev/null +++ b/src/place.py @@ -0,0 +1,91 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This module contains the code for a place (a delimited location +# in the world). +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +from parser import DefineCommand + + +class Place(object): + ''' + A Place is one discrete location in the game world, which can contain + players, monsters, items, NPCs, and links to other places. + ''' + + def __init__(self, name, description, + neighbours=[], monsters=[], + npc=[], items=[]): + ''' + The constructor for a new place. + Arguments: + name: the name of this place + description: a description string + neighbours: a list of place names of places bordering on this one + monsters: a list of instances of monsters + npc: a list of instances of NPCs + 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 + + def add_neighbour(self, place_name): + if place_name not in self.neighbours: + self.neighbours.append(place_name) + + def add_monster(self, monster): + self.monsters.append(monster) + + def add_npc(self, npc): + self.npc.append(npc) + + def add_item(self, item): + self.items.append(item) + + def remove_neighbour(self, place_name): + self.neighbours.remove(place_name) + + def remove_monster(self, monster): + self.monsters.remove(monster) + + def remove_npc(self, npc): + self.npc.remove(npc) + + def remove_item(self, item): + self.items.remove(item) + + +class NeighbourOption(OptionCommand): + ''' + Add a new neighbour to the current place + ''' + + def __init__(self, place): + OptionCommand.__init__("neighbour", + "Add the place given in the argument as a neighbour") + self.place = place + + def act(self, arg): + self.place.add_neighbour(arg) + + +class DefinePlace(DefineCommand): + ''' + The Atlantis language construct to create a place. + ''' + + def __init__(self, place): + DefineCommand.__init__("define-place", + "Describe a new location in the game world") + self.place = place + self.add_option(NeighbourOption(self.place)) + diff --git a/src/player.py b/src/player.py new file mode 100644 index 0000000..9ef72ad --- /dev/null +++ b/src/player.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# The player module is in charge of everything to do with the internal +# representation of a player character. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Player(object): + ''' + The Player class represents a game character. + ''' + + def __init__(self): + pass diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc new file mode 100644 index 0000000..57d9260 --- /dev/null +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc new file mode 100644 index 0000000..2b63657 --- /dev/null +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 7b79720..68761e2 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,10 +7,11 @@ # date: 02/05/2015 # -VERSION = (0, 0, 1) #release, major revision, minor revision +VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys -from parser import Parser +from server import Server +from client import Client def print_version(): @@ -19,17 +20,35 @@ print("Licensed under the terms of the GNU General Public License v3.") def print_help(): + help_text = """ +Usage: atlantis [options] + + --help -h Print this help text and exit + --version -v Print the version number and exit + --server -s Start an Atlantis server + --world Use as the world file (implies --server) + --client : Connect as a client to the server at : + +By default, atlantis starts a client instance and asks for all necessary input. +""" print_version() - print("\nHelp text not yet available.") + print(help_text) def main(): if "--version" in sys.argv or "-v" in sys.argv: print_version() elif "--help" in sys.argv or "-h" in sys.argv: print_help() elif "--world" in sys.argv: world_file = sys.argv[sys.argv.index("--world")+1] - Parser(world_file) + Server(world_file) + elif "--server" in sys.argv or "-s" in sys.argv: + Server() + elif "--client" in sys.argv: + server_address = sys.argv[sys.argv.index("--client")+1] + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) else: - print("Interactive mode not yet available!") + Client() if __name__ == "__main__": main() diff --git a/src/client.py b/src/client.py new file mode 100644 index 0000000..93a18e3 --- /dev/null +++ b/src/client.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This is the client module that the player interacts with. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Client(object): + ''' + The client is the interface between the player and the server. + ''' + + def __init__(self, server_ip=None, server_port=None): + if not (server_ip and server_port): + print("What server IP do you want to connect to?") + server_ip = input(">> ") + print("What port are you using?") + server_port = input(">> ") + print("The client would connect to "+server_ip+":"+server_port) diff --git a/src/parser.py b/src/parser.py index d17135e..002790f 100644 --- a/src/parser.py +++ b/src/parser.py @@ -1,21 +1,48 @@ #!/usr/bin/python3 # # Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. +# This module reads in a world file and parses it. This is where the +# structure of the Atlantis language is defined. # # Licensed under the terms of the GPLv3 # author: Daniel Vedder # date: 02/05/2015 # +from world import World + + +class OptionCommand(object): + ''' + This is the super class for all option commands. (A define command + includes one or more option commands.) + ''' + + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + + def act(self, arg): + ''' + Carry out this option commands action with argument arg. + Has to be extended by subclasses! + ''' + raise NotImplementedError + + class DefineCommand(object): ''' This is the super class for all define commands. It should be extended for each individual command, like define-place, define-monster, etc. ''' - def __init__(self): - pass + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + self.option_registry = [] + + def add_option(self, option_command): + self.option_registry.append(option_command) class Parser(object): @@ -25,4 +52,7 @@ ''' def __init__(self, world_file): - print("Loading world file '"+world_file+"'...") + self.world_file = world_file + + def generate_world(self): + return World() diff --git a/src/place.py b/src/place.py new file mode 100644 index 0000000..05fe873 --- /dev/null +++ b/src/place.py @@ -0,0 +1,91 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This module contains the code for a place (a delimited location +# in the world). +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +from parser import DefineCommand + + +class Place(object): + ''' + A Place is one discrete location in the game world, which can contain + players, monsters, items, NPCs, and links to other places. + ''' + + def __init__(self, name, description, + neighbours=[], monsters=[], + npc=[], items=[]): + ''' + The constructor for a new place. + Arguments: + name: the name of this place + description: a description string + neighbours: a list of place names of places bordering on this one + monsters: a list of instances of monsters + npc: a list of instances of NPCs + 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 + + def add_neighbour(self, place_name): + if place_name not in self.neighbours: + self.neighbours.append(place_name) + + def add_monster(self, monster): + self.monsters.append(monster) + + def add_npc(self, npc): + self.npc.append(npc) + + def add_item(self, item): + self.items.append(item) + + def remove_neighbour(self, place_name): + self.neighbours.remove(place_name) + + def remove_monster(self, monster): + self.monsters.remove(monster) + + def remove_npc(self, npc): + self.npc.remove(npc) + + def remove_item(self, item): + self.items.remove(item) + + +class NeighbourOption(OptionCommand): + ''' + Add a new neighbour to the current place + ''' + + def __init__(self, place): + OptionCommand.__init__("neighbour", + "Add the place given in the argument as a neighbour") + self.place = place + + def act(self, arg): + self.place.add_neighbour(arg) + + +class DefinePlace(DefineCommand): + ''' + The Atlantis language construct to create a place. + ''' + + def __init__(self, place): + DefineCommand.__init__("define-place", + "Describe a new location in the game world") + self.place = place + self.add_option(NeighbourOption(self.place)) + diff --git a/src/player.py b/src/player.py new file mode 100644 index 0000000..9ef72ad --- /dev/null +++ b/src/player.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# The player module is in charge of everything to do with the internal +# representation of a player character. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Player(object): + ''' + The Player class represents a game character. + ''' + + def __init__(self): + pass diff --git a/src/server.py b/src/server.py new file mode 100644 index 0000000..99a858f --- /dev/null +++ b/src/server.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This is the server module which is in ultimately in charge of all game logic. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +from parser import Parser + +#TODO: lock file for the server! + +class Server(object): + ''' + This is the master server class in charge of setting up everything + necessary for a game. + ''' + + def __init__(self, world_file=None): + print("The server is still under construction!") + if not world_file: + print("ATLANTIS: which world file should be loaded?") + print("Please provide an absolute or relative path.") + world_file = input(">> ") + parser = Parser(world_file) + self.world = parser.generate_world() diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc new file mode 100644 index 0000000..57d9260 --- /dev/null +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc new file mode 100644 index 0000000..2b63657 --- /dev/null +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 7b79720..68761e2 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,10 +7,11 @@ # date: 02/05/2015 # -VERSION = (0, 0, 1) #release, major revision, minor revision +VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys -from parser import Parser +from server import Server +from client import Client def print_version(): @@ -19,17 +20,35 @@ print("Licensed under the terms of the GNU General Public License v3.") def print_help(): + help_text = """ +Usage: atlantis [options] + + --help -h Print this help text and exit + --version -v Print the version number and exit + --server -s Start an Atlantis server + --world Use as the world file (implies --server) + --client : Connect as a client to the server at : + +By default, atlantis starts a client instance and asks for all necessary input. +""" print_version() - print("\nHelp text not yet available.") + print(help_text) def main(): if "--version" in sys.argv or "-v" in sys.argv: print_version() elif "--help" in sys.argv or "-h" in sys.argv: print_help() elif "--world" in sys.argv: world_file = sys.argv[sys.argv.index("--world")+1] - Parser(world_file) + Server(world_file) + elif "--server" in sys.argv or "-s" in sys.argv: + Server() + elif "--client" in sys.argv: + server_address = sys.argv[sys.argv.index("--client")+1] + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) else: - print("Interactive mode not yet available!") + Client() if __name__ == "__main__": main() diff --git a/src/client.py b/src/client.py new file mode 100644 index 0000000..93a18e3 --- /dev/null +++ b/src/client.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This is the client module that the player interacts with. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Client(object): + ''' + The client is the interface between the player and the server. + ''' + + def __init__(self, server_ip=None, server_port=None): + if not (server_ip and server_port): + print("What server IP do you want to connect to?") + server_ip = input(">> ") + print("What port are you using?") + server_port = input(">> ") + print("The client would connect to "+server_ip+":"+server_port) diff --git a/src/parser.py b/src/parser.py index d17135e..002790f 100644 --- a/src/parser.py +++ b/src/parser.py @@ -1,21 +1,48 @@ #!/usr/bin/python3 # # Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. +# This module reads in a world file and parses it. This is where the +# structure of the Atlantis language is defined. # # Licensed under the terms of the GPLv3 # author: Daniel Vedder # date: 02/05/2015 # +from world import World + + +class OptionCommand(object): + ''' + This is the super class for all option commands. (A define command + includes one or more option commands.) + ''' + + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + + def act(self, arg): + ''' + Carry out this option commands action with argument arg. + Has to be extended by subclasses! + ''' + raise NotImplementedError + + class DefineCommand(object): ''' This is the super class for all define commands. It should be extended for each individual command, like define-place, define-monster, etc. ''' - def __init__(self): - pass + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + self.option_registry = [] + + def add_option(self, option_command): + self.option_registry.append(option_command) class Parser(object): @@ -25,4 +52,7 @@ ''' def __init__(self, world_file): - print("Loading world file '"+world_file+"'...") + self.world_file = world_file + + def generate_world(self): + return World() diff --git a/src/place.py b/src/place.py new file mode 100644 index 0000000..05fe873 --- /dev/null +++ b/src/place.py @@ -0,0 +1,91 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This module contains the code for a place (a delimited location +# in the world). +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +from parser import DefineCommand + + +class Place(object): + ''' + A Place is one discrete location in the game world, which can contain + players, monsters, items, NPCs, and links to other places. + ''' + + def __init__(self, name, description, + neighbours=[], monsters=[], + npc=[], items=[]): + ''' + The constructor for a new place. + Arguments: + name: the name of this place + description: a description string + neighbours: a list of place names of places bordering on this one + monsters: a list of instances of monsters + npc: a list of instances of NPCs + 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 + + def add_neighbour(self, place_name): + if place_name not in self.neighbours: + self.neighbours.append(place_name) + + def add_monster(self, monster): + self.monsters.append(monster) + + def add_npc(self, npc): + self.npc.append(npc) + + def add_item(self, item): + self.items.append(item) + + def remove_neighbour(self, place_name): + self.neighbours.remove(place_name) + + def remove_monster(self, monster): + self.monsters.remove(monster) + + def remove_npc(self, npc): + self.npc.remove(npc) + + def remove_item(self, item): + self.items.remove(item) + + +class NeighbourOption(OptionCommand): + ''' + Add a new neighbour to the current place + ''' + + def __init__(self, place): + OptionCommand.__init__("neighbour", + "Add the place given in the argument as a neighbour") + self.place = place + + def act(self, arg): + self.place.add_neighbour(arg) + + +class DefinePlace(DefineCommand): + ''' + The Atlantis language construct to create a place. + ''' + + def __init__(self, place): + DefineCommand.__init__("define-place", + "Describe a new location in the game world") + self.place = place + self.add_option(NeighbourOption(self.place)) + diff --git a/src/player.py b/src/player.py new file mode 100644 index 0000000..9ef72ad --- /dev/null +++ b/src/player.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# The player module is in charge of everything to do with the internal +# representation of a player character. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Player(object): + ''' + The Player class represents a game character. + ''' + + def __init__(self): + pass diff --git a/src/server.py b/src/server.py new file mode 100644 index 0000000..99a858f --- /dev/null +++ b/src/server.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This is the server module which is in ultimately in charge of all game logic. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +from parser import Parser + +#TODO: lock file for the server! + +class Server(object): + ''' + This is the master server class in charge of setting up everything + necessary for a game. + ''' + + def __init__(self, world_file=None): + print("The server is still under construction!") + if not world_file: + print("ATLANTIS: which world file should be loaded?") + print("Please provide an absolute or relative path.") + world_file = input(">> ") + parser = Parser(world_file) + self.world = parser.generate_world() diff --git a/src/world.py b/src/world.py new file mode 100644 index 0000000..0c2fe32 --- /dev/null +++ b/src/world.py @@ -0,0 +1,53 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# The world module saves the current state of the game world. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class World(object): + ''' + The World class saves and gives access to the current state + of the game world. + ''' + + def __init__(self): + self.places = [] + self.players = [] + self.starting_place = None + + def register_place(self, place): + if self.place not in places: + self.places.append(place) + else: + print("Attempted to add a place that already exists!") + + def register_player(self, player): + if player not in self.players: + self.players.append(player) + if player.place == None: + if self.starting_place: + player.place = self.starting_place + else: + print("No starting place set!") + else: + print("Attempted to add a player that already exists!") + + def get_place(self, name): + for p in self.places: + if p.name == name: + return p + + def get_player(self, name): + for p in self.players: + if p.name == name: + return p + + def set_starting_place(self, name): + for p in self.places: + if p.name == name: + self.starting_place = p + diff --git a/notes b/notes new file mode 100644 index 0000000..4a0c6d9 --- /dev/null +++ b/notes @@ -0,0 +1,9 @@ +====================== +|| Project ATLANTIS || +====================== + +DEVELOPMENT NOTES + +- need to add unified error handling + +- need to add a lock file for the server \ No newline at end of file diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc new file mode 100644 index 0000000..57d9260 --- /dev/null +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc new file mode 100644 index 0000000..2b63657 --- /dev/null +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 7b79720..68761e2 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,10 +7,11 @@ # date: 02/05/2015 # -VERSION = (0, 0, 1) #release, major revision, minor revision +VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys -from parser import Parser +from server import Server +from client import Client def print_version(): @@ -19,17 +20,35 @@ print("Licensed under the terms of the GNU General Public License v3.") def print_help(): + help_text = """ +Usage: atlantis [options] + + --help -h Print this help text and exit + --version -v Print the version number and exit + --server -s Start an Atlantis server + --world Use as the world file (implies --server) + --client : Connect as a client to the server at : + +By default, atlantis starts a client instance and asks for all necessary input. +""" print_version() - print("\nHelp text not yet available.") + print(help_text) def main(): if "--version" in sys.argv or "-v" in sys.argv: print_version() elif "--help" in sys.argv or "-h" in sys.argv: print_help() elif "--world" in sys.argv: world_file = sys.argv[sys.argv.index("--world")+1] - Parser(world_file) + Server(world_file) + elif "--server" in sys.argv or "-s" in sys.argv: + Server() + elif "--client" in sys.argv: + server_address = sys.argv[sys.argv.index("--client")+1] + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) else: - print("Interactive mode not yet available!") + Client() if __name__ == "__main__": main() diff --git a/src/client.py b/src/client.py new file mode 100644 index 0000000..93a18e3 --- /dev/null +++ b/src/client.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This is the client module that the player interacts with. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Client(object): + ''' + The client is the interface between the player and the server. + ''' + + def __init__(self, server_ip=None, server_port=None): + if not (server_ip and server_port): + print("What server IP do you want to connect to?") + server_ip = input(">> ") + print("What port are you using?") + server_port = input(">> ") + print("The client would connect to "+server_ip+":"+server_port) diff --git a/src/parser.py b/src/parser.py index d17135e..002790f 100644 --- a/src/parser.py +++ b/src/parser.py @@ -1,21 +1,48 @@ #!/usr/bin/python3 # # Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. +# This module reads in a world file and parses it. This is where the +# structure of the Atlantis language is defined. # # Licensed under the terms of the GPLv3 # author: Daniel Vedder # date: 02/05/2015 # +from world import World + + +class OptionCommand(object): + ''' + This is the super class for all option commands. (A define command + includes one or more option commands.) + ''' + + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + + def act(self, arg): + ''' + Carry out this option commands action with argument arg. + Has to be extended by subclasses! + ''' + raise NotImplementedError + + class DefineCommand(object): ''' This is the super class for all define commands. It should be extended for each individual command, like define-place, define-monster, etc. ''' - def __init__(self): - pass + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + self.option_registry = [] + + def add_option(self, option_command): + self.option_registry.append(option_command) class Parser(object): @@ -25,4 +52,7 @@ ''' def __init__(self, world_file): - print("Loading world file '"+world_file+"'...") + self.world_file = world_file + + def generate_world(self): + return World() diff --git a/src/place.py b/src/place.py new file mode 100644 index 0000000..05fe873 --- /dev/null +++ b/src/place.py @@ -0,0 +1,91 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This module contains the code for a place (a delimited location +# in the world). +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +from parser import DefineCommand + + +class Place(object): + ''' + A Place is one discrete location in the game world, which can contain + players, monsters, items, NPCs, and links to other places. + ''' + + def __init__(self, name, description, + neighbours=[], monsters=[], + npc=[], items=[]): + ''' + The constructor for a new place. + Arguments: + name: the name of this place + description: a description string + neighbours: a list of place names of places bordering on this one + monsters: a list of instances of monsters + npc: a list of instances of NPCs + 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 + + def add_neighbour(self, place_name): + if place_name not in self.neighbours: + self.neighbours.append(place_name) + + def add_monster(self, monster): + self.monsters.append(monster) + + def add_npc(self, npc): + self.npc.append(npc) + + def add_item(self, item): + self.items.append(item) + + def remove_neighbour(self, place_name): + self.neighbours.remove(place_name) + + def remove_monster(self, monster): + self.monsters.remove(monster) + + def remove_npc(self, npc): + self.npc.remove(npc) + + def remove_item(self, item): + self.items.remove(item) + + +class NeighbourOption(OptionCommand): + ''' + Add a new neighbour to the current place + ''' + + def __init__(self, place): + OptionCommand.__init__("neighbour", + "Add the place given in the argument as a neighbour") + self.place = place + + def act(self, arg): + self.place.add_neighbour(arg) + + +class DefinePlace(DefineCommand): + ''' + The Atlantis language construct to create a place. + ''' + + def __init__(self, place): + DefineCommand.__init__("define-place", + "Describe a new location in the game world") + self.place = place + self.add_option(NeighbourOption(self.place)) + diff --git a/src/player.py b/src/player.py new file mode 100644 index 0000000..9ef72ad --- /dev/null +++ b/src/player.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# The player module is in charge of everything to do with the internal +# representation of a player character. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class Player(object): + ''' + The Player class represents a game character. + ''' + + def __init__(self): + pass diff --git a/src/server.py b/src/server.py new file mode 100644 index 0000000..99a858f --- /dev/null +++ b/src/server.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This is the server module which is in ultimately in charge of all game logic. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +from parser import Parser + +#TODO: lock file for the server! + +class Server(object): + ''' + This is the master server class in charge of setting up everything + necessary for a game. + ''' + + def __init__(self, world_file=None): + print("The server is still under construction!") + if not world_file: + print("ATLANTIS: which world file should be loaded?") + print("Please provide an absolute or relative path.") + world_file = input(">> ") + parser = Parser(world_file) + self.world = parser.generate_world() diff --git a/src/world.py b/src/world.py new file mode 100644 index 0000000..0c2fe32 --- /dev/null +++ b/src/world.py @@ -0,0 +1,53 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# The world module saves the current state of the game world. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +class World(object): + ''' + The World class saves and gives access to the current state + of the game world. + ''' + + def __init__(self): + self.places = [] + self.players = [] + self.starting_place = None + + def register_place(self, place): + if self.place not in places: + self.places.append(place) + else: + print("Attempted to add a place that already exists!") + + def register_player(self, player): + if player not in self.players: + self.players.append(player) + if player.place == None: + if self.starting_place: + player.place = self.starting_place + else: + print("No starting place set!") + else: + print("Attempted to add a player that already exists!") + + def get_place(self, name): + for p in self.places: + if p.name == name: + return p + + def get_player(self, name): + for p in self.players: + if p.name == name: + return p + + def set_starting_place(self, name): + for p in self.places: + if p.name == name: + self.starting_place = p + diff --git a/worlds/Example/example.atl b/worlds/Example/example.atl index 1087d86..3101edd 100644 --- a/worlds/Example/example.atl +++ b/worlds/Example/example.atl @@ -53,17 +53,20 @@ description Welcome to Nowhere! You are in the void, the space between \ the worlds. Around you is black. Black, except for one tiny pin-prick of light \ to the north. - north Elysium + neighbour Elysium define-place Elysium description Congratulations! You have achieved Elysium! - south Nowhere - west Fields of punishment + neighbour Nowhere + neighbour Fields of punishment npc Hades item Scroll of light define-place Fields of punishment description You really, really don't want to end up here... - east Elysium + neighbour Elysium monster Hellhound monster Fury + + +start-place Elysium \ No newline at end of file