Exemplo n.º 1
0
# Minus 1 col for last doesn't handle |CR Properly in populated with a character
real_width = bbs_io.pyGetTermWidth() - 1

url = 'http://bbs-scene.org/api/onelinerz.php?limit=%s' % str(real_limit)

bbs_io.pyPipe2Ansi("|CS|15 Loading Global BBS-Scene OneLiners|CR|CR")

req = requests.get(url, auth=(usrname, pssword))
if 200 != req.status_code:
    print 'error %s' % req.content
    print 'error %s' % req.status_code
    exit(1)

ansifile = "onelinerz"
bbs_io.pyAnsiPrintf(ansifile)

# can throw exceptions when xml is invalid, as a thread, nobody needs
# to catch it. theres some things that should be CDATA wrapped .. these
# break even viewing it in firefox, but upstream doesn't seem to
# notice, probably upstream does print('<xml_node>' + var +
# '</xml_node>'), i've found more than a few nasty escape flaws,
# we're breaking the shit out of encoding here, but most other bbs's
# are US-ASCII (cp437)-only, and bbs-api doesn't care

buf = ''.join((byte for byte in req.content
               if (ord(byte) >= 0x20 or ord(byte) in (0x09, 0x0a, 0x0d, 0x7f))
               and ord(byte) not in (0x9f, )))

# Remove any unicode characters from string before transforamtion.
buf = "".join((c if ord(c) < 128 else '?' for c in buf))
Exemplo n.º 2
0
# Minus 1 col for last doesn't handle |CR Properly in populated with a character
real_width = bbs_io.pyGetTermWidth() - 1

url = 'http://bbs-scene.org/api/onelinerz.php?limit=%s' % str(real_limit)

bbs_io.pyPipe2Ansi("|CS|15 Loading Global BBS-Scene OneLiners|CR|CR")

req = requests.get(url, auth=(usrname, pssword))
if 200 != req.status_code:
    print 'error %s' % req.content
    print 'error %s' % req.status_code
    exit(1)

ansifile = "onelinerz"
bbs_io.pyAnsiPrintf(ansifile)

# can throw exceptions when xml is invalid, as a thread, nobody needs
# to catch it. theres some things that should be CDATA wrapped .. these
# break even viewing it in firefox, but upstream doesn't seem to
# notice, probably upstream does print('<xml_node>' + var +
# '</xml_node>'), i've found more than a few nasty escape flaws,
# we're breaking the shit out of encoding here, but most other bbs's
# are US-ASCII (cp437)-only, and bbs-api doesn't care

buf = ''.join((byte for byte in req.content
    if (ord(byte) >= 0x20
    or ord(byte) in (0x09, 0x0a, 0x0d, 0x7f))
    and ord(byte) not in (0x9f,)))

# Remove any unicode characters from string before transforamtion.
Exemplo n.º 3
0
def start_up():
    # Main Startup
    bbs_io.pyAnsiPrintf(ansifile)
    get_wall()
    bbs_io.pyPipe2Ansi("|CR|07Post a line to the wall? |15(|12y|04/|12n|07)|08: ")
