Ejemplo n.º 1
0
def main():
    global stdscr

    print BT_LOGO
    time.sleep(1)

    try: # Crash protection ;)
        init.init()
        stdscr = init.stdscr

        h, w = stdscr.getmaxyx()

        # Create falco and put him into the map
#        falco = Person(-1, "Falco", -1, [0, 0], ["F", curses.COLOR_WHITE, curses.COLOR_BLUE],
#                   configs.colorof["falco"][0])
#        falco.jumpTo(1, 0)
#        falco.crashWith = FalcoCrashMike

        theWorld = world.World(stdscr, w, h)

        # Mike is the hero!
        mike = Player(theWorld.statusBox, -1, "Du", -1, [0, 0], ["M", curses.COLOR_BLACK, curses.COLOR_RED],
                      configs.colorof["mike"][0], profile={"hp": [100, 100],
                                                       "mp": [0, 0]})

        # Adding mike and falco to Bermuda Triangle World
        theWorld.setPlayer(mike)
#        theWorld.addPerson(falco)

        theWorld.setCheatWalkEverywhere(False)

        # Adding water in map (mike cannot move on it)
        for i in range(10):
            theWorld.gMaps[1][1].gMap[10][i] = ["~", curses.COLOR_WHITE, curses.COLOR_BLUE, True, nothing]
        for i in range(10):
            theWorld.gMaps[1][0].gMap[10][198-i] = ["~", curses.COLOR_WHITE, curses.COLOR_BLUE, False, nothing]

        theWorld.load("testsave")
    
    
        while 1:                     # Gameloop
            timer.fpsDelay()         # FPS-Control
            clearError()
                                     # +++ Event handling +++
            c = stdscr.getch()       # I don't think an eventloop is needed in a
                                     # textadventure
            if c == ord("q"):
                theWorld.sendText("Bitte im Menue Beenden ('m' druecken)")
            if c == ord("w"): # Switches between colored and b/w
                misc.COLORED = not misc.COLORED
                theWorld.redrawAllMaps()
            if c == ord("m"): menu.start() # Enter menu
            if c == ord("h"): theWorld.playerGoLeft()  #
            if c == ord("j"): theWorld.playerGoDown()  #  Player
            if c == ord("k"): theWorld.playerGoUp()    #  movement
            if c == ord("l"): theWorld.playerGoRight() #
            if c == ord("s"): theWorld.load("testsave.btt")  # Loading doesn't really work ;)
            if c == ord("x"): theWorld.sendText(str(mike.gMap.pos))
            # --- Event handling ---

            # +++ Drawing +++
            oldH = h   # Need this for resizing
            oldW = w
            h, w = stdscr.getmaxyx()
            #stdscr.erase()
            # Window size exception
            if (w < 70) | (h < 24):
                stdscr.erase()
                stdscr.addstr(h/2, (w - len(BT_WINDOW_TOO_SMALL)) / 2,
                              BT_WINDOW_TOO_SMALL)
            elif misc.BT_ERROR != "":
                stdscr.addstr(h/2, (w - len(misc.BT_ERROR)) / 2,
                              misc.BT_ERROR)
            else:
                # Check for resize event
                if (oldH != h) | (oldW != w):
                    stdscr.erase()  # Have to clear the whole screen. Maybe this should do the theWorld object...
                    theWorld.resize(w, h)

                # Painting wonderful border ;)
                stdscr.box()
                stdscr.addstr(0, (w - len(BT_SMALL_LOGOTEXT)) / 2,
                              BT_SMALL_LOGOTEXT)

                theWorld.draw(stdscr)
                waveWare(w - 10, h - 1, stdscr)

            stdscr.refresh()
        # --- Drawing ---
    
        init.quit()

    except SystemExit:   # This is not really an error so there happens nothing
        pass
    except:              # If there was an error python will do this:
        # Exiting curses
        curses.nocbreak()
        stdscr.keypad(0)
        curses.echo()
        curses.endwin()

        # Telling there is went something wrong
        print "Hardcore error in Bermuda Triangle " + BT_VERSION + " :`(  Exiting forced!!!"
        print "Please send bt_last_error.log and a  description what you did"
        print "to [email protected]"

        # Writing error to file
        errorFile = file("bt_last_error.log", "w")
        errorFile.write("Error in Bermuda Triangle Text - Version " + BT_VERSION + "\n")
        traceback.print_exc(file=errorFile)
        errorFile.close()

        # If debug is switched on it will print the error to stdout
        if misc.DEBUG:
            traceback.print_exc()
