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


Python Level.won方法代码示例

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


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

示例1: __init__

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import won [as 别名]
class LevelController:
    """ Controller class for the level """
    
    def __init__(self):
        """ Initialize the Level Controller """
        self.level = Level(4)
        self.minefield_view = MinefieldView(self.level.minefield, self.level.drone)
        
        self.actions = {KAO_UP:self.level.drone.up,
                        KAO_DOWN:self.level.drone.down,
                        KAO_LEFT:self.level.drone.left,
                        KAO_RIGHT:self.level.drone.right,
                        ord('s'):self.level.drone.scan,
                        ord('d'):self.level.drone.defuse,
                        ESCAPE:self.stopRunning}
        
    def run(self):
        """ Run the controller """
        self.running = True
        self.loop()
        
    def loop(self):
        """ Run the controller main loop """
        while self.running:
            print self.minefield_view
            self.processInput()
            self.checkGameOver()
            
    def processInput(self):
        """ Process the input """
        kao_char = getch()
        if kao_char in self.actions:
            self.actions[kao_char]()
            
    def stopRunning(self):
        """ Stop the Controller from running """
        self.running = False
            
    def checkGameOver(self):
        """ Check if the Game is Over """
        if self.level.lost():
            self.stopRunning()
            if self.level.destroyed():
                print "Destroyed!"
            elif self.level.noPower():
                print "No Power!"
            print "Game Over\r"
        elif self.level.won():
            self.stopRunning()
            print "Congratulations! You won!"
开发者ID:cloew,项目名称:PyMine,代码行数:52,代码来源:level_controller.py


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