Exemplo n.º 4
0
def main_module():

    # Clear Screen, Default color 15 = White Text, Background = |18 Dark Green
    bbs_io.pyPipe2Ansi("|CS|15|18")

    # Put Raw Line of Text, No String Parsing
    bbs_io.pyPutLine("This is just a test!, test.py in the src/scripts folder! :) ")

    # Reset Text color to 15 = White, Background |16 = Black with 2 carriage returns
    bbs_io.pyPipe2Ansi("|15|16|CR|CR")

    # Run Pause Prompt
    bbs_io.pyStartPause()

    # Put String with MCI Codes |09 = Light Blue, with |IP Ip address, |DE = Wait 1 second...  CR = Carriage Return
    bbs_io.pyPipe2Ansi("|CR|09This is a Test with MCI Codes: |07{ |15IP ADDRESS |07} |13|IP, |DE|05Wait Over!  |CR|03Did you like the test?|CR")

    #Put String with MCI Codes
    bbs_io.pyPipe2Ansi("|CR|CR|09This is a simple get HotKey Test, hit any key! |CR");

    #Get Hotkey Input into ch, will Contain All Chars, Minus Escape Sequences.. If ch = 27, then ESC Sequence, Arrow Key, etc..

    # Testing the pyGetKey Functions
    bbs_io.pyPipe2Ansi('|15Hotkey Input: |11')

    # ch = the int key code returned from key press.
    ch = bbs_io.pyGetKey()
    
    # Write out the key that was pressed first. 
    # Convery from a String with Number, to Int Number, Then to Character Value.
    print chr(int(ch))

    # Test Key Input, and Extended Esc Sequences
    # if input Ch == 27, & Extended is not blank, Then Escape
    # Other Extended Sequence capture Arrow, Home Insert, F1 keys etc..
    # Then it could be arror keys, Home, Insert etc...  
   
    myStr = "|CR|03Char (Int): |11" + ch
    bbs_io.pyPipe2Ansi(myStr)

    # Check input character.
    if ch == '27':
    	if bbs_io.pyGetKeyExtended() <> "":
            # Means we got an Arror Key, Home, Insert Etc..
            myStr = "|CR|03GetKeyExtended (ESC Sequence): |11" + bbs_io.pyGetKeyExtended()
    	    bbs_io.pyPipe2Ansi(myStr)
	    
    	else:
            # Means we got just the ESC Key
    	    bbs_io.pyPipe2Ansi("|CR|03GetKeyExtended (ESC Sequence) Empty (ESC Hit!)")
    else:
        # Normal Key/Letter Input
        bbs_io.pyPipe2Ansi("|CR|03Normal Input")

    # Reset Text color to 15 = White, Background |16 = Black with 2 carriage returns
    bbs_io.pyPipe2Ansi("|15|16|CR|CR")

    # Set Length of Input to Return to 15 chars.
    bbs_io.pyPipe2Ansi("|15Get Line Input |08(|15Hit ENTER when done.|08) |07: ")

    len = 15
    getstr = bbs_io.pyGetLine(len);

    bbs_io.pyPipe2Ansi("|03|CR|CRPrinting Line Input: |07")
    print getstr


    # Test Fancy Input, input field,  |IN Limits the input field (overide), |FB sets forground and bg colors.
    text = "|CRInput Field Testing.. : "
    
    # Set default length of input field to 10
    len = 10

    # Append input field to text string
    text = bbs_io.pyInputField(text,len);

    # Write out input field
    bbs_io.pyPipe2Ansi(text)


    # Now getline after inputfield!! :)  Fancy.
    getstr = bbs_io.pyGetLine(len);

    bbs_io.pyPipe2Ansi("|03|CR|CRPrinting Inputfield Line Input: |07")
    print getstr


    bbs_io.pyPipe2Ansi("|15|CR|CRDisplaying an ansi file, hit any key to continue|CR|CR")
    bbs_io.pyStartPause()

    # Will printf out ansi.ans in ansi folder leave off extension .ans
    ansifile = "file"
    bbs_io.pyAnsiPrintf(ansifile)

    # Run Pause Prompt
    bbs_io.pyStartPause()

    # Clear Screen,  Move down two lones, then go back to Home |xy coords . Top left of screen!
    bbs_io.pyPipe2Ansi("|CS|CR|CR|XY0101|13Testing XY top left coner of screen")

    # Print Done.
    bbs_io.pyPipe2Ansi("|CR|05done.")

    # Run Pause Prompt
    bbs_io.pyStartPause()
Exemplo n.º 5
0
def start_up():
    # Main Startup
    bbs_io.pyAnsiPrintf(ansifile)
    get_wall()
    bbs_io.pyPipe2Ansi(
        "|CR|07Post a line to the wall? |15(|12y|04/|12n|07)|08: ")