Ejemplo n.º 2
0
def main():
    global stdscr, theWorld, cursor

    print BT_LOGO
    time.sleep(1)

    try: # Crash protection ;)
        init.init()
        stdscr = init.stdscr

        h, w = stdscr.getmaxyx()

        world.foreground = foreground
        world.background = background
        theWorld = world.World(stdscr, w, h, filename = sys.argv[1])
        theWorld.statusBox = statusbox.EditorStatusBox(stdscr, w, h, 
                                                       w / 2)
        theWorld.statusBox.newField(theWorld.maps[0, 0][0, 0])
        world.World.borderFunction = borderFunction
        theWorld.resize(w, h)

        theWorld.keys = {
            "h": [theWorld.playerGoLeft, (True,)],
            "j": [theWorld.playerGoDown, (True,)],
            "k": [theWorld.playerGoUp, (True,)],
            "l": [theWorld.playerGoRight, (True,)],
            "c": [executeCode, ()],
            "C": [repeatCode, ()],
            "A": [insertFile, ()],
            "a": [insertAscii, ()],
            "t": [insertText, ()],
            "v": [insertVText, ()],
            "F": [fill, ()],
            "T": [addTrigger, ()],
            "r": [addRTrigger, ()],
            "f": [changeForeground, ()],
            "b": [changeBackground, ()],
            "g": [changeWalkable, ()],
            "s": [saveMap, ()],
            "e": [insertFlag, ()]
        }
        # Initialize cursor object
        cursor = Player(theWorld.statusBox, -1, "Cursor", -1, theWorld, [0, 0], ["C", 0, 3],
                      configs.colorof["mike"][0], profile={"hp": [100, 100],
                                                       "mp": [0, 0]})

        theWorld.sendText("BTText Map Editor!")
        
        # Adding cursor to the world
        theWorld.setPlayer(cursor)

        # Loading editor initializing file
        try:
            filename = "%s/editinit.py" % sys.argv[1]
            initFile = file(filename).read()
            theWorld.evalCode(initFile, filename)
        except:
            theWorld.sendText(btText('Could not load editinit.py'))
            theWorld.sendText(btText('Use this file to extend this editor'))
            theWorld.sendText(str(sys.exc_info()[0]))
            theWorld.sendText(str(sys.exc_info()[1]))


        while 1:                     # Gameloop
            timer.fpsDelay()         # FPS-Control
            clearError()

            c = None
                                     # +++ Event handling +++
            try:
                c = stdscr.getkey()
            except curses.error:
                pass
                                     # textadventure
            if c == "q":
                init.quit()
                sys.exit()
#            if c == "w": # Switches between colored and b/w
#                misc.COLORED = not misc.COLORED
#                theWorld.redrawAllMaps()
            keys = theWorld.keys
            if c in keys:
                elem = keys[c]
                elem[0](*elem[1])
                if '' in keys:
                    elem = keys['']
                    elem[0](*elem[1])
