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


Python Timer.run方法代码示例

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


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

示例1: __init__

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import run [as 别名]
class Game:
    def __init__(self, REALWIDTH, REALHEIGHT, GAMEWIDTH, GAMEHEIGHT):
        """
        peaklass
        """
        global levelTime

        pygame.init()

        self.width = GAMEWIDTH
        self.height = GAMEHEIGHT
        self.realwidth = REALWIDTH
        self.realheight = REALHEIGHT
        self.screen = pygame.display.set_mode((self.realwidth,self.realheight))
        pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0)) # tavaline hiir n'htamatuks
        self.welcomeScreen = pygame.image.load('Pics/gameAvaekraan4.png').convert()
        self.statboard = pygame.image.load("Pics/statboard3.png").convert()
        self.pauseScreen = pygame.image.load('Pics/paused.png').convert_alpha()
        self.speedpot = pygame.image.load("Pics/speedpot.png").convert_alpha()
        self.hppot2 = pygame.image.load("Pics/2HPpot.png").convert_alpha()
        self.hppot5 = pygame.image.load("Pics/5HPpot.png").convert_alpha()
        self.background = pygame.transform.scale((pygame.image.load("Pics/spacev3.png").convert()), (1024,768))
        self.MachineGun = pygame.transform.scale((pygame.image.load("Pics/machinegun.png").convert_alpha()), (60,40))
        self.ShotGun = pygame.transform.scale((pygame.image.load("Pics/shotgun.png").convert_alpha()), (60,40))
        self.HandGun = pygame.transform.scale((pygame.image.load("Pics/handgun2.png").convert_alpha()), (50,50))
        self.bg_imgRect = self.background.get_rect()
        pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
        pygame.mixer.music.load('Sounds/track1_track2.mp3') # <--------------------------------------------------------- SIIN TAUSTAMUSS
        pygame.mixer.music.play(-1)  # maitu korda m'ngib
        self.music_playing = 1
        self.play_sounds = 1
        """
        kiirus - bloki kiirusW
        maxw - maksimaalne laius
        maxh - maksimaaline pikkus
        lykkab - mitu pixlit lykkab eemale kokkuporkel
        dmg - mitu dmg teeb lykkamisega
        """

        self.blokityyp = {
            "tavaline" : {
                "maxKiirus" : 0.2, # bloki maksimaalne kiirus
                "lykkab" : 0, # lykkamistugevus
                "dmg" : 0, # dmg kokkuporkel
                "img" : "Pics/tavalineblokkBlurred.png"
            },
            "lykkaja" : {
                "maxKiirus" : 0.5,
                "lykkab" : 200,
                "dmg" : 2,
                "img" : "Pics/lykkajablokkBlurred.png"
            }


        }
        self.enemytype = {
            "tavaline" : {
                "elusi" : 1,
                "img" : "Pics/tavalinevastane30x30.png",
                "speed" : 0.1,
                "dmg" : 1
            },
            "tulistaja" : {
                "elusi" : 2,
                "img" : "Pics/tulistajavastane40x40_2.png",
                "speed" : 0.05,
                "dmg" : 2,
                "weapon" : 1,
                "delay" : 1
            },
            "boss" : {
                "boss" : 1,
                "elusi" : 10,
                "img" : "Pics/boss.png",
                "speed" : 0.1,
                "dmg" : 1000,
                "weapon" : 1,
                "delay" : 1
            }
        }

        self.blokid = []
        self.pahad = []
        self.laserid = []
        self.lained = []

        pygame.font.get_fonts()
        self.font=pygame.font.SysFont('bauhaus93',35)


        self.level = 1

        self.levelTime = levelTime
        self.levelTimer = Timer(self.levelTime)

        self.run = True

        self.mouseHolding = False

        self.gaming = False
#.........这里部分代码省略.........
开发者ID:Kaspar94,项目名称:SpaceKappaShooter,代码行数:103,代码来源:main.py

示例2: print

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import run [as 别名]
    print(message.format(*args, now=now))

def one(timer):
    format_time("{now}: Called One")

def two(timer):
    format_time("{now}: Called Two")

def three(timer):
    format_time("{now}: Called Three")

class Repeater:
    def __init__(self):
        self.count = 0
    def repeater(self, timer):
        format_time("{now}: repeat {0}", self.count)
        self.count += 1
        timer.call_after(5, self.repeater)

timer = Timer()
timer.call_after(1, one)
timer.call_after(2, one)
timer.call_after(2, two)
timer.call_after(4, two)
timer.call_after(3, three)
timer.call_after(6, three)
repeater = Repeater()
timer.call_after(5, repeater.repeater)
format_time("{now}: Starting")
timer.run()
开发者ID:Dennitizer,项目名称:Python_Master-the-Art-of-Design-Patterns,代码行数:32,代码来源:1261_07_26_timer_test.py