Exemplo n.º 6
0
def bootup_sequence():
    
    # Startup Message
    bbs_io.pyPipe2Ansi("|CS|07|16Starting Bootup Sequence... |DE|DE|CS")

    ansifile = "osload"
    bbs_io.pyAnsiPrintf(ansifile)

    bbs_io.pyPipe2Ansi("|CR|CR                             |15Enthral OS |07v|151.0 |07Alpha")
    bbs_io.pyPipe2Ansi("|CR|CR                           '-[                   ]-'")

    bootup_done = False

    # Loop Bootup Bar
    barLen = 20
    percent = 0
    progress = ""
    color = 3

    # Setup Bootup Percentage Bar (ESC) Will abort.
    for i in range(barLen): 

        # Listen for ESC Key, if Hit Abort Mem Test       
        while stdin in select([stdin], [], [], 0)[0]:
            ch = bbs_io.pyGetKey()
            if ch == '27':
                escsequence = bbs_io.pyGetKeyExtended()                
                if not escsequence: # we jsut just ESC no arror keys
                    # We got Escape, exit loop.
                    bootup_done = True                

                    # Display full pencentage bar
                    # Repeat string to max length after abort
                    output = format("\r\x1b[31G|%02d" % (color))
                    bbs_io.pyPipe2Ansi(output)

                    color = 11
                    progress = chr(177)
                    bbs_io.pyPipe2Ansi(repstr(progress,19))
            
                    break

        else:

            # Test if loop is done.
            if bootup_done is True:
                break


            if i < int(barLen * percent):
                progress += chr(177)

            # Format Output with color Pipe Codes.            
            output = format("\r\x1b[31G|%02d" % (color))
            bbs_io.pyPipe2Ansi(output)

            # Slide Fade the update on progress bar.
            for o in range(len(progress)):
                bbs_io.pyPipe2Ansi(progress[o])
                sleep(0.02)

            # Delay between drawing redrawing bar
            sleep(0.15)

            percent += 1

            # Alternate high/low colors.
            if color == 3:
                color = 11
            else:
                color = 3

    bbs_io.pyPipe2Ansi("|CR|CR                                   |07OS Loaded|08.")
    bbs_io.pyPipe2Ansi("|DE|DE")
    bbs_io.pyPipe2Ansi("|CS|07")