#            if c == ord("m"): menu.start() # Enter menu
#            if c == ord("h"): theWorld.playerGoLeft()  #
#            if c == ord("j"): theWorld.playerGoDown()  #  Cursor
#            if c == ord("k"): theWorld.playerGoUp()    #  movement
#            if c == ord("l"): theWorld.playerGoRight() #
#            if c == ord("s"): theWorld.save("testsave.btt")  # Loading doesn't really work ;)
#            if c == ord("a"): insertAscii()
#            if c == ord("t"): insertText()
#            if c == ord("f"): changeForeground()
#            if c == ord("b"): changeBackground()

            # --- Event handling ---

            # +++ Drawing +++
            oldH = h   # Need this for resizing
            oldW = w
            h, w = stdscr.getmaxyx()
            #stdscr.erase()
            # Window size exception
            if (w < 70) | (h < 24):
                stdscr.erase()
                stdscr.addstr(h/2, (w - len(BT_WINDOW_TOO_SMALL)) / 2,
                              BT_WINDOW_TOO_SMALL)
            elif misc.BT_ERROR != "":
                stdscr.addstr(h/2, (w - len(misc.BT_ERROR)) / 2,
                              misc.BT_ERROR)
            else:
                # Check for resize event
                if (oldH != h) | (oldW != w):
                    stdscr.erase()  # Have to clear the whole screen. Maybe this should do the theWorld object...
                    theWorld.resize(w, h)

                # Painting wonderful border ;)
                stdscr.box()
                stdscr.addstr(0, (w - len(BT_SMALL_LOGOTEXT)) / 2,
                              BT_SMALL_LOGOTEXT)

                theWorld.draw(stdscr)
                waveWare(w - 10, h - 1, stdscr)

            stdscr.refresh()
        # --- Drawing ---
    
        init.quit()

    except SystemExit:   # This is not really an error so there happens nothing
        pass
    except:              # If there was an error python will do this:
        # Exiting curses
        curses.nocbreak()
        stdscr.keypad(0)
        curses.echo()
        curses.endwin()

        # Telling there is went something wrong
        print "Hardcore error in Bermuda Triangle " + BT_VERSION + " :`(  Exiting forced!!!"
        print "Please send bt_last_error.log and a  description what you did"
        print "to [email protected]"

        # Writing error to file
        errorFile = file("bt_last_error.log", "w")
        errorFile.write("Error in Bermuda Triangle Text - Version " + BT_VERSION + "\n")
        traceback.print_exc(file=errorFile)
        errorFile.close()

        # If debug is switched on it will print the error to stdout
        if misc.DEBUG:
            traceback.print_exc()
Ejemplo n.º 3
0
def main():
    global stdscr, theWorld, cursor

    print BT_LOGO
    time.sleep(1)

    try: # Crash protection ;)
        init.init()
        stdscr = init.stdscr

        h, w = stdscr.getmaxyx()


        theWorld = world.World(stdscr, w, h)

        shortcutList = [
            ["h", theWorld.playerGoLeft],
            ["j", theWorld.playerGoDown],
            ["k", theWorld.playerGoUp],
            ["l", theWorld.playerGoRight],
            ["a", insertAscii],
            ["t", insertText],
            ["f", changeForeground],
            ["b", changeBackground],
            ["g", changeWalkable],
            ["s", saveMap],
            ["e", insertFlag]]
        # Initialize cursor object
        cursor = Player(theWorld.statusBox, -1, "Cursor", -1, [0, 0], ["C", 0, 3],
                      configs.colorof["mike"][0], profile={"hp": [100, 100],
                                                       "mp": [0, 0]})

        theWorld.sendText("BTText Map Editor!")
        
        # Adding cursor to the world
        theWorld.setPlayer(cursor)

        theWorld.setCheatWalkEverywhere(True)

        while 1:                     # Gameloop
            timer.fpsDelay()         # FPS-Control
            clearError()
                                     # +++ Event handling +++
            c = stdscr.getch()       # I don't think an eventloop is needed in a
                                     # textadventure
            if c == ord("q"):
                init.quit()
                sys.exit()
            if c == ord("w"): # Switches between colored and b/w
                misc.COLORED = not misc.COLORED
                theWorld.redrawAllMaps()
            for elem in shortcutList:
                if c == ord(elem[0]):
                    elem[1]()
