当前位置: 首页>>代码示例>>Python>>正文


Python Term.waitforkey方法代码示例

本文整理汇总了Python中term.Term.waitforkey方法的典型用法代码示例。如果您正苦于以下问题:Python Term.waitforkey方法的具体用法?Python Term.waitforkey怎么用?Python Term.waitforkey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在term.Term的用法示例。


在下文中一共展示了Term.waitforkey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Zedventure

# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import waitforkey [as 别名]
class Zedventure (object):
    __slots__ = ('time','area','hero','actors','term','rng')
    def __init__(self,args):
        # init the game
        self.time = 0
        self.area = None
        self.term = None
        self.hero = None
        self.actors = []
        self.rng = random.Random()

    def __call__(self,screen):
        """Z(screen) -> None"""
        # init the interface
        self.area = area.Area(self)
        self.term = Term(self,screen)
        (y, x) = self.term.viewsize()  # wtf? why can't curses
        self.area.resize(y, x-1)       # draw on the screen edge?
        self.hero = Hero(self.area,1,1,None)
        self.actors = [self.hero]
        self.actors.extend(self.area.generate(0))
        self.area.enter(self.hero.y, self.hero.x, self.hero)
        self.term.redraw()
        # start the game
        running = True
        while running:
            actor = self.actors[0]
            try:
                while actor.wait_until <= self.time:
                    actor.act()
            except QuitGame:
                self.term.msg('Goodbye, thanks for playing!')
                self.term.waitforkey()
                running = False
            except Escaped:
                self.term.msg('You escaped with %d gold!' % self.hero.gold)
                self.term.waitforkey()
                running = False
            except WasKilled:
                self.term.msg('You died.')
                self.term.waitforkey()
                running = False
            finally:
                self.time += 1
            self.queue_actor(actor)

    def new_level(self,increment):
        self.actors = self.area.generate(increment)
        self.actors.insert(0,self.hero)
        self.area.occ[self.hero.y,self.hero.x] = self.hero

    def prev_level(self):
        self.new_level(-1)

    def next_level(self):
        self.new_level(1)

    def queue_actor(self,actor):
        done = False
        for i,a in enumerate(self.actors):
            if a > actor:
                self.actors.remove(actor)
                self.actors.insert(i, actor)
                done = True
                break
        if not done:
            self.actors.remove(actor)
            self.actors.append(actor)

    def coinflip(self):
        return bool(self.rng.randint(0,1))

    def chance_in(self,odds):
        return self.rng.randint(1,odds) == 1

    def percent_chance(self,pct):
        return self.rng.randint(1,100) <= pct
开发者ID:codelurker,项目名称:zedventure,代码行数:79,代码来源:game.py

示例2: Zedventure

# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import waitforkey [as 别名]
class Zedventure(object):
    __slots__ = ("time", "area", "hero", "actors", "term", "rng", "game_over")

    def __init__(self, args):
        # init the game
        self.time = 0
        self.area = None
        self.term = None
        self.hero = None
        self.game_over = None
        self.actors = []
        self.rng = random.Random()

    def __call__(self, screen):
        """Z(screen) -> None"""
        # init the interface
        self.area = area.Area(self)
        self.term = Term(self, screen)
        (y, x) = self.term.viewsize()  # wtf? why can't curses
        self.area.resize(y, x - 1)  # draw on the screen edge?
        self.hero = Hero(self.area, 1, 1, None)
        self.actors = [self.hero]
        self.actors.extend(self.area.generate(0))
        self.area.enter(self.hero.y, self.hero.x, self.hero)
        self.term.redraw()
        # start the game
        running = True
        while running:
            actor = self.actors[0]
            while running and actor.wait_until <= self.time:
                actor.act()
                if self.game_over == "quit":
                    self.term.msg("Goodbye, thanks for playing!")
                    self.term.waitforkey()
                    running = False
                elif self.game_over == "escaped":
                    self.term.msg("You escaped with %d gold!" % self.hero.gold)
                    self.term.waitforkey()
                    running = False
                elif self.game_over == "killed":
                    self.term.msg("You died.")
                    self.term.waitforkey()
                    running = False
            self.time += 1
            self.queue_actor(actor)

    def new_level(self, increment):
        self.actors = self.area.generate(increment)
        self.actors.insert(0, self.hero)
        self.area.occ[self.hero.y, self.hero.x] = self.hero

    def prev_level(self):
        if self.area.depth < 1:
            self.game_over = "escaped"
        else:
            self.new_level(-1)

    def next_level(self):
        self.new_level(1)

    def queue_actor(self, actor):
        done = False
        for i, a in enumerate(self.actors):
            if a > actor:
                self.actors.remove(actor)
                self.actors.insert(i, actor)
                done = True
                break
        if not done:
            self.actors.remove(actor)
            self.actors.append(actor)

    def coinflip(self):
        return bool(self.rng.randint(0, 1))

    def chance_in(self, odds):
        return self.rng.randint(1, odds) == 1

    def percent_chance(self, pct):
        return self.rng.randint(1, 100) <= pct
开发者ID:zenhob,项目名称:zedventure,代码行数:82,代码来源:game.py


注:本文中的term.Term.waitforkey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。