Example #1
0
    def __init__(self, GAME, floorConfig=None, loop=True, cartridgeReader=False, init=True):
        self.cartridgeReader = cartridgeReader
        self.loop = loop
        self.wait = time.sleep
        if floorConfig is None:
            conf = LSFloorConfig()
            conf.selectConfig()
        else:
            conf = LSFloorConfig(floorConfig)
        if conf.containsVirtual() is True:
            self.REAL_FLOOR = False
        else:
            self.REAL_FLOOR = True

        self.audio = LSAudio(initSound=init)
        self.display = LSDisplay(conf=conf, eventCallback = self.handleTileStepEvent, initScreen=init)

        self.ROWS = conf.rows
        self.COLUMNS = conf.cols
        os.system('cls' if os.name == 'nt' else 'clear')
        print("Board size is {:d}x{:d}".format(self.ROWS, self.COLUMNS))
            
        self.GAME = GAME
        self.moves = []
        self.sensorMatrix = defaultdict(lambda: defaultdict(int))
        self.currentGame = None
        self.newGame(self.GAME)

        #these are for bookkeeping
        self.frames = 0
        self.frameRenderTime = 0
        
        # This lock prevents handleTileStepEvent() from being run by polling loops before init is complete
        self.initLock.set()
    def __init__(self, rows=None, cols=None, conf=None, eventCallback=None, initScreen=True):
        if conf is None:
            if rows is None or cols is None:
                conf = LSFloorConfig()
                conf.selectConfig()
            else:
                conf = LSFloorConfig(rows=rows, cols=cols)
                conf.makeVirtual()

        self.floor = LSFloor(conf, eventCallback = eventCallback)

        try:
            self.floor.register(LSPygameFloor)      # For now it's the only emulator we have
        except BadEmulator:
            self.floor.register(LSASCIIFloor)

        self.rows = conf.rows
        self.cols = conf.cols
        self.lastTileSetTimestamp = time.time()

        if initScreen is True:
            self.splash()
            wait(3)
            self.clearAll()
Example #3
0
def main():

    print("\nLightsweeper Configuration utility")

    conf = lsconfig.readConfiguration()
    try:
        floorDir = conf["FLOORSDIR"]
    except KeyError:
        floorDir = conf["CONFIGDIR"]

    floorFiles = list(filter(lambda ls: ls.endswith(".floor"), os.listdir(floorDir)))

    if len(floorFiles) is 0:
        config = None
    else:
        choices = floorFiles
        NEW = "New Floor"
        choices.insert(0, NEW)
        selection = userSelect(choices, "\nWhich floor configuration would you like to edit?")
        if selection == NEW:
            config = None
        else:
            fileName = selection
            absFloorConfig = os.path.abspath(os.path.join(floorDir, fileName))
            try:
                config = LSFloorConfig(absFloorConfig)
            except lsconfig.CannotParseError as e:
                print("\nCould not parse the configuration at {:s}: {:s}".format(absFloorConfig, e))

    if config is None:                              # Start a new configuration
        config = interactiveConfig()

    elif config.cells is 0:     # Start a new configuration with a pre-existing filename
        config = interactiveConfig(config)

    else:                       # Load an existing configuration for editing
        print("\nThis is the configuration saved in " + config.fileName + ":\n")
        config.printConfig()

        print("\nBut the editing code is not here yet. Sorry.")
        exit()


    print("\nThis is the configuration: ")
    config.printConfig()

    if config.fileName is None:
        fileName = input("\nPlease enter a filename for this configuration (or blank to not save): ")
    else:
        fileName = config.fileName
    if fileName == "":
        print("OK, not saving this configuration.")
    else:
        try:
            config.writeConfig(fileName)
        except FileExistsError:
            if yesNO("{:s} already exists, would you like to overwrite it?".format(config.fileName)) is True:
                config.writeConfig(fileName, overwrite=True)
            else:
                print("OK, not saving any changes to this configuration.")
            

    input("\nDone - Press the Enter key to exit") # keeps double-click window open