#            if c == ord("m"): menu.start() # Enter menu
#            if c == ord("h"): theWorld.playerGoLeft()  #
#            if c == ord("j"): theWorld.playerGoDown()  #  Cursor
#            if c == ord("k"): theWorld.playerGoUp()    #  movement
#            if c == ord("l"): theWorld.playerGoRight() #
#            if c == ord("s"): theWorld.save("testsave.btt")  # Loading doesn't really work ;)
#            if c == ord("a"): insertAscii()
#            if c == ord("t"): insertText()
#            if c == ord("f"): changeForeground()
#            if c == ord("b"): changeBackground()

            # --- Event handling ---

            # +++ Drawing +++
            oldH = h   # Need this for resizing
            oldW = w
            h, w = stdscr.getmaxyx()
            #stdscr.erase()
            # Window size exception
            if (w < 70) | (h < 24):
                stdscr.erase()
                stdscr.addstr(h/2, (w - len(BT_WINDOW_TOO_SMALL)) / 2,
                              BT_WINDOW_TOO_SMALL)
            elif misc.BT_ERROR != "":
                stdscr.addstr(h/2, (w - len(misc.BT_ERROR)) / 2,
                              misc.BT_ERROR)
            else:
                # Check for resize event
                if (oldH != h) | (oldW != w):
                    stdscr.erase()  # Have to clear the whole screen. Maybe this should do the theWorld object...
                    theWorld.resize(w, h)

                # Painting wonderful border ;)
                stdscr.box()
                stdscr.addstr(0, (w - len(BT_SMALL_LOGOTEXT)) / 2,
                              BT_SMALL_LOGOTEXT)

                theWorld.draw(stdscr)
                waveWare(w - 10, h - 1, stdscr)

            stdscr.refresh()
        # --- Drawing ---
    
        init.quit()

    except SystemExit:   # This is not really an error so there happens nothing
        pass
    except:              # If there was an error python will do this:
        # Exiting curses
        curses.nocbreak()
        stdscr.keypad(0)
        curses.echo()
        curses.endwin()

        # Telling there is went something wrong
        print "Hardcore error in Bermuda Triangle " + BT_VERSION + " :`(  Exiting forced!!!"
        print "Please send bt_last_error.log and a  description what you did"
        print "to [email protected]"

        # Writing error to file
        errorFile = file("bt_last_error.log", "w")
        errorFile.write("Error in Bermuda Triangle Text - Version " + BT_VERSION + "\n")
        traceback.print_exc(file=errorFile)
        errorFile.close()

        # If debug is switched on it will print the error to stdout
        if misc.DEBUG:
            traceback.print_exc()
Ejemplo n.º 4
0
Archivo: bt.py Proyecto: kidaa/bttext
def main():
    global stdscr

    print BT_LOGO
    time.sleep(1)

    try: # Crash protection ;)
        init.init()
        stdscr = init.stdscr

        h, w = stdscr.getmaxyx()

        theWorld = world.World(stdscr, w, h, filename=sys.argv[1])
