def menu_loop(): answer = str(raw_input(">")) if answer == "1": print "Generating world..." tile = TileGenerator() tile.generate_first() tile.generate_all() save = open("save.txt", "w") save.write("00" + "\n") save.close() game_loop() elif answer == "2": print "Loading world..." with open("save.txt") as f: coordinates = str(f.readlines()) player.x = int(coordinates[2]) player.y = int(coordinates[3]) print "[DONE]" game_loop() elif answer == "3": print "Not yet implemented!" menu_loop() elif answer == "4": sys.exit("Quit") else: print "Please chose 1, 2, 3, or 4!" menu_loop()
def west_of_you(self): tile = TileGenerator() world = tile.load_world() west_tile = "None" search = str(player.x - 1) + str(player.y) for sublist in world: if sublist[0] == search: west_tile = sublist[1] break return west_tile
def south_of_you(self): tile = TileGenerator() world = tile.load_world() south_tile= "None" search = str(player.x) + str(player.y - 1) for sublist in world: if sublist[0] == search: south_tile = sublist[1] break return south_tile
def input_parse(self, answer): tile = TileGenerator() if self.answer == "N": if player.y < MAX_RANGE: player.y += 1 elif player.y >= MAX_RANGE: player.y += 0 current_pos = "End of the world" world = tile.load_world() search = str(player.x) + str(player.y) for sublist in world: if sublist[0] == search: current_pos = sublist[1] break #debug info print player.name + " is in " + current_pos print "On your north is " + self.north_of_you() print "On your south is " + self.south_of_you() print "On your east is " + self.east_of_you() print "On your west is " + self.west_of_you() save = open("save.txt", "w") save.write(search+ "\n") save.close() elif self.answer == "S": if player.y >= MIN_RANGE: player.y -= 1 elif player.y < MIN_RANGE: player.y += 0 current_pos = "End of the world" world = tile.load_world() search = str(player.x) + str(player.y) for sublist in world: if sublist[0] == search: current_pos = sublist[1] break #debug info print player.name + " is in " + current_pos print "On your north is " + self.north_of_you() print "On your south is " + self.south_of_you() print "On your east is " + self.east_of_you() print "On your west is " + self.west_of_you() save = open("save.txt", "w") save.write(search + "\n") save.close() elif self.answer == "E": if player.x < MAX_RANGE: player.x += 1 elif player.x >= MAX_RANGE: player.x += 0 current_pos = "End of the world" world = tile.load_world() search = str(player.x) + str(player.y) for sublist in world: if sublist[0] == search: current_pos = sublist[1] break #debug info print player.name + " is in " + current_pos print "On your north is " + self.north_of_you() print "On your south is " + self.south_of_you() print "On your east is " + self.east_of_you() print "On your west is " + self.west_of_you() save = open("save.txt", "w") save.write(search + "\n") save.close() elif self.answer == "W": if player.x >= MIN_RANGE: player.x -= 1 elif player.x < MIN_RANGE: player.x += 0 current_pos = "End of the world" world = tile.load_world() search = str(player.x) + str(player.y) for sublist in world: if sublist[0] == search: current_pos = sublist[1] break #debug info print player.name + " is in " + current_pos print "On your north is " + self.north_of_you() print "On your south is " + self.south_of_you() print "On your east is " + self.east_of_you() print "On your west is " + self.west_of_you() save = open("save.txt", "w") save.write(search + "\n") save.close() elif self.answer == "Q": sys.exit("Quit!") elif self.answer == "I": self.inventory() elif self.answer == "HELP": print("""- Enter N to go North - Enter S to go South - Enter E to go East - Enter W to go West - Enter I to see the inventory - Enter Q to quit the game""") else: print "Enter HELP to see the commands"