Exemplo n.º 7
0
def main_module():

    # Clear Screen, Default color 15 = White Text, Background = |18 Dark Green
    bbs_io.pyPipe2Ansi("|CS|15|18")

    # Put Raw Line of Text, No String Parsing
    bbs_io.pyPutLine(
        "This is just a test!, test.py in the src/scripts folder! :) ")

    # Reset Text color to 15 = White, Background |16 = Black with 2 carriage returns
    bbs_io.pyPipe2Ansi("|15|16|CR|CR")

    # Run Pause Prompt
    bbs_io.pyStartPause()

    # Put String with MCI Codes |09 = Light Blue, with |IP Ip address, |DE = Wait 1 second...  CR = Carriage Return
    bbs_io.pyPipe2Ansi(
        "|CR|09This is a Test with MCI Codes: |07{ |15IP ADDRESS |07} |13|IP, |DE|05Wait Over!  |CR|03Did you like the test?|CR"
    )

    #Put String with MCI Codes
    bbs_io.pyPipe2Ansi(
        "|CR|CR|09This is a simple get HotKey Test, hit any key! |CR")

    #Get Hotkey Input into ch, will Contain All Chars, Minus Escape Sequences.. If ch = 27, then ESC Sequence, Arrow Key, etc..

    # Testing the pyGetKey Functions
    bbs_io.pyPipe2Ansi('|15Hotkey Input: |11')

    # ch = the int key code returned from key press.
    ch = bbs_io.pyGetKey()

    # Write out the key that was pressed first.
    # Convery from a String with Number, to Int Number, Then to Character Value.
    print chr(int(ch))

    # Test Key Input, and Extended Esc Sequences
    # if input Ch == 27, & Extended is not blank, Then Escape
    # Other Extended Sequence capture Arrow, Home Insert, F1 keys etc..
    # Then it could be arror keys, Home, Insert etc...

    myStr = "|CR|03Char (Int): |11" + ch
    bbs_io.pyPipe2Ansi(myStr)

    # Check input character.
    if ch == '27':
        if bbs_io.pyGetKeyExtended() <> "":
            # Means we got an Arror Key, Home, Insert Etc..
            myStr = "|CR|03GetKeyExtended (ESC Sequence): |11" + bbs_io.pyGetKeyExtended(
            )
            bbs_io.pyPipe2Ansi(myStr)

        else:
            # Means we got just the ESC Key
            bbs_io.pyPipe2Ansi(
                "|CR|03GetKeyExtended (ESC Sequence) Empty (ESC Hit!)")
    else:
        # Normal Key/Letter Input
        bbs_io.pyPipe2Ansi("|CR|03Normal Input")

    # Reset Text color to 15 = White, Background |16 = Black with 2 carriage returns
    bbs_io.pyPipe2Ansi("|15|16|CR|CR")

    # Set Length of Input to Return to 15 chars.
    bbs_io.pyPipe2Ansi(
        "|15Get Line Input |08(|15Hit ENTER when done.|08) |07: ")

    len = 15
    getstr = bbs_io.pyGetLine(len)

    bbs_io.pyPipe2Ansi("|03|CR|CRPrinting Line Input: |07")
    print getstr

    # Test Fancy Input, input field,  |IN Limits the input field (overide), |FB sets forground and bg colors.
    text = "|CRInput Field Testing.. : "

    # Set default length of input field to 10
    len = 10

    # Append input field to text string
    text = bbs_io.pyInputField(text, len)

    # Write out input field
    bbs_io.pyPipe2Ansi(text)

    # Now getline after inputfield!! :)  Fancy.
    getstr = bbs_io.pyGetLine(len)

    bbs_io.pyPipe2Ansi("|03|CR|CRPrinting Inputfield Line Input: |07")
    print getstr

    bbs_io.pyPipe2Ansi(
        "|15|CR|CRDisplaying an ansi file, hit any key to continue|CR|CR")
    bbs_io.pyStartPause()

    # Will printf out ansi.ans in ansi folder leave off extension .ans
    ansifile = "file"
    bbs_io.pyAnsiPrintf(ansifile)

    # Run Pause Prompt
    bbs_io.pyStartPause()

    # Clear Screen,  Move down two lones, then go back to Home |xy coords . Top left of screen!
    bbs_io.pyPipe2Ansi(
        "|CS|CR|CR|XY0101|13Testing XY top left coner of screen")

    # Print Done.
    bbs_io.pyPipe2Ansi("|CR|05done.")

    # Run Pause Prompt
    bbs_io.pyStartPause()
