diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc index 57d9260..077e656 100644 --- a/src/__pycache__/client.cpython-34.pyc +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc index 57d9260..077e656 100644 --- a/src/__pycache__/client.cpython-34.pyc +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/parser.cpython-34.pyc b/src/__pycache__/parser.cpython-34.pyc index 3c0874d..ffeaf68 100644 --- a/src/__pycache__/parser.cpython-34.pyc +++ b/src/__pycache__/parser.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc index 57d9260..077e656 100644 --- a/src/__pycache__/client.cpython-34.pyc +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/parser.cpython-34.pyc b/src/__pycache__/parser.cpython-34.pyc index 3c0874d..ffeaf68 100644 --- a/src/__pycache__/parser.cpython-34.pyc +++ b/src/__pycache__/parser.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b63657..87708fb 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc index 57d9260..077e656 100644 --- a/src/__pycache__/client.cpython-34.pyc +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/parser.cpython-34.pyc b/src/__pycache__/parser.cpython-34.pyc index 3c0874d..ffeaf68 100644 --- a/src/__pycache__/parser.cpython-34.pyc +++ b/src/__pycache__/parser.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b63657..87708fb 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 new file mode 100644 index 0000000..f29617b --- /dev/null +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc index 57d9260..077e656 100644 --- a/src/__pycache__/client.cpython-34.pyc +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/parser.cpython-34.pyc b/src/__pycache__/parser.cpython-34.pyc index 3c0874d..ffeaf68 100644 --- a/src/__pycache__/parser.cpython-34.pyc +++ b/src/__pycache__/parser.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b63657..87708fb 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 new file mode 100644 index 0000000..f29617b --- /dev/null +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 68761e2..ebbb075 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -10,10 +10,71 @@ VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys +import os from server import Server from client import Client +global clear +if "linux" in sys.platform: + clear = "clear" +elif "win" in sys.platform: + clear = "cls" + + +def start_menu(): + ''' + Show the start menu and process the player's input + ''' + global clear + os.system(clear) + try: #Print the Atlantis logo + fn = os.path.join(os.path.dirname(__file__), "banner.txt") + img_file = open(fn, "r") + logo = img_file.read() + img_file.close() + print(logo) + except IOError: + print("Could not find logo!") + print("Welcome! What do you want to do?") + print(" -> (S)tart a server") + print(" -> (J)oin game") + print(" -> (A)bout") + print(" -> (E)xit") + print() + choice = input("Please choose an option: ") + act_on_choice(choice) + +#TODO! +def act_on_choice(choice): + if choice == "s" or choice == "S": + print("What port do you want to start the server on?") #indicate range! + server_port = input(">> ") + print("What world file do you want to load?") + print("(Specify an absolute or relative path)") + world_file = input(">> ") + Server(server_port, world_file) + elif choice == "j" or choice == "J": + print("What server do you want to connect to?") + print("Format: :") + server_address = input(">> ") + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) + elif choice == "a" or choice == "A": + print_version() + print("(c) 2015 Daniel Vedder") + input("\nPlease press ENTER") + start_menu() + elif choice == "e" or choice == "E": + print("Goodbye!") + exit() + else: + print("Invalid choice!") + input("Please press ENTER") + startMenu() + + def print_version(): version_string = str(VERSION[0])+"."+str(VERSION[1])+"."+str(VERSION[2]) print("Atlantis "+version_string) @@ -25,11 +86,11 @@ --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) + --server Start an atlantis server on (requires --world) + --world Use as the world file (requires --server) --client : Connect as a client to the server at : -By default, atlantis starts a client instance and asks for all necessary input. +If no arguments are passed, atlantis starts an interactive interface. """ print_version() print(help_text) @@ -37,18 +98,17 @@ 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: + elif "--server" in sys.argv and "--world" in sys.argv: + server_port = sys.argv[sys.argv.find("--server")+1] world_file = sys.argv[sys.argv.index("--world")+1] - Server(world_file) - elif "--server" in sys.argv or "-s" in sys.argv: - Server() + Server(port, world_file) 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: - Client() + start_menu() if __name__ == "__main__": main() diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc index 57d9260..077e656 100644 --- a/src/__pycache__/client.cpython-34.pyc +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/parser.cpython-34.pyc b/src/__pycache__/parser.cpython-34.pyc index 3c0874d..ffeaf68 100644 --- a/src/__pycache__/parser.cpython-34.pyc +++ b/src/__pycache__/parser.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b63657..87708fb 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 new file mode 100644 index 0000000..f29617b --- /dev/null +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 68761e2..ebbb075 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -10,10 +10,71 @@ VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys +import os from server import Server from client import Client +global clear +if "linux" in sys.platform: + clear = "clear" +elif "win" in sys.platform: + clear = "cls" + + +def start_menu(): + ''' + Show the start menu and process the player's input + ''' + global clear + os.system(clear) + try: #Print the Atlantis logo + fn = os.path.join(os.path.dirname(__file__), "banner.txt") + img_file = open(fn, "r") + logo = img_file.read() + img_file.close() + print(logo) + except IOError: + print("Could not find logo!") + print("Welcome! What do you want to do?") + print(" -> (S)tart a server") + print(" -> (J)oin game") + print(" -> (A)bout") + print(" -> (E)xit") + print() + choice = input("Please choose an option: ") + act_on_choice(choice) + +#TODO! +def act_on_choice(choice): + if choice == "s" or choice == "S": + print("What port do you want to start the server on?") #indicate range! + server_port = input(">> ") + print("What world file do you want to load?") + print("(Specify an absolute or relative path)") + world_file = input(">> ") + Server(server_port, world_file) + elif choice == "j" or choice == "J": + print("What server do you want to connect to?") + print("Format: :") + server_address = input(">> ") + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) + elif choice == "a" or choice == "A": + print_version() + print("(c) 2015 Daniel Vedder") + input("\nPlease press ENTER") + start_menu() + elif choice == "e" or choice == "E": + print("Goodbye!") + exit() + else: + print("Invalid choice!") + input("Please press ENTER") + startMenu() + + def print_version(): version_string = str(VERSION[0])+"."+str(VERSION[1])+"."+str(VERSION[2]) print("Atlantis "+version_string) @@ -25,11 +86,11 @@ --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) + --server Start an atlantis server on (requires --world) + --world Use as the world file (requires --server) --client : Connect as a client to the server at : -By default, atlantis starts a client instance and asks for all necessary input. +If no arguments are passed, atlantis starts an interactive interface. """ print_version() print(help_text) @@ -37,18 +98,17 @@ 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: + elif "--server" in sys.argv and "--world" in sys.argv: + server_port = sys.argv[sys.argv.find("--server")+1] world_file = sys.argv[sys.argv.index("--world")+1] - Server(world_file) - elif "--server" in sys.argv or "-s" in sys.argv: - Server() + Server(port, world_file) 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: - Client() + start_menu() if __name__ == "__main__": main() diff --git a/src/banner.txt b/src/banner.txt new file mode 100644 index 0000000..f845fc6 --- /dev/null +++ b/src/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| / || +|| O - MM _ MM ATLANTIS || +|| | \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc index 57d9260..077e656 100644 --- a/src/__pycache__/client.cpython-34.pyc +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/parser.cpython-34.pyc b/src/__pycache__/parser.cpython-34.pyc index 3c0874d..ffeaf68 100644 --- a/src/__pycache__/parser.cpython-34.pyc +++ b/src/__pycache__/parser.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b63657..87708fb 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 new file mode 100644 index 0000000..f29617b --- /dev/null +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 68761e2..ebbb075 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -10,10 +10,71 @@ VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys +import os from server import Server from client import Client +global clear +if "linux" in sys.platform: + clear = "clear" +elif "win" in sys.platform: + clear = "cls" + + +def start_menu(): + ''' + Show the start menu and process the player's input + ''' + global clear + os.system(clear) + try: #Print the Atlantis logo + fn = os.path.join(os.path.dirname(__file__), "banner.txt") + img_file = open(fn, "r") + logo = img_file.read() + img_file.close() + print(logo) + except IOError: + print("Could not find logo!") + print("Welcome! What do you want to do?") + print(" -> (S)tart a server") + print(" -> (J)oin game") + print(" -> (A)bout") + print(" -> (E)xit") + print() + choice = input("Please choose an option: ") + act_on_choice(choice) + +#TODO! +def act_on_choice(choice): + if choice == "s" or choice == "S": + print("What port do you want to start the server on?") #indicate range! + server_port = input(">> ") + print("What world file do you want to load?") + print("(Specify an absolute or relative path)") + world_file = input(">> ") + Server(server_port, world_file) + elif choice == "j" or choice == "J": + print("What server do you want to connect to?") + print("Format: :") + server_address = input(">> ") + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) + elif choice == "a" or choice == "A": + print_version() + print("(c) 2015 Daniel Vedder") + input("\nPlease press ENTER") + start_menu() + elif choice == "e" or choice == "E": + print("Goodbye!") + exit() + else: + print("Invalid choice!") + input("Please press ENTER") + startMenu() + + def print_version(): version_string = str(VERSION[0])+"."+str(VERSION[1])+"."+str(VERSION[2]) print("Atlantis "+version_string) @@ -25,11 +86,11 @@ --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) + --server Start an atlantis server on (requires --world) + --world Use as the world file (requires --server) --client : Connect as a client to the server at : -By default, atlantis starts a client instance and asks for all necessary input. +If no arguments are passed, atlantis starts an interactive interface. """ print_version() print(help_text) @@ -37,18 +98,17 @@ 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: + elif "--server" in sys.argv and "--world" in sys.argv: + server_port = sys.argv[sys.argv.find("--server")+1] world_file = sys.argv[sys.argv.index("--world")+1] - Server(world_file) - elif "--server" in sys.argv or "-s" in sys.argv: - Server() + Server(port, world_file) 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: - Client() + start_menu() if __name__ == "__main__": main() diff --git a/src/banner.txt b/src/banner.txt new file mode 100644 index 0000000..f845fc6 --- /dev/null +++ b/src/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| / || +|| O - MM _ MM ATLANTIS || +|| | \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/src/parser.py b/src/parser.py index 002790f..86cd37e 100644 --- a/src/parser.py +++ b/src/parser.py @@ -12,17 +12,24 @@ from world import World +# +# FIXME: conceptually a bit messed up, especially needs work on how the argument +# gets passed to the OptionCommand +# + + 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): + def __init__(self, name, doc_string, arg): self.name = name self.doc_string = doc_string + self.arg = arg - def act(self, arg): + def act(self): ''' Carry out this option commands action with argument arg. Has to be extended by subclasses! @@ -44,6 +51,19 @@ def add_option(self, option_command): self.option_registry.append(option_command) + def execute(self): + ''' + Execute this command with all its options + ''' + for o in self.option_registry: + o.act(arg) + + +define_command_registry = [] + +def register_define_command(def_com): + define_command_registry.append(def_com) + class Parser(object): ''' diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc index 57d9260..077e656 100644 --- a/src/__pycache__/client.cpython-34.pyc +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/parser.cpython-34.pyc b/src/__pycache__/parser.cpython-34.pyc index 3c0874d..ffeaf68 100644 --- a/src/__pycache__/parser.cpython-34.pyc +++ b/src/__pycache__/parser.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b63657..87708fb 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 new file mode 100644 index 0000000..f29617b --- /dev/null +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 68761e2..ebbb075 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -10,10 +10,71 @@ VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys +import os from server import Server from client import Client +global clear +if "linux" in sys.platform: + clear = "clear" +elif "win" in sys.platform: + clear = "cls" + + +def start_menu(): + ''' + Show the start menu and process the player's input + ''' + global clear + os.system(clear) + try: #Print the Atlantis logo + fn = os.path.join(os.path.dirname(__file__), "banner.txt") + img_file = open(fn, "r") + logo = img_file.read() + img_file.close() + print(logo) + except IOError: + print("Could not find logo!") + print("Welcome! What do you want to do?") + print(" -> (S)tart a server") + print(" -> (J)oin game") + print(" -> (A)bout") + print(" -> (E)xit") + print() + choice = input("Please choose an option: ") + act_on_choice(choice) + +#TODO! +def act_on_choice(choice): + if choice == "s" or choice == "S": + print("What port do you want to start the server on?") #indicate range! + server_port = input(">> ") + print("What world file do you want to load?") + print("(Specify an absolute or relative path)") + world_file = input(">> ") + Server(server_port, world_file) + elif choice == "j" or choice == "J": + print("What server do you want to connect to?") + print("Format: :") + server_address = input(">> ") + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) + elif choice == "a" or choice == "A": + print_version() + print("(c) 2015 Daniel Vedder") + input("\nPlease press ENTER") + start_menu() + elif choice == "e" or choice == "E": + print("Goodbye!") + exit() + else: + print("Invalid choice!") + input("Please press ENTER") + startMenu() + + def print_version(): version_string = str(VERSION[0])+"."+str(VERSION[1])+"."+str(VERSION[2]) print("Atlantis "+version_string) @@ -25,11 +86,11 @@ --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) + --server Start an atlantis server on (requires --world) + --world Use as the world file (requires --server) --client : Connect as a client to the server at : -By default, atlantis starts a client instance and asks for all necessary input. +If no arguments are passed, atlantis starts an interactive interface. """ print_version() print(help_text) @@ -37,18 +98,17 @@ 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: + elif "--server" in sys.argv and "--world" in sys.argv: + server_port = sys.argv[sys.argv.find("--server")+1] world_file = sys.argv[sys.argv.index("--world")+1] - Server(world_file) - elif "--server" in sys.argv or "-s" in sys.argv: - Server() + Server(port, world_file) 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: - Client() + start_menu() if __name__ == "__main__": main() diff --git a/src/banner.txt b/src/banner.txt new file mode 100644 index 0000000..f845fc6 --- /dev/null +++ b/src/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| / || +|| O - MM _ MM ATLANTIS || +|| | \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/src/parser.py b/src/parser.py index 002790f..86cd37e 100644 --- a/src/parser.py +++ b/src/parser.py @@ -12,17 +12,24 @@ from world import World +# +# FIXME: conceptually a bit messed up, especially needs work on how the argument +# gets passed to the OptionCommand +# + + 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): + def __init__(self, name, doc_string, arg): self.name = name self.doc_string = doc_string + self.arg = arg - def act(self, arg): + def act(self): ''' Carry out this option commands action with argument arg. Has to be extended by subclasses! @@ -44,6 +51,19 @@ def add_option(self, option_command): self.option_registry.append(option_command) + def execute(self): + ''' + Execute this command with all its options + ''' + for o in self.option_registry: + o.act(arg) + + +define_command_registry = [] + +def register_define_command(def_com): + define_command_registry.append(def_com) + class Parser(object): ''' diff --git a/src/place.py b/src/place.py index 05fe873..8ffd706 100644 --- a/src/place.py +++ b/src/place.py @@ -64,14 +64,20 @@ self.items.remove(item) +# +# FIXME: conceptually a bit messed up, especially needs work on how the argument +# gets passed to the OptionCommand +# + class NeighbourOption(OptionCommand): ''' Add a new neighbour to the current place ''' - def __init__(self, place): + def __init__(self, arg, place): OptionCommand.__init__("neighbour", - "Add the place given in the argument as a neighbour") + "Add the place given in the argument as a neighbour", + arg) self.place = place def act(self, arg): diff --git a/src/__pycache__/client.cpython-34.pyc b/src/__pycache__/client.cpython-34.pyc index 57d9260..077e656 100644 --- a/src/__pycache__/client.cpython-34.pyc +++ b/src/__pycache__/client.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/parser.cpython-34.pyc b/src/__pycache__/parser.cpython-34.pyc index 3c0874d..ffeaf68 100644 --- a/src/__pycache__/parser.cpython-34.pyc +++ b/src/__pycache__/parser.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index 2b63657..87708fb 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 new file mode 100644 index 0000000..f29617b --- /dev/null +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 68761e2..ebbb075 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -10,10 +10,71 @@ VERSION = (0, 0, 3) #release, major revision, minor (git) revision import sys +import os from server import Server from client import Client +global clear +if "linux" in sys.platform: + clear = "clear" +elif "win" in sys.platform: + clear = "cls" + + +def start_menu(): + ''' + Show the start menu and process the player's input + ''' + global clear + os.system(clear) + try: #Print the Atlantis logo + fn = os.path.join(os.path.dirname(__file__), "banner.txt") + img_file = open(fn, "r") + logo = img_file.read() + img_file.close() + print(logo) + except IOError: + print("Could not find logo!") + print("Welcome! What do you want to do?") + print(" -> (S)tart a server") + print(" -> (J)oin game") + print(" -> (A)bout") + print(" -> (E)xit") + print() + choice = input("Please choose an option: ") + act_on_choice(choice) + +#TODO! +def act_on_choice(choice): + if choice == "s" or choice == "S": + print("What port do you want to start the server on?") #indicate range! + server_port = input(">> ") + print("What world file do you want to load?") + print("(Specify an absolute or relative path)") + world_file = input(">> ") + Server(server_port, world_file) + elif choice == "j" or choice == "J": + print("What server do you want to connect to?") + print("Format: :") + server_address = input(">> ") + server_ip = server_address[:server_address.find(":")] + server_port = server_address[server_address.find(":")+1:] + Client(server_ip, server_port) + elif choice == "a" or choice == "A": + print_version() + print("(c) 2015 Daniel Vedder") + input("\nPlease press ENTER") + start_menu() + elif choice == "e" or choice == "E": + print("Goodbye!") + exit() + else: + print("Invalid choice!") + input("Please press ENTER") + startMenu() + + def print_version(): version_string = str(VERSION[0])+"."+str(VERSION[1])+"."+str(VERSION[2]) print("Atlantis "+version_string) @@ -25,11 +86,11 @@ --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) + --server Start an atlantis server on (requires --world) + --world Use as the world file (requires --server) --client : Connect as a client to the server at : -By default, atlantis starts a client instance and asks for all necessary input. +If no arguments are passed, atlantis starts an interactive interface. """ print_version() print(help_text) @@ -37,18 +98,17 @@ 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: + elif "--server" in sys.argv and "--world" in sys.argv: + server_port = sys.argv[sys.argv.find("--server")+1] world_file = sys.argv[sys.argv.index("--world")+1] - Server(world_file) - elif "--server" in sys.argv or "-s" in sys.argv: - Server() + Server(port, world_file) 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: - Client() + start_menu() if __name__ == "__main__": main() diff --git a/src/banner.txt b/src/banner.txt new file mode 100644 index 0000000..f845fc6 --- /dev/null +++ b/src/banner.txt @@ -0,0 +1,10 @@ +==================================================== +|| / || +|| O - MM _ MM ATLANTIS || +|| | \ ||_/.\_|| || +|| |*| |*| Lost worlds await || +|| ~~~~~| | A | |~~~~ || +|| ~~~~###########~~~ || +|| ~~~#############~~ (c) 2015 Daniel Vedder || +|| ~~~~~~~~~~~~~~~~~~ || +==================================================== diff --git a/src/parser.py b/src/parser.py index 002790f..86cd37e 100644 --- a/src/parser.py +++ b/src/parser.py @@ -12,17 +12,24 @@ from world import World +# +# FIXME: conceptually a bit messed up, especially needs work on how the argument +# gets passed to the OptionCommand +# + + 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): + def __init__(self, name, doc_string, arg): self.name = name self.doc_string = doc_string + self.arg = arg - def act(self, arg): + def act(self): ''' Carry out this option commands action with argument arg. Has to be extended by subclasses! @@ -44,6 +51,19 @@ def add_option(self, option_command): self.option_registry.append(option_command) + def execute(self): + ''' + Execute this command with all its options + ''' + for o in self.option_registry: + o.act(arg) + + +define_command_registry = [] + +def register_define_command(def_com): + define_command_registry.append(def_com) + class Parser(object): ''' diff --git a/src/place.py b/src/place.py index 05fe873..8ffd706 100644 --- a/src/place.py +++ b/src/place.py @@ -64,14 +64,20 @@ self.items.remove(item) +# +# FIXME: conceptually a bit messed up, especially needs work on how the argument +# gets passed to the OptionCommand +# + class NeighbourOption(OptionCommand): ''' Add a new neighbour to the current place ''' - def __init__(self, place): + def __init__(self, arg, place): OptionCommand.__init__("neighbour", - "Add the place given in the argument as a neighbour") + "Add the place given in the argument as a neighbour", + arg) self.place = place def act(self, arg): diff --git a/src/server.py b/src/server.py index 99a858f..aaecbb4 100644 --- a/src/server.py +++ b/src/server.py @@ -18,11 +18,9 @@ necessary for a game. ''' - def __init__(self, world_file=None): + def __init__(self, port, world_file): 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.port = port + self.world_file = world_file + parser = Parser(self.world_file) self.world = parser.generate_world()