示例#1
0
def main():
    if len(sys.argv) != 2:
        prog_name = sys.argv[0]
        if sys.argv[0].endswith('__main__.py'):
            prog_name = '-m xyppy'
        print('usage examples:')
        print('    python ' + prog_name + ' STORY_FILE.z5')
        print('    python ' + prog_name + ' http://example.com/STORY_FILE.z5')
        sys.exit()

    url = sys.argv[1]
    if any(map(url.startswith, ['http://', 'https://', 'ftp://'])):
        f = urllib2.urlopen(url)
        mem = f.read()
        f.close()
    else:
        with open(url, 'rb') as f:
            mem = f.read()
    if blorb.is_blorb(mem):
        mem = blorb.get_code(mem)
    env = Env(mem)

    if env.hdr.version not in [3, 4, 5, 7, 8]:
        err('unsupported z-machine version: ' + str(env.hdr.version))

    term.init(env)
    env.screen.first_draw()
    ops.setup_opcodes(env)
    try:
        while True:
            step(env)
    except KeyboardInterrupt:
        pass
示例#2
0
文件: tests.py 项目: jtruscott/ld27
 def setUp(self):
     if self.force_backend:
         term.init(backends=[self.force_backend], width=self.width, height=self.height)
     else:
         term.init(width=self.width, height=self.height)
     term.clear()
     term.set_title(self._testMethodName)
示例#3
0
文件: tests.py 项目: jtruscott/ld27
 def setUp(self):
     if self.force_backend:
         term.init(backends=[self.force_backend],
                   width=self.width,
                   height=self.height)
     else:
         term.init(width=self.width, height=self.height)
     term.clear()
     term.set_title(self._testMethodName)
示例#4
0
def main():
    log.debug('Starting up')
    term.init()
    term.settitle('Mutants Of Melimnor    (PyWeek #13: Mutate!)')
    try:
        event.fire('setup')
        game.start()

    except game.GameShutdown:
        term.reset()
    except KeyboardInterrupt:
        term.reset()
        raise
    except Exception, e:
        log.exception(e)
        raise
示例#5
0
# from curses import wrapper
#
# # @wrapper
# def main(stdscr):
#     stdscr.clear()
#     code = "print 'Hello, world'"
#     stdscr.addstr(0, 0, code)
#     stdscr.refresh()
#
#     # term.getKey()
#
# wrapper(main)

from curses import wrapper

def main(stdscr):
    # Clear screen
    stdscr.clear()

    # This raises ZeroDivisionError when i == 10.
    for i in range(0, 11):
        v = i-10
        stdscr.addstr(i, 0, '10 divided by {} is {}'.format(v, 10/v))

    stdscr.refresh()
    stdscr.getkey()

# wrapper(main)

main(term.init())
示例#6
0
文件: myhack.py 项目: gnar/pyhack
#!/usr/bin/python
from __future__ import print_function
import ui
import game
import term
import savegame

import sys, traceback

if __name__ == "__main__":
  try:
    __builtins__.game = savegame.load()
  except:
    __builtins__.game = game.Game()

  term.init()
  try:
    ui.mainloop()
  except Exception as e:
    term.go(0, 0)
    term.deinit()
    traceback.print_tb(sys.exc_traceback)
    print("%s: %s" % (type(e), e.message))
  finally:
    term.deinit()
示例#7
0
    'arm': 'Arm',
    'ignite': 'Ignite',
    'burn': 'Burn',
    'coast': 'Coast',
    'apogee': 'Apogee',
    'wait': 'Wait',
    'eject': 'Eject',
    'fall': 'Fall',
    'recover': 'Recover'
}

inited = False

try:
    comm.init()
    term.init()

    box.init('blackbox.json')

    data = {'time': 0, 'state': 'no_comm', 'sensors': None}
    count = 0

    while True:
        try:
            cmd = sys.stdin.read(1)

            if cmd == 't':
                comm.send({'command': 'test'})
            elif cmd == 'a':
                comm.send({'command': 'arm'})
            elif cmd == 'd':