#        world.World.step = step

        # Mike is the hero!
        player = Player(theWorld.statusBox, -1, "Du", -1, theWorld, [0, 0], ["M", curses.COLOR_BLACK, curses.COLOR_RED],
                      configs.colorof["mike"][0], profile={"hp": [100, 100],
                                                       "mp": [0, 0]})

        # Adding mike to Bermuda Triangle World
        theWorld.setPlayer(player)

        theWorld.keys = {
                "q":
                    [theWorld.sendText,
                     ("Use the menu to quit (press 'm')",)],
#                "w": # Switches between colored and b/w
#                    misc.COLORED = not misc.COLORED
#                    theWorld.redrawAllMaps()
                "m": [menu.start, ()], # Enter menu
                "h": [theWorld.playerGoLeft, ()],  #
                "j": [theWorld.playerGoDown, ()],  #  Player
                "k": [theWorld.playerGoUp, ()],    #  movement
                "l": [theWorld.playerGoRight, ()], #
                "KEY_LEFT": [theWorld.playerGoLeft, ()],
                "KEY_RIGHT": [theWorld.playerGoRight, ()],
                "KEY_UP": [theWorld.playerGoUp, ()],
                "KEY_DOWN": [theWorld.playerGoDown, ()],
                "y": [theWorld.attackLeft, ()],
                "z": [theWorld.attackLeft, ()],
                "u": [theWorld.attackDown, ()],
                "i": [theWorld.attackUp, ()],
                "o": [theWorld.attackRight, ()],
                "c": [executeCode, (theWorld,)],
#                "x": [theWorld.sendText, (str(mike.gMap.pos))],
        }

        theWorld.onStepDict['trigger'] = [trigger, ()]
        theWorld.onStepDict['rtrigger'] = [rtrigger, ()]
        theWorld.onStepDict['crash'] = [crash, ()]

        theWorld.onFrameDict['personOnFrame'] = [personOnFrame, ()]

        # Try to load and evaluate the init file.
        try:
            filename = "%s/init.py" % sys.argv[1]
            initFile = file(filename).read()
#            code = compile(initFile, filename, 'exec')
#            eval(code)
            theWorld.evalCode(initFile)
        except:
            theWorld.sendText('Could not load init.py')

        while 1:                     # Gameloop
            timer.fpsDelay()         # FPS-Control
            clearError()
                                     # +++ Event handling +++
            try:
                c = stdscr.getkey() 
                if c in theWorld.keys:
                    elem = theWorld.keys[c]
                    elem[0](*elem[1])

            # --- Event handling ---
            except SystemExit:
                raise SystemExit
            except curses.error:
                pass
            except:
                theWorld.sendText(str(sys.exc_info()[0]))
                theWorld.sendText(str(sys.exc_info()[1]))

            theWorld.frame()

            # +++ Drawing +++
            oldH = h   # Need this for resizing
            oldW = w
            h, w = stdscr.getmaxyx()
            #stdscr.erase()
            # Window size exception
            if (w < 70) | (h < 24):
                stdscr.erase()
                stdscr.addstr(h/2, (w - len(BT_WINDOW_TOO_SMALL)) / 2,
                              BT_WINDOW_TOO_SMALL)
            elif misc.BT_ERROR != "":
                stdscr.addstr(h/2, (w - len(misc.BT_ERROR)) / 2,
                              misc.BT_ERROR)
            else:
                # Check for resize event
                if (oldH != h) | (oldW != w):
                    stdscr.erase()  # Have to clear the whole screen. Maybe this should do the theWorld object...
                    theWorld.resize(w, h)

                # Painting wonderful border ;)
                stdscr.box()
                stdscr.addstr(0, (w - len(BT_SMALL_LOGOTEXT)) / 2,
                              BT_SMALL_LOGOTEXT)

                theWorld.draw(stdscr)
                waveWare(w - 10, h - 1, stdscr)

            stdscr.refresh()
        # --- Drawing ---
    

    except SystemExit:   # This is not really an error so there happens nothing
        init.quit()
    except:              # If there was an error python will do this:
        init.quit()
        # Exiting curses
        curses.nocbreak()
        stdscr.keypad(0)
        curses.echo()
        curses.endwin()

        # Telling there is went something wrong
        print "Error!"
        print "Please send bt_last_error.log and a  description what you did"
        print "to [email protected]"

        # Writing error to file
        errorFile = file("bt_last_error.log", "w")
        errorFile.write("Error in Bermuda Triangle Text - Version " + BT_VERSION + "\n")
        traceback.print_exc(file=errorFile)
        errorFile.close()

        # If debug is switched on it will print the error to stdout
        if misc.DEBUG:
            traceback.print_exc()