def __init__(self, map_screen, background_screen, text_screen): """ Constructor. :param map_screen: Surface :param background_screen: Surface :param text_screen: Surface """ self.amount_of_enemies = 0 self.amount_of_empty_colonies = 0 self.map_to_load = None self.race_manager = RaceManager() self.human_players = [] self.players = [] self.map = Map(GUISettings.SCREEN_WIDTH, GUISettings.SCREEN_HEIGHT) self.event_handler = EventHandler(self) self.screen = map_screen self.background_screen = background_screen self.player_one = Player() self.human_players.append(self.player_one) self.sound_driver = SoundDriver() self.map_loader = MapLoader(self) self.text_screen = text_screen self.running = True self.map_manager = MapManager() self.state = MainMenu(self) self.menu = MenuSettings.MAIN_MENU(self)
def __init__(self, race, position=None, event_answer=[], _map=None): """ Constructor to create action Args: race ([int]): The race of the NPC. position ([(float,float)], optional): The position (x,y) of the NPC if not set, it will try to find the closest NPC if it is in a diferent map. Defaults to None. event_answer (list, optional): A list of indexes containing the index of the event answers. Defaults to []. _map ([str], optional): A map name, if not set, it will use the current map. Defaults to None. """ self.race = race self.event_answer = event_answer self.position = position self.mapName = _map if self.mapName == None: map_path, self.mapName = MapManager.GetClosestMapPathWithNPC( self.race) if self.position == None: self.position = MapManager.GetNpcFromMap(self.mapName, self.race) OpenLog.DebugPrint("[NPC-ACTION] - New NPC Action race " + str(self.race) + " on map " + str(self.mapName) + " at position " + str(self.position))
def __init__(self, gametype, pgui): self.gui = pgui self.filesystem = FileSystem() self.iohandler = IOHandler(gametype, pgui) self.mapmanager = MapManager(self.filesystem.getData('map')) self.mapmanager.getVisibleObjects() self.messagehandler = MessageHandler( self.filesystem.getData("messages")) self.gamerun = False self.securitycamera = True self.talked = False
def MoveToMapPosition(self, finalPosition, mapName=None, listLinks=[], callback=None, maxDist=250): if len(listLinks) == 0: if mapName == None or mapName == background.GetCurrentMapName(): OpenLog.DebugPrint("Moving to (" + str(finalPosition[0]) + "," + str(finalPosition[1]) + ") on " + str(background.GetCurrentMapName())) return Movement.GoToPositionAvoidingObjects(finalPosition[0], finalPosition[1], maxDist, callback=callback) listLinks = MapManager.GetMapPath(mapName) if len(listLinks) == 0: OpenLog.DebugPrint("Error no map found by the name: " + str(mapName)) return None self.maxDist = maxDist self.leftLinkList = listLinks self.finalPosition = finalPosition self.callback = callback self.SetStateMoving()
def __init__(self, name, author, description, version, menuText, gplugins): Plugin.Plugin.__init__(self, name, author, description, version, menuText, gplugins) self.mm = MapManager.getMapManager() self.mm_names = self.mm.getMapNames() random.seed(time.time()) self.mm_dndx = random.randint(0, len(self.mm_names) - 1)
def mapCacheGet(self, mapName): mapMan = MapManager.getMapManager() if mapName in self.mapCache: return self.mapCache[mapName] qimg = mapMan.getMiniMap(mapName) if qimg is None: return None #qimg = QtGui.QPixmap.fromImage(qimg) self.mapCache[mapName] = qimg return qimg
def run(map_filename, starting_step): """ the main game loop. runs until user hits quit button (F4) """ atexit.register(WinMan.terminate) input_listener = InputListener() input_listener.start() MapMan.init_map(map_filename) while not global_vars.quit: global_vars.step += 1 step_start = time() MapMan.update() if global_vars.hidden_run: if global_vars.step >= starting_step: WinMan.init() global_vars.hidden_run = False else: WinMan.progress_info(starting_step) else: WinMan.update(MapMan.token_map(), MapMan.watch_info()) current_time = time() if (current_time - step_start) < global_vars.step_duration: sleep(global_vars.step_duration - (current_time - step_start)) while global_vars.pause and not global_vars.quit: if global_vars.single_step: global_vars.single_step = False break sleep(0.01) input_listener.join()
import TaxiManager import threading import json import TaxiMove import urlparse import sys import time reload(sys) sys.setdefaultencoding('utf-8') # ------------------------------------- # MAIN # ------------------------------------- if __name__ == '__main__': MapManager.mapManager = MapManager.MapManager("NomMap") MapManager.mapManager.loadFileMap() TaxiManager.taxiManager = TaxiManager.TaxiManager(MapManager.mapManager) TaxiManager.taxiManager.newTaxi() """ # TEST TAXI MOVE # Test request clientMessageHandle = {"cabRequest":{"location":{"location":{"to":"m","progression":0.8,"name":"mh","from":"h"},"area":"Quartier Sud","locationType":"street"},"area":"Quartier Sud"}} #clientMessageHandle = {"cabRequest":{"location":{"location":"m","area":"Quartier Sud","locationType":"vertex"},"area":"Quartier Sud"}} TaxiManager.taxiManager.addCabRequest(clientMessageHandle) TaxiManager.taxiManager.onRequestAnswer("yes") path = [] p0 = {} p0["area"] = "Quartier Nord"
#! /usr/bin/env python from MapManager import * if __name__ == '__main__': Map = MapManager("toto") Map.LoadFileMap()
def __init__(self): self.handrail_locator = HandrailLocator.calibrate_from_package_return_handrail_filter() self.map_manager = MapManager.create_sample_map_manager() self.camera = CameraController()
class Driver: """ Game driver. Sets matches, takes input, controls game flow and checks for a winner. """ def __init__(self, map_screen, background_screen, text_screen): """ Constructor. :param map_screen: Surface :param background_screen: Surface :param text_screen: Surface """ self.amount_of_enemies = 0 self.amount_of_empty_colonies = 0 self.map_to_load = None self.race_manager = RaceManager() self.human_players = [] self.players = [] self.map = Map(GUISettings.SCREEN_WIDTH, GUISettings.SCREEN_HEIGHT) self.event_handler = EventHandler(self) self.screen = map_screen self.background_screen = background_screen self.player_one = Player() self.human_players.append(self.player_one) self.sound_driver = SoundDriver() self.map_loader = MapLoader(self) self.text_screen = text_screen self.running = True self.map_manager = MapManager() self.state = MainMenu(self) self.menu = MenuSettings.MAIN_MENU(self) def get_races(self): """ :return: Dictionary with available races """ return self.race_manager.get_races() def get_races_array(self): """ :return: Array with available races """ return self.race_manager.get_races_array() def get_maps(self): """ :return: Dictionary with available maps """ return self.map_manager.get_maps() def get_maps_array(self): """ :return: Array with available maps """ return self.map_manager.get_maps_array() def is_running(self): """ :return: True if the game is running and False otherwise :rtype: bool """ return self.running def quit(self): """ Set running state to False. """ self.running = False def load_map(self): """ Load map from selected data. """ # Clear players self.players = [] # Load map self.map_loader.load_in_map(self.map_to_load, self.map, self.human_players) # Set new players self.players = self.map_loader.players def add_random_player(self): """ Add an enemy with a random race. """ self.players.append(RandomPlayer()) def set_player_name(self, name): """ Set a name for the player. :param name: Name to set """ # TODO: Set and use player name self.player_one.set_name(name) def set_player_race(self, race): """ Set race for the human player. :param race: Race to set """ self.player_one.set_race(race) def get_player_name(self): """ :return: Player's name """ return self.player_one.name def get_player_race(self): """ :return: Player's race """ return self.player_one.race def add_player(self, player): """ :param player: Add a new player to the game """ self.players.append(player) def check_winning_condition(self): """ Check if there's a winner. A race is the winning race when there are no other races on the map. :return The winner :rtype AbstractRace """ win = NullRace() for gr_col in self.map.graphic_colonies: race = gr_col.colony.race if win.same_type(NullRace()): win = race if not race.same_type(NullRace()) and not race.same_type(win): return NullRace() for gr_pty in self.map.graphic_parties: if not gr_pty.party.race.same_type(win): return NullRace() self.won(win) return win def won(self, race): """ React after a winner has been found. :param race: Winning race :type race: AbstractRace """ self.state.won(race) def set_state(self, state): """ Change current game state. :param state: The new state :type state: GameState """ self.state = state def tick(self): """ Actions to perform every tick. """ # Handle input self.handle_events() # Update background self.map.tick_background() # Draw background self.map.draw_background(self.background_screen) # Run main self.run() # Check for a winner self.check_winning_condition() def handle_events(self): """ Ask the event handler to handle input. """ self.event_handler.handle_events() def run(self): """ Run main, specified by current state. """ self.state.run() def get_colonies_in(self, position): """ Get colonies that contain given point. :param position: Point to scan :type position: Point :return: Array of colonies :rtype List """ return self.map.get_colonies_in(position) def select(self, position): """ Select given position and act according to current state. :param position: Position selected :type position: tuple """ position = Point(position[0], position[1]) self.state.select(position) def release_mouse(self, position): """ Release mouse at given position and act according to current state. :param position: Position where release occurs :type position: tuple """ position = Point(position[0], position[1]) self.state.release_mouse(position) def hover(self, position): """ Hover at given position and act according to current state. :param position: Position to hover :type position: tuple """ position = Point(position[0], position[1]) self.state.hover(position) def update_mouse_position(self, position): """ Acknowledge current mouse position. :param position: Mouse position :type position: tuple """ position = Point(position[0], position[1]) self.state.update_mouse_position(position) def pause_key(self): """ Pause key has been pressed. """ self.state.pause() def main_menu_key(self): """ Main menu key has been pressed. """ self.state.main_menu_key() def selection_left(self): """ Selection left key has been pressed. """ self.state.selection_left() def selection_right(self): """ Selection right key has been pressed. """ self.state.selection_right() def selection_up(self): """ Selection up key has been pressed. """ self.state.selection_up() def selection_down(self): """ Selection down key has been pressed. """ self.state.selection_down() def select_key(self): """ Selection key has been pressed. """ self.state.select_key() def load_random_map(self): """ Load a random map. """ # Make screen transparent in one tick self.move_alpha_to(self.screen, 0, 255) # Remove all players self.players = [] # Load map # # self.map_loader.load_in_map(FOUR_BASES, self.map, self.human_players) self.map_loader.load_random(self.map, self.amount_of_empty_colonies, 40, 60, self.human_players, self.amount_of_enemies, self.race_manager.get_races_array()) # Retrieve players for this match self.players = self.map_loader.players @staticmethod def move_alpha_to(surface, target, speed=GUISettings.DEFAULT_ALPHA_CHANGE_SPEED): """ Move alpha of a given surface towards a target value. :param surface: Surface which alpha to change :type surface: Surface :param target: Target alpha value :type target: int :param speed: Maximum change :type speed: int """ current_alpha = surface.get_alpha() if not current_alpha == target: move_dir = (target - current_alpha) / abs(target - current_alpha) move_amount = min(speed, abs(target - current_alpha)) surface.set_alpha(current_alpha + move_dir * move_amount) def start_game(self): """ Start game. Load a map and change state. """ self.load_random_map() self.set_state(InGame(self)) def start_custom_map_game(self): """ Start game. Load a map and change state. """ self.load_map() self.set_state(InGame(self)) def set_menu(self, menu): """ Set current menu. :param menu: Next menu :type menu: Menu """ self.menu = menu def play_select(self): """ Play select sound. """ self.sound_driver.play_select() def play_move_selection(self): """ Play move selection sound. """ self.sound_driver.play_move_selection() def play_taken(self): """ Play taken sound. """ self.sound_driver.play_taken()
class GameManager(object): def __init__(self, gametype, pgui): self.gui = pgui self.filesystem = FileSystem() self.iohandler = IOHandler(gametype, pgui) self.mapmanager = MapManager(self.filesystem.getData('map')) self.mapmanager.getVisibleObjects() self.messagehandler = MessageHandler( self.filesystem.getData("messages")) self.gamerun = False self.securitycamera = True self.talked = False def start(self): msghandler = self.messagehandler iohandler = self.iohandler if self.gui is None: # Tutorial p = self.mapmanager.getPlayer() iohandler.setOutput(msghandler.getMessage("introduction-welcome")) name = iohandler.getInput( msghandler.getMessage("introduction-name")) p.setName(name) iohandler.setOutput( msghandler.getMessage("introduction-personalwelcome").replace( "%name%", p.getName())) iohandler.setOutput(msghandler.getMessage("introduction-help")) res = iohandler.getInput( msghandler.getMessage("introduction-helpcommands")) while res != "help commands": res = iohandler.getInput( msghandler.getMessage( "general-invalidintroductionhelpcommand")) iohandler.setOutput(msghandler.getMessage("general-seperator")) iohandler.setOutput( msghandler.getMessage("commands-commands-info")) iohandler.setOutput(msghandler.getMessage("introduction-end")) # Game begin self.gamerun = True while self.gamerun: iohandler.setOutput(msghandler.getMessage("general-seperator")) input = self.iohandler.getInput( msghandler.getMessage("general-input")) self.__handleCommand(input) else: msg = msghandler.getMessage("introduction-welcome") msg = msg + "\n" + msghandler.getMessage("introduction-help") msg = msg + "\n" + msghandler.getMessage( "introduction-helpcommands") self.gui.write(msg) self.gui.start() def inputtrigger(self): input = self.iohandler.getInput( self.messagehandler.getMessage("general-input")) self.__handleCommand(input) # TODO: REMOVE L2-KARTE FROM DEFAULT INVENTORY def __handleCommand(self, input: str): msghandler = self.messagehandler iohandler = self.iohandler rawcommand = input.split(" ") command = rawcommand[0] args = rawcommand[1:] if command == "help" and len(args) == 1: iohandler.setOutput( msghandler.getMessage("commands-" + args[0] + "-info")) elif command == "quit": exit(0) elif command == "commands": iohandler.setOutput( msghandler.getMessage("commands-commands-info")) elif command == "left": self.mapmanager.rotatePlayer("left") direction = msghandler.getMessage("turn-left") facing = msghandler.getMessage( "turn-" + self.mapmanager.getPlayer().getFacing()) msg = msghandler.getMessage("turn-general").replace( "%direction%", direction).replace("%facing%", facing) iohandler.setOutput(msg) elif command == "right": self.mapmanager.rotatePlayer("right") direction = msghandler.getMessage("turn-right") facing = msghandler.getMessage( "turn-" + self.mapmanager.getPlayer().getFacing()) msg = msghandler.getMessage("turn-general").replace( "%direction%", direction).replace("%facing%", facing) iohandler.setOutput(msg) elif command == "lookaround": objects = self.mapmanager.getVisibleObjects() for o in objects: direction = o[2] objtype = o[0] msg = "" # left if direction == 0: if objtype == "wall": msg = msghandler.getMessage("lookaround-left").replace( "%object%", msghandler.getMessage("lookaround-wall")) elif objtype == "door": msg = msghandler.getMessage("lookaround-left").replace( "%object%", msghandler.getMessage("lookaround-door")) msg = msg + "\n" + msghandler.getMessage( "lookaround-doorname").replace( "%doorname%", o[1].getName()) msg = msg + "\n" + msghandler.getMessage( "lookaround-doorstatus").replace( "%status%", msghandler.getMessage("lookaround-" + o[1].getStatus())) elif objtype == "object": msg = msghandler.getMessage("lookaround-left").replace( "%object%", o[1].getName()) elif objtype == "narrator": msg = msghandler.getMessage("lookaround-left").replace( "%object%", o[1].getName()) # front elif direction == 1: if objtype == "wall": msg = msghandler.getMessage( "lookaround-front").replace( "%object%", msghandler.getMessage("lookaround-wall")) elif objtype == "door": msg = msghandler.getMessage( "lookaround-front").replace( "%object%", msghandler.getMessage("lookaround-door")) msg = msg + "\n" + msghandler.getMessage( "lookaround-doorname").replace( "%doorname%", o[1].getName()) msg = msg + "\n" + msghandler.getMessage( "lookaround-doorstatus").replace( "%status%", msghandler.getMessage("lookaround-" + o[1].getStatus())) elif objtype == "object": msg = msghandler.getMessage( "lookaround-front").replace( "%object%", o[1].getName()) elif objtype == "narrator": msg = msghandler.getMessage( "lookaround-front").replace( "%object%", o[1].getName()) # right elif direction == 2: if objtype == "wall": msg = msghandler.getMessage( "lookaround-right").replace( "%object%", msghandler.getMessage("lookaround-wall")) elif objtype == "door": msg = msghandler.getMessage( "lookaround-right").replace( "%object%", msghandler.getMessage("lookaround-door")) msg = msg + "\n" + msghandler.getMessage( "lookaround-doorname").replace( "%doorname%", o[1].getName()) msg = msg + "\n" + msghandler.getMessage( "lookaround-doorstatus").replace( "%status%", msghandler.getMessage("lookaround-" + o[1].getStatus())) elif objtype == "object": msg = msghandler.getMessage( "lookaround-right").replace( "%object%", o[1].getName()) elif objtype == "narrator": msg = msghandler.getMessage( "lookaround-right").replace( "%object%", o[1].getName()) if len(msg) > 0: iohandler.setOutput(msg) else: iohandler.setOutput( msghandler.getMessage("lookaround-nothing")) elif command == "move": objects = self.mapmanager.getVisibleObjects() obj = None msg = "" for o in objects: direction = o[2] objtype = o[0] if direction == 1: if objtype == "door": if o[1].getStatus() is not "open": msg = msghandler.getMessage( "lookaround-nomove") + " " obj = o break else: if o[1].getName() == "Portal": self.gamerun = False iohandler.setOutput( msghandler.getMessage("general-portalend")) return else: msg = msghandler.getMessage( "lookaround-nomove") + " " obj = o break if obj is not None: objtype = obj[0] if objtype == "wall": msg = msg + msghandler.getMessage( "lookaround-front").replace( "%object%", msghandler.getMessage("lookaround-wall")) elif objtype == "door": if obj[1].getStatus() is not "open": msg = msg + msghandler.getMessage( "lookaround-front").replace( "%object%", msghandler.getMessage("lookaround-door")) elif objtype == "object": msg = msg + msghandler.getMessage( "lookaround-front").replace("%object%", obj[1].getName()) elif objtype == "narrator": msg = msg + msghandler.getMessage( "lookaround-front").replace("%object%", obj[1].getName()) if len(msg) > 0: iohandler.setOutput(msg) else: p = self.mapmanager.getPlayer() pos = p.getPosition() facing = p.getFacing() if facing == "n": pos = [pos[0], pos[1] + 1] elif facing == "e": pos = [pos[0] + 1, pos[1]] elif facing == "s": pos = [pos[0], pos[1] - 1] elif facing == "w": pos = [pos[0] - 1, pos[1]] p.setPosition(pos) if pos == [6, 15] or pos == [7, 15]: if self.securitycamera: self.gamerun = False iohandler.setOutput( msghandler.getMessage("general-gamefailded")) return iohandler.setOutput(msghandler.getMessage("lookaround-move")) elif command == "goto" and len(args) >= 2: pos = [int(args[0]), int(args[1])] objatpos = self.mapmanager.objectAtPosition(pos) if objatpos is not None: iohandler.setOutput(msghandler.getMessage("goto-nomove")) else: p = self.mapmanager.getPlayer() p.setPosition(pos) iohandler.setOutput( msghandler.getMessage("goto-move").replace( "%x%", args[0]).replace("%y%", args[1])) pass elif command == "showinventory": p = self.mapmanager.getPlayer() inv = p.getInventory() if len(inv) == 0: iohandler.setOutput(msghandler.getMessage("inventory-noitems")) else: msg = msghandler.getMessage("inventory-show") for o in inv: msg = msg + "\n" + o.getName() iohandler.setOutput(msg) elif command == "door" and len(args) >= 1: if not (args[0] == "open" or args[0] == "close"): iohandler.setOutput( msghandler.getMessage("general-invalidcommand")) return objects = self.mapmanager.getVisibleObjects() obj = None for o in objects: direction = o[2] objtype = o[0] if direction == 1 and objtype == "door": obj = o[1] break if obj is None: iohandler.setOutput(msghandler.getMessage("door-nodoor")) return status = obj.getStatus() if status == "broken": iohandler.setOutput(msghandler.getMessage("door-broken")) return if args[0] == "open": if status == "open": iohandler.setOutput( msghandler.getMessage("door-alreadystatus").replace( "%status%", msghandler.getMessage("lookaround-open"))) return elif type(obj) == CardDoor: p = self.mapmanager.getPlayer() inv = p.getInventory() # Find the highest keycard in inventory keylevel = "" for o in inv: if "-Karte" in o.getName(): kl = o.getName().replace("-Karte", "") if len(kl) == 2: if len(keylevel) > 0: kllist = kl.split('') keylevellist = keylevel.split('') if kllist[1] > keylevellist[1]: keylevel = kl else: keylevel = kl # Test for exitdoor: if obj.getName() == "Ausgang": found = False for o in inv: if o.getName() == "USB-Stick": found = True if found: res = obj.open(keylevel) if not res: iohandler.setOutput( msghandler.getMessage("door-noperm")) return else: self.gamerun = False iohandler.setOutput( msghandler.getMessage( "general-gamefinished")) return else: iohandler.setOutput( msghandler.getMessage("door-noexit")) return res = obj.open(keylevel) if not res: iohandler.setOutput( msghandler.getMessage("door-noperm")) else: iohandler.setOutput( msghandler.getMessage("door-action").replace( "%action%", msghandler.getMessage("door-opened"))) # Find a matching door code in the inventory elif type(obj) == CodeDoor: p = self.mapmanager.getPlayer() inv = p.getInventory() res = False for o in inv: if "Pincodezettel-" in o.getName(): code = o.getName().replace("Pincodezettel-", "") res = obj.open(code) if res: iohandler.setOutput( msghandler.getMessage("door-action"). replace( "%action%", msghandler.getMessage("door-opened"))) return if not res: iohandler.setOutput( msghandler.getMessage("door-noperm")) else: obj.open() elif args[0] == "close": if status == "close": iohandler.setOutput( msghandler.getMessage("door-alreadystatus").replace( "%status%", msghandler.getMessage("lookaround-close"))) return else: obj.close() iohandler.setOutput( msghandler.getMessage("door-action").replace( "%action%", msghandler.getMessage("door-closed"))) elif command == "getposition": p = self.mapmanager.getPlayer() pos = p.getPosition() iohandler.setOutput( msghandler.getMessage("goto-position").replace( "%x%", str(pos[0])).replace("%y%", str(pos[1]))) elif command == "facing": p = self.mapmanager.getPlayer() facing = p.getFacing() facingmsg = msghandler.getMessage("turn-" + facing) iohandler.setOutput( msghandler.getMessage("turn-facing").replace( "%facing%", facingmsg)) elif command == "object" and len(args) >= 1: if not (args[0] == "showinventory" or args[0] == "getitem" or args[0] == "putitem" or args[0] == "move"): iohandler.setOutput( msghandler.getMessage("general-invalidcommand")) return objects = self.mapmanager.getVisibleObjects() obj = None for o in objects: direction = o[2] objtype = o[0] if direction == 1 and objtype == "object": obj = o[1] break if obj is None: iohandler.setOutput(msghandler.getMessage("object-noobject")) return if args[0] == "showinventory": inv = obj.getInventory() if len(inv) == 0: iohandler.setOutput( msghandler.getMessage("object-noitems").replace( "%objectname%", obj.getName())) return else: msg = msghandler.getMessage("object-show").replace( "%objectname%", obj.getName()) for o in inv: msg = msg + "\n" + o.getName() iohandler.setOutput(msg) elif args[0] == "getitem" and len(args) >= 2: inv = obj.getInventory() p = self.mapmanager.getPlayer() pinv = p.getInventory() for o in inv: if o.getName() == args[1]: inv.remove(o) obj.setInventory(inv) pinv.append(o) p.setInventory(pinv) iohandler.setOutput( msghandler.getMessage("object-get").replace( "%item%", o.getName()).replace("%objectname%", obj.getName())) return iohandler.setOutput( msghandler.getMessage("object-noget").replace( "%name%", args[1]).replace("%objectname%", obj.getName())) elif args[0] == "putitem" and len(args) >= 2: inv = obj.getInventory() p = self.mapmanager.getPlayer() pinv = p.getInventory() for o in pinv: if o.getName() == args[1]: pinv.remove(o) p.setInventory(pinv) inv.append(o) obj.setInventory(inv) iohandler.setOutput( msghandler.getMessage("object-put").replace( "%item%", o.getName()).replace("%objectname%", obj.getName())) return iohandler.setOutput( msghandler.getMessage("object-noput").replace( "%name%", args[1])) elif args[0] == "move" and len(args) >= 2: if not (args[1] == "left" or args[1] == "right" or args[1] == "forward"): iohandler.setOutput( msghandler.getMessage("general-invalidcommand")) return p = self.mapmanager.getPlayer() ppos = p.getPosition() pfacing = p.getFacing() if not obj.isMovable(): iohandler.setOutput( msghandler.getMessage("object-nomove").replace( "%objectname%", obj.getName())) return objpos = obj.getPosition() postomove = objpos if pfacing == "n": if args[1] == "left": postomove = [objpos[0] - 1, objpos[1]] elif args[1] == "right": postomove = [objpos[0] + 1, objpos[1]] elif args[1] == "forward": postomove = [objpos[0], objpos[1] + 1] elif pfacing == "e": if args[1] == "left": postomove = [objpos[0], objpos[1] + 1] elif args[1] == "right": postomove = [objpos[0], objpos[1] - 1] elif args[1] == "forward": postomove = [objpos[0] + 1, objpos[1]] elif pfacing == "s": if args[1] == "left": postomove = [objpos[0] + 1, objpos[1]] elif args[1] == "right": postomove = [objpos[0] - 1, objpos[1]] elif args[1] == "forward": postomove = [objpos[0], objpos[1] - 1] elif pfacing == "w": if args[1] == "left": postomove = [objpos[0], objpos[1] - 1] elif args[1] == "right": postomove = [objpos[0], objpos[1] + 1] elif args[1] == "forward": postomove = [objpos[0] - 1, objpos[1]] objatpos = self.mapmanager.objectAtPosition(postomove) if objatpos is not None: objname = "" if type(objatpos) == list: objname = msghandler.getMessage("lookaround-wall") elif type(objatpos) == Object: objname = objatpos.getName() else: objname = msghandler.getMessage("lookaround-door") iohandler.setOutput( msghandler.getMessage("object-nomoveblocked").replace( "%objectname%", objname)) return obj.setPosition(postomove) dir = msghandler.getMessage("turn-" + args[1]) iohandler.setOutput( msghandler.getMessage("object-moved").replace( "%direction%", dir)) elif command == "hackserver": objects = self.mapmanager.getVisibleObjects() obj = None msg = "" for o in objects: direction = o[2] objtype = o[0] if direction == 1: if type(o[1]) == Object: if o[1].getName() == "Server": obj = o[1] break if not obj: msg = msghandler.getMessage("server-noserver") else: if not self.securitycamera: msg = msghandler.getMessage("server-alreadyhacked") else: self.securitycamera = False msg = msghandler.getMessage("server-hacked") iohandler.setOutput(msg) elif command == "talk": objects = self.mapmanager.getVisibleObjects() obj = None msg = "" for o in objects: direction = o[2] objtype = o[0] if direction == 1: if objtype == "narrator": obj = o[1] if obj is None: msg = msghandler.getMessage("talk-notalk") else: if self.talked: msg = msghandler.getMessage("talk-talk") else: msg = msghandler.getMessage("talk-talk") self.talked = True p = self.mapmanager.getPlayer() inv = p.getInventory() key = Object("L2-Karte", 999, False, True, None, None) inv.append(key) p.setInventory(inv) msg = msg + "\n" + msghandler.getMessage("talk-keycard") iohandler.setOutput(msg) else: iohandler.setOutput( msghandler.getMessage("general-invalidcommand"))
def updateUI(self): # Battle Rooms if self.paneltab == 1: # current battle return if self.paneltab == 2: # all battles panel = self.wParent w = panel.width() h = panel.height() # this is set by a callback from the MapManager module # when a asynchronous URL fetch is done to get the # minimap image, or anything else and we need to redraw self.mapsUpdated = False painter = QtGui.QPainter(panel) painter.setFont(QtGui.QFont('Tahoma')) fontm = painter.fontMetrics() # create options # - option for show empty # - option for show full # - option for official games # - search box for game description # - button to open new battle # clear any controls from the other panel widgets = self.widgets for k in widgets: if k.find('bs_') != 0: w = widgets[k] # unref it from the wid w.setParent(None) widgets[k] = None # basically we create them like this so we can easily # clear them if they switch to the current battle panel if 'bs_scroll' not in widgets: widgets['bs_scroll'] = QtGui.QScrollBar(panel) widgets['bs_scroll'].valueChanged.connect(self.sbValueChanged) bs_scroll = widgets['bs_scroll'] bs_scroll.move(panel.width() - 15, 50) bs_scroll.resize(15, panel.height() - 50) bs_scroll.show() if 'bs_spanel' not in widgets: bs_spanel = QtGui.QWidget(panel) bs_bl = QtGui.QHBoxLayout() widgets['bs_spanel'] = bs_spanel bs_spanel.move(0, 0) bs_spanel.resize(panel.rect().width(), 50) bs_spanel.setLayout(bs_bl) bs_spanel.show() widgets['bs_newbattle'] = QtGui.QPushButton(panel) widgets['bs_newbattle'].setText('New Battle') widgets['bs_newbattle'].show() bs_bl.addWidget(widgets['bs_newbattle']) widgets['bs_showempty'] = QtGui.QCheckBox(panel) widgets['bs_showempty'].setText('Show Empty') widgets['bs_showempty'].show() bs_bl.addWidget(widgets['bs_showempty']) widgets['bs_showfull'] = QtGui.QCheckBox(panel) widgets['bs_showfull'].setText('Show Full') widgets['bs_showfull'].show() bs_bl.addWidget(widgets['bs_showfull']) widgets['bs_nextpage'] = QtGui.QPushButton(panel) widgets['bs_nextpage'].setText('Next Page') widgets['bs_nextpage'].show() bs_bl.addWidget(widgets['bs_nextpage']) widgets['bs_prevpage'] = QtGui.QPushButton(panel) widgets['bs_prevpage'].setText('Prev Page') widgets['bs_prevpage'].show() bs_bl.addWidget(widgets['bs_prevpage']) gyoff = 50 gridw = 400 gridh = 100 colcnt = int(w / gridw) rowcnt = int(h / (gridh - gyoff)) + 1 widgets['bs_scroll'].setRange(0, rowcnt * gridh) if 'battleimg' not in self.image_cache: self.image_cache['battleimg'] = QtGui.QImage('./images/surprised-skull-2.png') if colcnt < 1: colcnt = 1 if rowcnt < 1: rowcnt = 1 # battles bc = 0 sz = colcnt * rowcnt off = self.page * (colcnt * rowcnt) for bk in self.battles: b = self.battles[bk] #andx = bc - off # actual index (relative to page) andx = bc bc = bc + 1 arow = int(andx / colcnt) # actual row acol = andx - (arow * colcnt) # actual col ax = acol * gridw # actual x (col) ay = arow * gridh # actual y (row) # above the top if ay + gridh < self.sbpixel: continue # past the bottom if ay > (self.sbpixel + h): continue # adjust for slider position ay = ay - self.sbpixel # okay render this to the panel #mapImage = self.mapCacheGet(b['map']) mapImage = MapManager.fetchMiniMapAsync(b['map'], self.mapFetchAsyncCb) if mapImage is not None: painter.drawImage( QtCore.QRect(ax, ay + gyoff, 100, 100), mapImage, QtCore.QRect(0, 0, -1, -1) ) for p in b['players']: if p in self.players: if self.players[p]['inGame']: painter.drawImage( QtCore.QRect(ax, ay + gyoff, 100, 100), self.image_cache['battleimg'], QtCore.QRect(0, 0, -1, -1) ) break ######################### if acol == colcnt - 1: tw = w - ax else: tw = gridw painter.drawRect(ax, ay + gyoff, tw, gridh) painter.drawText(ax + 110, gyoff + ay + fontm.height() * 0 + 10, 'Mod: %s' % b['mod']) painter.drawText(ax + 110, gyoff + ay + fontm.height() * 1 + 10, 'Desc: %s' % b['desc']) painter.drawText(ax + 110, gyoff + ay + fontm.height() * 2 + 10, 'Map: %s' % b['map']) painter.drawText(ax + 110, gyoff + ay + fontm.height() * 3 + 10, 'Players/Specs: %s/%s' % (len(b['players']) - b['specs'], b['specs'])) #################################### cntSpecs = b['specs'] cntInGame = 0 for p in b['players']: if p in self.players: if self.players[p]['inGame']: cntInGame = cntInGame + 1 cntIdle = len(b['players']) - cntInGame - cntSpecs maxp = b['maxPlayers'] perRow = 20 c_InGame = QtGui.QColor(0x00, 0xff, 0x00) c_Spec = QtGui.QColor(0x00, 0xff, 0xff) c_Idle = QtGui.QColor(0x00, 0x00, 0x00) c_Empty = QtGui.QColor(0x99, 0x99, 0x99) i = 0 while i < maxp: row = int(i / perRow) col = i - (row * perRow) __y = row * 10 + ay + fontm.height() * 4 + 10 + gyoff __x = col * 10 + ax + 110 if cntInGame > 0: cntInGame = cntInGame - 1 c = c_InGame elif cntSpecs > 0: cntSpecs = cntSpecs - 1 c = c_Spec elif cntIdle > 0: cntIdle = cntIdle - 1 c = c_Idle else: c = c_Empty painter.fillRect(__x, __y, 7, 7, c) i = i + 1 ##################### continue ##################### return return
if __name__ == '__main__': curses.initscr() curses.beep() curses.beep() window = curses.newwin(HEIGHT, WIDTH, 0, 0) window.timeout(TIMEOUT) window.keypad(1) curses.noecho() curses.curs_set(0) window.border(0) characterManager = CharactersManager() treasureManager = TreasureManager() myMap = MapManager.Map() myMap.creer_niveau() coord = myMap.listeSalles[1][1].pos character = Characters("me", (coord[0] + 2, coord[1] + 2), 100, 10, 0.8, 10) while True: window.clear() window.border(0) renderMap(window, myMap.carte) window.addstr(character.position[0] + 1, character.position[1] + 1, '*') for monster in characterManager.instance.charactersList: window.addstr(monster.position[0] + 1, monster.position[1] + 1,
import MapMonitor, MapManager, TimeManager, DijkstraHandler mapM = MapManager.MapManager() mapM.inputManager() dijH = DijkstraHandler.DijkstraHandler(mapM.getGraph()) while True: inStr = input().split() dijH.dijkstra(float(inStr[1]), float(inStr[2]), float(inStr[0]) / 120) monM = MapMonitor.MapMonitor(dijH.dstnc, dijH.prvus, mapM.getGraph(), float(inStr[2])) monM.ploter() print( "Time :{}\n_____________________________________________________________________________\n " .format(dijH.dstnc[float(inStr[2])] * 120))
def setUp(self): # Init core-objects self.mapManager = MapManager([200, 200]) self.network = BayesianNetwork(self.mapManager) self.nodes = [BayesianNode(self.network) for i in range(0,10)]
def run(self): """ periodically querys the keyboard keypress and acts accordingly in its own thread. responds to the following keypresses: F1, F2, F3, F4 and mouse clicks """ while not global_vars.quit: sleep(0.01) key = WinMan.key_pressed() if key == 268: #F4 / Quit global_vars.quit = True continue if global_vars.hidden_run: continue if key == 265: #F1 / Pause global_vars.pause = True WinMan.replace_option("Pause", "Resume") WinMan.replace_option("Faster", "Single Step") WinMan.replace_option("Slower", "") WinMan.update() global_vars.swap_step_duration = global_vars.step_duration global_vars.step_duration = 0.1 while True: key = WinMan.key_pressed() if key == 265: #F1 / Resume (changed at this point) global_vars.pause = False global_vars.step_duration = global_vars.swap_step_duration WinMan.replace_option("Resume", "Pause") WinMan.replace_option("Single Step", "Faster") WinMan.replace_option("", "Slower") break elif key == 266: global_vars.single_step = True elif key == 268: #F4 / Quit global_vars.quit = True break elif key == curses.KEY_MOUSE: id, x, y, z, bstate = curses.getmouse() MapMan.set_watched_entity(y - 2, x) WinMan.update(tile_info=MapMan.watch_info()) sleep(0.01) elif key == 266: #F2 / Faster global_vars.step_duration = round( global_vars.step_duration - 0.1, 1 ) if global_vars.step_duration <= 0: global_vars.step_duration = 0.1 WinMan.update() elif key == 267: #F3 / Slower global_vars.step_duration = round( global_vars.step_duration + 0.1, 1 ) if global_vars.step_duration > 2: global_vars.step_duration = 2 WinMan.update() elif key == curses.KEY_MOUSE: id, x, y, z, bstate = curses.getmouse() MapMan.set_watched_entity(y - 2, x)