示例3: Mees

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import run [as 别名]
class Mees(object): # peamees
    global SCREEN_WIDTH, SCREEN_HEIGHT  # ekraani laius ja pikkus
    def __init__(self):

        #pygame.mixer.init(frequency=22050, size=-16, channels=4)
        self.saund = pygame.mixer.Sound("Sounds/singleshot.wav")
        self.saund.set_volume(0.2)
        self.chan = pygame.mixer.find_channel()

        self.saund2 = pygame.mixer.Sound("Sounds/teleport2.wav")
        self.saund2.set_volume(0.8)
        self.chan2 = pygame.mixer.find_channel()

        self.saund3 = pygame.mixer.Sound("Sounds/pickup.wav")
        self.saund3.set_volume(0.8)
        self.chan3 = pygame.mixer.find_channel()

        self.saund4 = pygame.mixer.Sound("Sounds/slurp.wav")
        self.saund4.set_volume(1)
        self.chan4 = pygame.mixer.find_channel()


        self.lives = 7 # mitu elu mehel
        self.rect = Rect(30,SCREEN_HEIGHT-100,10,10) # ta kast
        self.image = pygame.transform.scale((pygame.image.load("Pics/Kappa.png").convert_alpha()), (30,30))
        self.imageDisco = pygame.transform.scale((pygame.image.load("Pics/discokappa.png").convert_alpha()), (30,30))
        self.image2 = pygame.image.load('Pics/Untitled.png').convert_alpha()
        self.image2Rect = self.image2.get_rect()
        self.newRect = self.image.get_rect()
        self.rect.w = self.newRect[2]
        self.rect.h = self.newRect[3]
        self.speed = 0.8 # kiirus

        self.bullets = [] # valjalastud kuulid

        self.bulletCount = 20 # kuulide arv
        
        self.font=pygame.font.Font(None,30)

        #voimalikud relvad
        self.relvad = {
            "handgun" :
                { "dmg" : 1, # palju relv dmg teeb
                  "speed" : 2, # kui kiirelt kuul lendabs
                  "hoida" : 0, # kas automaat
                  "bullets" : 12, # palju kuule
                  "pide" : 12, # palju pide hoiab
                  "kokku" : -1 # palju kokku kuule
                },
            "machinegun" :
                { "dmg" : 1,
                  "speed" : 4,
                  "hoida" : 1,
                  "bullets" : 50,
                  "pide" : 50,
                  "kokku" : 300,
                  "vahe" : 0.2 # kuulide laskmis vahe ajaliselt automaatselt
                },
            "pump" :
                { "dmg" : 1,
                  "speed" : 2,
                  "hoida" : 0,
                  "bullets" : 8,
                  "pide" : 8,
                  "kokku" : 72,
               }
        }
        self.potid = {
            0 :
                {
                    "heals" : 2,
                     #"img" : "Pics/2HPpot.png"
                },
            1 :
                {
                    "heals" : 5
                    #"img" : "Pics/5HPpot.png"
                },
            2 :
                {
                    "speed" : 1,
                    "time" : 20
                }
        }

        self.relv = "handgun" # mis relv hetkel

        self.relvakogu = ["handgun","machinegun"]
        self.potikogu = []

        self.shootTimer = Timer(1)
        self.speedTimer = Timer(0)
        self.shootTimer.run()
        self.koos = []
        self.saiJuurde = 0
        self.dead = 0
        self.ulti = 5
    def update_logic(self):
        self.shootTimer.update()
        self.speedTimer.update()
#.........这里部分代码省略.........
开发者ID:Kaspar94,项目名称:SpaceKappaShooter,代码行数:103,代码来源:mees.py

示例4: PyTetrisModel

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import run [as 别名]
class PyTetrisModel(object):

    blockList = {"I": Block([[1, 1, 1, 1]]),

                 "J": Block([[1, 0, 0],
                             [1, 1, 1]]),

                 "L": Block([[0, 0, 1],
                             [1, 1, 1]]),

                 "O": Block([[1, 1],
                             [1, 1]]),

                 "S": Block([[0, 1, 1],
                             [1, 1, 0]]),

                 "T": Block([[0, 1, 0],
                             [1, 1, 1]]),

                 "Z": Block([[1, 1, 0],
                             [0, 1, 1]])}

    blockColorList = [(0, 0, 0),
                      (194, 54, 33),
                      (37, 188, 36),
                      (173, 173, 39),
                      (73, 46, 255),
                      (211, 56, 211),
                      (51, 187, 200),
                      (203, 204, 205)]

    def __init__(self):
        self._state = "initialized"

        self._difficulty = 'crazy'

        # map 以左上角为原点,从左往右是 x 正方向,从上往下是 y 正方向。
        #
        #   (0, 0)  (1, 0)  (2, 0)  ...     (9, 0)
        #   (0, 1)  (1, 1)  (2, 1)  ...     (9, 1)
        #   ...     ...     ...     ...     ...
        #   (0, 19) (1, 19) (2, 19) ...     (9, 19)
        #
        self.map = Block([[None]*10 for i in range(20)])

        self.timer = None

        self.next_block = Block([[]])
        self.active_block = Block([[]])
        self.active_block_position = (0, 0)

        self.gameover_callback = None

        # 在按左右方向键时,可能会和正在对自身进行访问的 tick 函数造成的冲突。
        # 所以这儿准备一个 Lock 。
        self.lock = Lock()

        self.score = 0

    @property
    def difficulty(self):
        return self._difficulty

    @difficulty.setter
    def difficulty(self, value):
        if self.state == "initialized":
            if value in DIFFICULTY.keys():
                self.difficulty = value
            else:
                raise NoSuchDifficulty
        else:
            raise WrongState

    @property
    def state(self):
        return self._state

    @state.setter
    def state(self, value):
        stderr.write("model: set state to " + str(value) + "\n")
        self._state = value

    def start(self):
        if self.state == "initialized":
            self.state = "start"
            self.timer = Timer(target=self.tick,
                               interval=DIFFICULTY[self.difficulty]['interval'])
            self.timer.run()
        else:
            stderr.write("model: the state is not initialized, can not start the game")

    def pause(self):
        self.timer.pause()

    def resume(self):
        self.timer.resume()

    def press_arrow_key(self, direction):
        if self.state == "falling":
            with self.lock:
#.........这里部分代码省略.........
开发者ID:aheadlead,项目名称:PyTetris,代码行数:103,代码来源:model.py


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