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


Python Field.destroy方法代码示例

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


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

示例1: Saver

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import destroy [as 别名]
class Saver():
    def __init__(self, balls=int(random.random() * 100), trail=" "):
        self.field = Field(title="Term Saver")
        self.balls = [Ball(x=int(random.random() * self.field.x-1)+1, y=int(random.random() * self.field.y-1)+1) for x in range(balls)]
        self.speed = 0.009
        self.trail = trail
        return

    def update(self):
        for ball in self.balls:
            hitWall = self.walled(ball)

            if hitWall: # wall collision
                ball.bounce(hitWall)

            # ball collision

            self.clearTrail(ball, self.trail, True)
            ball.move()

            self.field.write_at(item=ball.image, coords=ball.getPosition())

        # clear the field randomly (.1% chance)
        if random.choice(range(1000)) == 1:
            self.field.clear()
        self.field.deploy()
        return

    def walled(self, ball):
        direction = []
        if ball.x < 1:
            direction.append('right')
        elif ball.x >= self.field.x-1:
            direction.append('left')

        if ball.y < 1:
            direction.append('down')
        elif ball.y >= self.field.y-1:
            direction.append('up')

        if len(direction):
            return ' '.join(direction)
        return None

    def run(self):
        run = 1
        while run:
            c = self.field.display.getch()
            if c == ord('q'):
                run = 0
            self.update()
            time.sleep(self.speed)
        self.field.destroy()
        return

    def clearTrail(self, obj, remains=" ", centered=False):
        for i in range(len(obj.image)):
            self.field.write_at(item=remains, coords=[obj.x+i, obj.y], centered=centered)
        return
开发者ID:cameronbriar,项目名称:curses,代码行数:61,代码来源:saver.py

示例2: Rain

# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import destroy [as 别名]
class Rain():
    def __init__(self, drops=int(random.random() * 100), trail=" "):
        self.field = Field(title="Zen Rain")
        self.drops = [Drop(x=int(random.random() * self.field.x-1)+1, y=int(random.random() * self.field.y-1)+1) for x in range(drops)]
        self.speed = 0.009
        self.trail = trail
        self.wind  = random.choice((1, -1, 0))
        return

    def new_drop(self):
        newdrop = Drop(x=int(random.random() * self.field.x-1)+1, y=int(random.random() * self.field.y-1)+1)
        newdrop.dx = self.wind
        return newdrop

    def update(self):
        for drop in self.drops:
            hitWall = self.walled(drop)

            if hitWall: # wall collision
                drop.bounce(hitWall)

                if 'more' in hitWall:
                    self.drops.pop(self.drops.index(drop))
                    self.drops.append(self.new_drop())

            self.clearTrail(drop, self.trail, True)
            drop.move()

            self.field.write_at(item=drop.image, coords=drop.getPosition(), color='blue')

        # clear the field randomly (.1% chance)
        #if random.choice(range(1000)) == 1:
        #    self.field.clearField()
        self.field.deploy()
        return

    def walled(self, drop):
        direction = []
        if drop.x < 1:
            direction.append('right')
        elif drop.x >= self.field.x-1:
            direction.append('left')

        if drop.y < 1:
            direction.append('down')
        elif drop.y >= self.field.y-1:
            direction.append('more')

        if len(direction):
            return ' '.join(direction)
        return None


    def run(self):
        run = 1
        while run:
            c = self.field.display.getch()
            if c == ord('q'):
                run = 0
            self.update()
            time.sleep(self.speed)
        self.field.destroy()
        return

    def clearTrail(self, obj, remains=" ", centered=False):
        for i in range(len(obj.image)):
            self.field.write_at(remains, (obj.x + i), obj.y, None, centered, None)
        return
开发者ID:cameronbriar,项目名称:curses,代码行数:70,代码来源:rain.py


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