Exemplo n.º 8
0
def play():
    import time
    from random import randint
    import os

    field = []
    global charcache
    charcache = ""
    field_width = 10
    field_height = 20
    # Access scheme looks like this:
    #   layout[p][r][ypox][xpos]
    # layoutcolor = [ 7,2,3,4,4,6,7 ]
    layout = [
        #  ##
        #  ##
        [[[1, 1], [1, 1]]],
        #  #
        #  #
        #  #
        #  #
        [
            [[0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]],
            [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]],
        ],
        #  ###
        #   #
        [
            [[0, 0, 0], [1, 1, 1], [0, 1, 0]],
            [[0, 1, 0], [0, 1, 1], [0, 1, 0]],
            [[0, 1, 0], [1, 1, 1], [0, 0, 0]],
            [[0, 1, 0], [1, 1, 0], [0, 1, 0]],
        ],
        #  #
        #  #
        #  ##
        [
            [[0, 1, 0], [0, 1, 0], [0, 1, 1]],
            [[0, 0, 1], [1, 1, 1], [0, 0, 0]],
            [[1, 1, 0], [0, 1, 0], [0, 1, 0]],
            [[0, 0, 0], [1, 1, 1], [1, 0, 0]],
        ],
        #   #
        #   #
        #  ##
        [
            [[0, 1, 0], [0, 1, 0], [1, 1, 0]],
            [[0, 0, 0], [1, 1, 1], [0, 0, 1]],
            [[0, 1, 1], [0, 1, 0], [0, 1, 0]],
            [[1, 0, 0], [1, 1, 1], [0, 0, 0]],
        ],
        #  ##
        #   ##
        [[[0, 1, 0], [1, 1, 0], [1, 0, 0]], [[0, 0, 0], [1, 1, 0], [0, 1, 1]]],
        #   ##
        #  ##
        [[[0, 1, 0], [0, 1, 1], [0, 0, 1]], [[0, 0, 0], [0, 1, 1], [1, 1, 0]]],
    ]

    fieldx1 = 32
    fieldy1 = 10
    scorex1 = 11
    scorey1 = 11

    class RectRedraw:
        x1 = None
        y1 = None
        x2 = None
        y2 = None

        def max(r, val, valmax):
            if val > valmax:
                return valmax
            return val

        def min(r, val, valmin):
            if val < valmin:
                return valmin
            return val

        def merge(r, x1, y1, x2, y2):
            if r.x1 is None or r.x1 > x1:
                r.x1 = r.min(x1, 0)
            if r.y1 is None or r.y1 > y1:
                r.y1 = r.min(y1, 0)
            if r.x2 is None or r.x2 < x2:
                r.x2 = r.max(x2, field_width)
            if r.y2 is None or r.y2 < y2:
                r.y2 = r.max(y2, field_height)
            # print r.x1,r.y1,r.x2,r.y2

        def clean(r):
            r.x1 = None
            r.y1 = None
            r.x2 = None
            r.y2 = None

    rr = RectRedraw()
    for _ in range(field_height):
        field.append([0] * field_width)

    def echo(s):
        global charcache
        charcache += s

    # Turn off the Cursor
    bbs_io.pyPipe2Ansi("\x1b[?25l")

    # Display Welcome Message
    bbs_io.pyPipe2Ansi("|CS|CR|CR|09REAdY YOUR tERMiNAl! |CR|CR|03PRESS ANY kEY")

    # get key from user, wait for input.
    bbs_io.pyGetKey()

    # Clear the Screen First
    bbs_io.pyPipe2Ansi("|CS")

    # Display ANSI screen .ans extension is assumed.
    bbs_io.pyAnsiPrintf("tetris")

    def gotoxy(x, y):
        echo("|XY%02d%02d" % (x + 1, y + 1))

    def plotblock(color, lastcolor):
        if color:
            # c = u'\u2588\u2588'  # '\xDB\xDB'
            c = chr(219) + chr(219)
        else:  # both empty
            c = "  "
            color = 0
        # Output optimization
        if color % 8 == 0:
            color = color / 8
        if color == lastcolor:
            echo(c)
        else:
            if color:
                fg = str(30 + color % 8)
            else:
                fg = "37"
            if color >= 8:
                bg = ";%d" % (40 + color / 8)
            else:
                bg = ""
            echo("\x1b[0;" + fg + bg + "m")
            echo(c)
            lastcolor = color
        return lastcolor

    def drawfield():
        lastcolor = ""
        for y in range(0, field_height, 2):
            gotoxy(fieldx1 + 2, fieldy1 + 1 + y / 2)
            # Which block to show, full, half-up, half-down or empty.
            for x in range(field_width):
                color = field[y][x] + field[y + 1][x] * 8
                if field[y][x] and field[y + 1][x]:
                    # c = u'\u2588'  # '\xDB'
                    c = chr(219)
                    if field[y][x] == field[y + 1][x]:
                        color = color % 8
                    else:
                        # c = u'\u2580'  # '\xDF'
                        c = chr(223)
                elif field[y][x] and not field[y + 1][x]:
                    # c = u'\u2580'  # '\xDF'
                    c = chr(223)
                elif not field[y][x] and field[y + 1][x]:
                    # c = u'\u2584'  # '\xDC'
                    c = chr(220)
                else:  # both empty
                    c = " "
                # Output optimization
                if color % 8 == 0:
                    color = color / 8
                if color == lastcolor:
                    echo(c)
                else:
                    if color:
                        fg = str(30 + color % 8)
                    else:
                        fg = "37"
                    if color >= 8:
                        bg = ";%d" % (40 + color / 8)
                    else:
                        bg = ""
                    echo("\x1b[0;" + fg + bg + "m")
                    echo(c)
                    lastcolor = color
        # echo(term.normal)
        echo("|07|16")  # reset background color

    layoutcolor = [7, 2, 7, 6, 3, 6, 3]
    # p    = -1  # Current piece type
    nextpiece = randint(0, len(layout) - 1)
    p = randint(0, len(layout) - 1)
    p = 1
    r = 0  # Current rotation
    xpos = 4  # X position
    # ypos = -2  # Y position
    ypos = -len(layout[p][0])
    level = 1
    score = 0
    lines = 0

    def flush():
        global charcache
        bbs_io.pyPipe2Ansi(charcache)
        charcache = ""

    def fillpiece(x, y, p, r, value):
        row = 0
        for line in layout[p][r]:
            col = 0
            for c in line:
                if c and (y + row) >= 0:
                    field[y + row][x + col] = value
                col += 1
            row += 1

    def showpiece(x, y, p, r):
        fillpiece(x, y, p, r, layoutcolor[p])

    def hidepiece():
        fillpiece(xpos, ypos, p, r, 0)

    def testpiece(x, y, newr):
        hidepiece()
        # Space at the new location?
        row = 0
        for line in layout[p][newr]:
            col = 0
            for c in line:
                try:
                    if c:
                        if (y + row) >= 0 and field[y + row][x + col] or (x + col) < 0 or (x + col) > 9:
                            return 0
                except IndexError:
                    return 0
                col += 1
            row += 1
        # Movement possible
        return 1

    def movepiece(x, y, newr):
        if testpiece(x, y, newr):
            # Build redraw rectangle
            rr.merge(xpos, ypos, xpos + len(layout[p][0][0]), ypos + len(layout[p][0]))
            rr.merge(x, y, x + len(layout[p][0][0]), y + len(layout[p][0]))
            showpiece(x, y, p, newr)
            return (x, y, newr, 1)
        else:
            showpiece(xpos, ypos, p, r)
            return (xpos, ypos, r, 0)

    def shownext(p):
        r = 0
        for y in range(4):
            gotoxy(26, 18 + y)
            echo(" " * 4)

        bbs_io.pyPipe2Ansi("|%02d" % (layoutcolor[p]))

        yoffset = int(len(layout[p][r][0]) < 4)
        xoffset = int(len(layout[p][r]) < 3)
        for y in range(len(layout[p][r])):
            for x in range(len(layout[p][r][y])):
                val = layout[p][r][y][x]
                if val:
                    gotoxy(26 + x + xoffset, 18 + y + yoffset)
                    # echo(u'\u2588\u2588')
                    echo(chr(219) + chr(219))

    def drawstats():
        bbs_io.pyPipe2Ansi("|XY%02d%02d%d" % (scorex1, scorey1 + 1, level))
        bbs_io.pyPipe2Ansi("|XY%02d%02d%d" % (scorex1, scorey1 + 3, lines))
        bbs_io.pyPipe2Ansi("|XY%02d%02d%d" % (scorex1, scorey1 + 4, score))

    drawstats()
    ticksize = 0.4
    nexttick = time.time() + ticksize
    showpiece(xpos, ypos, p, r)
    gotoxy(26, 17)
    # echo(term.blue_reverse('next'))
    echo("|09|17n|00|17ext|07|16")
    shownext(nextpiece)

    # Full redraw first frame
    rr.merge(0, 0, field_width, field_height)

    buf = ""
    key = ""
    while True:
        drawfield()
        slice = nexttick - time.time()
        if slice < 0:
            slice = 0
        echo(buf)
        buf = ""
        flush()

        # Get User Key presses for block movement {Non-Blocking)
        if stdin in select([stdin], [], [], slice + 0.01)[0]:
            key = bbs_io.pyGetKey()
            if key != "":
                # if we got an escape sequence, then reassign the key
                if key == "27":
                    # Get Extended ESC Sequence
                    key = bbs_io.pyGetKeyExtended()
                else:
                    # Translate int to char value.
                    key = chr(int(key))
        else:
            key = ""

        now = time.time()
        # hidepiece()
        if key is not None:
            if key in ("q", "Q"):
                return (0, 0, 0)
            elif key in ("[D", "h"):
                xpos, ypos, r, m = movepiece(xpos - 1, ypos, r)
            elif key in ("[C", "l"):
                xpos, ypos, r, m = movepiece(xpos + 1, ypos, r)
            elif key in ("[A", "k"):
                xpos, ypos, r, m = movepiece(xpos, ypos, (r + 1) % len(layout[p]))
            elif key in ("[B", "j"):
                xpos, ypos, r, m = movepiece(xpos, ypos + 1, r)
            elif key in (" ",):
                m = True
                c = 0
                while m:
                    xpos, ypos, r, m = movepiece(xpos, ypos + 1, r)
                    if m:
                        c += 1
                if c:
                    nexttick = time.time() + ticksize

        # New tick?
        if now > nexttick:
            nexttick += ticksize
            # Move down piece
            xpos, ypos, r, moved = movepiece(xpos, ypos + 1, r)
            # Piece has touched down?
            if not moved:
                # Is the player dead?
                if ypos <= -len(layout[p][0]):

                    # End of Game Message
                    bbs_io.pyPipe2Ansi("|XY3324|12!! |04gAME OVeR |12!!|07")
                    bbs_io.pyGetKey()

                    #                    death_win = AnsiWindow(height=6, width=40,
                    #                                           yloc=fieldy1 + 10 / 2, xloc=fieldx1 - 11)
                    #                    death_win.colors['border'] = term.bold_black
                    #                    echo_unbuffered(death_win.clear() + death_win.border())
                    #                    echo_unbuffered(
                    #                        term.move(fieldy1 + 10 / 2 + 1, fieldx1 - 11))
                    #                    echo_unbuffered((
                    #                                    u'!! gAME OVeR!! Score was: %i' % (score,)).center(40))
                    #                    echo_unbuffered(
                    #                        term.move(fieldy1 + 10 / 2 + 3, fieldx1 - 11))
                    #                    echo_unbuffered(u'press RETURN'.center(40))
                    #                    while True:
                    #                        inp = getch()
                    #                        if inp in (u'\r', term.KEY_ENTER):
                    #                            break
                    return (score, level, lines)

                # Any complete rows to remove?
                complete = []
                for y in range(field_height):
                    x = 0
                    while x < field_width:
                        if field[y][x] == 0:
                            break
                        x += 1
                    if x == field_width:
                        complete.append(y)
                if len(complete) > 0:
                    # Add score
                    lines += len(complete)
                    score += len(complete) * len(complete) * 100
                    # Shrink field
                    for line in complete:
                        del field[line]
                        field.insert(0, [0] * field_width)

                    if lines >= level * 10:
                        level += 1
                        ticksize = 0.4 - level * 0.02
                    drawstats()

                    # Redraw complete field
                    rr.merge(0, 0, field_width, field_height)

                # Time for a new piece
                p = nextpiece
                nextpiece = randint(0, len(layout) - 1)
                r = 0
                xpos = 4
                ypos = -len(layout[p][0])
                showpiece(xpos, ypos, p, r)
                shownext(nextpiece)