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


Python Game.push_button方法代码示例

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


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

示例1: __init__

# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import push_button [as 别名]
class Bot:

    def __init__(self, config):
        self.config = config
        self.irc = Irc(config)
        self.game = Game()

    def run(self):
        last_start = time.time()

        while True:
            new_messages = self.irc.recv_messages(1024)
            
            if new_messages:
                for message in new_messages:
                    button = message['message'].lower()
                    username = message['username']

                    if not self.game.is_valid_button(button):
                        continue

                    if self.config['start_throttle']['enabled'] and button == 'start':
                        if time.time() - last_start < self.config['start_throttle']['time']:
                            continue

                    pbutton(username, button)
                    self.game.push_button(button)

                    if button == 'start':
                        last_start = time.time()
开发者ID:JamieMagee,项目名称:twitch-plays,代码行数:32,代码来源:bot.py

示例2: __init__

# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import push_button [as 别名]
class Bot:

    def __init__(self):
        self.config = config
        self.irc = Irc(config)
        self.game = Game()
        self.stats = Stats()
        if self.config['features']['gui_stats']:
            self.GUI = GUI(self)

    def run(self):
        throttle_timers = {button:0 for button in config['throttled_buttons'].keys()}

        while True:
            new_messages = self.irc.recv_messages(1024)
            
            if not new_messages:
                continue
            
            for message in new_messages: 
                button = message['message'].lower()
                username = message['username'].lower()
                
                if not self.game.is_valid_button(button):
                    continue
                
                if button in self.config['throttled_buttons']:
                    if (time.time() - throttle_timers[button] <
                            self.config['throttled_buttons'][button]):
                        continue
                    throttle_timers[button] = time.time()
                    
                if not self.game.is_political(button):
                    if (self.config['features']['play_game'] and
                            not button in self.config['misc']['blocked_buttons']):
                        self.game.push_button(button)
                
                self.stats.tally_message(username, message['message'])
            
            if self.config['features']['stats_on']:
                if self.config['features']['gui_stats']:
                    self.GUI.run()
                if self.config['features']['console_stats']:
                    pframe(self.stats)
                    
            elif self.config['features']['pbutton_on']:
                pbutton(self.stats.message_buffer)
开发者ID:xblink,项目名称:twitch-plays-stats,代码行数:49,代码来源:bot.py

示例3: __init__

# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import push_button [as 别名]
class Bot:

    def __init__(self):
        self.config = config
        self.irc = Irc(config)
        self.game = Game()

        self.message_buffer = [{'username': '', 'button': ''}] * 10


    def set_message_buffer(self, message):
        chat_height = 10
        self.message_buffer.insert(chat_height - 1, message)
        self.message_buffer.pop(0)


    def run(self):
        last_start = time.time()

        while True:
            new_messages = self.irc.recv_messages(1024)
            
            if not new_messages:
                continue

            for message in new_messages: 
                button = message['message'].lower()
                username = message['username'].lower()

                if not self.game.is_valid_button(button):
                    continue

                print button

                if self.config['start_throttle']['enabled'] and button == 'start':
                    if time.time() - last_start < self.config['start_throttle']['time']:
                        continue

                if button == 'start':
                    last_start = time.time()

                self.set_message_buffer({'username': username, 'button': button})
                pbutton(self.message_buffer)
                self.game.push_button(button)
开发者ID:Random101,项目名称:twitch-plays,代码行数:46,代码来源:bot.py

示例4: __init__

# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import push_button [as 别名]
class Bot:

    def __init__(self):
        self.config = config
        self.irc = Irc(config)
        self.game = Game()

        self.message_buffer = [{'username': '', 'button': ''}] * self.config['misc']['chat_height']


    def set_message_buffer(self, message):
        self.message_buffer.insert(self.config['misc']['chat_height'] - 1, message)
        self.message_buffer.pop(0)


    def run(self):
        throttle_timers = {button:0 for button in config['throttled_buttons'].keys()}

        while True:
            new_messages = self.irc.recv_messages(1024)
            
            if not new_messages:
                continue

            for message in new_messages: 
                button = message['message'].lower()
                username = message['username'].lower()

                if not self.game.is_valid_button(button):
                    continue

                if button in self.config['throttled_buttons']:
                    if time.time() - throttle_timers[button] < self.config['throttled_buttons'][button]:
                        continue

                    throttle_timers[button] = time.time()
         

                self.set_message_buffer({'username': username, 'button': button})
                pbutton(self.message_buffer)
                self.game.push_button(button)
开发者ID:aaronthebrilliant,项目名称:twitch-plays,代码行数:43,代码来源:bot.py

示例5: __init__

# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import push_button [as 别名]
class Bot:

	def __init__(self):
		self.config = config
		self.game = Game()
		self.message_buffer = [{'button': ''}] * self.config['misc']['chat_height']

	def set_message_buffer(self, message):
		self.message_buffer.insert(self.config['misc']['chat_height'] - 1, message)
		self.message_buffer.pop(0)

	def run(self):
		throttle_timers = {button:0 for button in config['throttled_buttons'].keys()}

		while True:
			button = choice(self.game.keymap)
			if button in self.config['throttled_buttons']:
				if time.time() - throttle_timers[button] < self.config['throttled_buttons'][button]:
					continue
				throttle_timers[button] = time.time()

			self.set_message_buffer({'username': username, 'button': button})
			pbutton(self.message_buffer)
			self.game.push_button(button)
开发者ID:fattredd,项目名称:fattredd.github.io,代码行数:26,代码来源:rngBot.py

示例6: __init__

# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import push_button [as 别名]
class Bot:

    def __init__(self):
        self.config = config
        self.irc = Irc(config)
        self.game = Game()
        self.botOn = True
        self.message_buffer = [{'username': '', 'button': ''}] * self.config['misc']['chat_height']

    def set_message_buffer(self, message):
        self.message_buffer.insert(self.config['misc']['chat_height'] - 1, message)
        self.message_buffer.pop(0)

    def run(self):
        throttle_timers = {button:0 for button in config['throttled_buttons'].keys()}

        while True:
            new_messages = self.irc.recv_messages(1024)
            
            if not new_messages:
                continue

            for message in new_messages: 
                button = message['message'].lower()
                username = message['username'].lower()

                #Turns off the bot with one of your commands
                if username == 'YOUR USERNAME GOES HERE':
                    if button == 'YOUR INPUT SHUTOFF MESSAGE HERE':
                        self.botOn = False

                #Turns on the bot with one of your commands
                if username == 'YOUR USERNAME GOES HERE':
                    if button == 'YOUR INPUT TURNON MESSAGE HERE':
                        self.botOn = True

                #Helper for writing actionable data to csv
                if button in self.game.keymap.keys():
                    actionable = 1
                else:
                    actionable = 0

                #Helper for writing is Bot Active data to csv
                if self.botOn == True:
                    chatActionsOn = 1
                else:
                    chatActionsOn = 0

                #Creates an array of data to write to csv
                chat_data_array = [username, time.time(), button, actionable , chatActionsOn]
                
                #Writes a message to the csv that tracks chat data
                with open('chat_data.csv', 'a+') as chatData:
                    writer = csv.writer(chatData)
                    writer.writerow(chat_data_array)

                #If the Bot is on, then it outputs the appropriate action.
                #If the Bot is off, continues to gen the input feed but does not execute an action
                if self.botOn == True:
                    if not self.game.is_valid_button(button):
                        continue

                    if button in self.config['throttled_buttons']:
                        if time.time() - throttle_timers[button] < self.config['throttled_buttons'][button]:
                            continue

                        throttle_timers[button] = time.time()
                    

                    self.set_message_buffer({'username': username, 'button': button})
                    pbutton(self.message_buffer) #This is a console output function. It outputs the log of inputs from chat
                    self.game.push_button(button)
                else:
                    self.set_message_buffer({'username': username, 'button': button})
                    pbutton(self.message_buffer)
                    
开发者ID:paulperrone,项目名称:twitch-IRC,代码行数:77,代码来源:bot_basic.py

示例7: __init__

# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import push_button [as 别名]

#.........这里部分代码省略.........
                self.game.democracy=True
            if self.democracy: #this is Democracy
                lastvotetime=time.time()
                self.queueStatus="Adding Votes"
                while time.time()-lastvotetime<self.botConfig['votetime']: #collect commands for votetime seconds
                    self.daQueue.updateQueue()
                    self.update_message(self.botConfig['votetime']-time.time()+lastvotetime)
                    comList,userList=self.curQueue.getCom()
                    self.lastButton=comList
                    timetaken=time.time()
                    index=0;
                    for button in comList:
                        username=userList[index]
                        index +=1
                        self.queueStatus="Adding Votes"
                        
                        self.addVote(button)
                        userLength=self.commandDisplayLength-len(button)-2
                        printusername=username
                        if len(username)>userLength:
                            printusername=username[0:userLength-3]+'...'
                        self.update_message_buffer(printusername+': '+button)
                        #pbutton(self.message_buffer)
                    if time.time()-timetaken<self.botConfig['checktime']: #don't check more frequently than once every 0.1
                        self.queueStatus="Sleeping"
                        time.sleep(self.botConfig['checktime'])
                self.queueStatus="Running Command"
                vote=self.topVote() #running the command after votetime seconds
                if vote:
                    self.lastPushed=vote
                    words=vote.split("+") #input-time check should have already made sure it's a valid command
                    for y in words:
                        try:
                            self.game.push_button(y)
                        except:
                            time.sleep(0.01) #this is just to fill this catch block. It's bad, yes.
                        time.sleep(.15)
                    self.clearVote()
                self.update_message(0)
            else: #this is Anarchy
                self.queueStatus="Pushing buttons"
                self.update_message(0)
                comList,userList=self.curQueue.getCom()
                self.lastButton=comList
                timetaken=time.time()
                index=0;
                for button in comList:
                    username=userList[index]
                    index +=1
                    words=button.split("+") #input-time check should have already made sure it's a valid command
                    
                    for y in words:
                        if y in self.config['throttled_buttons']:
                            if time.time() - throttle_timers[y] < self.config['throttled_buttons'][y]:
                                continue

                            throttle_timers[y] = time.time()
                        try: #Just in case of weird edge case
                            self.game.push_button(y)
                        except:
                            time.sleep(0.01) #this is just to fill this catch block. It's bad, yes.
                        time.sleep(.05) #Anarchy is a bit more jumpy than Democracy
                    userLength=self.commandDisplayLength-len(button)-2
                    printusername=username
                    if len(username)>userLength:
                        printusername=username[0:userLength-3]+'...'
开发者ID:cicero225,项目名称:twitch-plays,代码行数:70,代码来源:bot.py

示例8: __init__

# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import push_button [as 别名]

#.........这里部分代码省略.........
                        upgrade_price = self.game.cc.get_upgrade_price(upgrade_ind)
                        if upgrade_price > 1000000:
                            upgrade_price = float(upgrade_price) / 1000000
                            numdivs += 1
                            while upgrade_price > 1000:
                                upgrade_price = float(upgrade_price) / 1000
                                numdivs += 1
                        if numdivs == 0:
                            pricesuffix = ''
                        elif numdivs == 1:
                            pricesuffix = ' M'
                        elif numdivs == 2:
                            pricesuffix = ' B'
                        elif numdivs == 3:
                            pricesuffix = ' T'
                        elif numdivs == 4:
                            pricesuffix = ' Qa'
                        elif numdivs == 5:
                            pricesuffix = ' Qi'
                        elif numdivs == 6:
                            pricesuffix = ' Sx'
                        elif numdivs == 7:
                            pricesuffix = ' Sp'
                        elif numdivs == 8:
                            pricesuffix = ' O'
                        short_price = "%.3f%s" % (upgrade_price, pricesuffix)
                        self.irc.say('UPGRADE' + str(upgrade_ind+1) + ': ' + upgrade_name + ' (' + short_price + ')')
                elif button == '!commands':
                    self.irc.say('Clickclick..., Golden, Reindeer, Dungeon, Up, Down, Left, Right, Stay, Upgrade1 - Upgrade5, Info UpgradeX, NoPledge, Santa, Cursor, Grandma, Farm, Factory, Mine, Shipment, Lab, Portal, Time, Antimatter, Prism, View, Scrolldown, Scrollup, Expand, Collapse, Reset, Continue')
                elif self.game.is_valid_button(button):
                    if button == 'pop' and config['pop_bar']['enable']:
                        pop_counter += 1
                        if pop_counter >= pop_counter_max:
                            pop_counter = 0
                            self.game.push_button('unwrinkle')
                        set_pop_bar(pop_counter)
                    elif button == 'reset' or button == 'continue': 
                        if button == 'reset':
                            reset_counter += 5
                            if reset_counter >= reset_counter_max:
                                reset_counter = 0
                                self.game.push_button('reset')
                                pledge_counter = 0
                                set_pledge_bar(pledge_counter)
                        else:
                            reset_counter -= 5
                            if reset_counter < 0:
                                reset_counter = 0
                        suffix = '({0}/{1})'.format(reset_counter,reset_counter_max)
                    elif button[:7] == 'upgrade':
                        reset_counter -= 1
                        if reset_counter < 0:
                            reset_counter = 0
                        if len(button) == 7:
                            upgrade_ind = 0
                        else:
                            upgrade_ind = int(button[7])-1
                        name = self.game.cc.get_upgrade_name(upgrade_ind)
                        if config['pledge_bar']['enable'] and (name == 'Elder Pledge' or name == 'Elder Covenant' or name == 'Revoke Elder Covenant'):
                          # Throttle pledges if necessary
                          pledge_counter += 1
                          if pledge_counter >= pledge_counter_max:
                            self.game.push_button(button)
                            pledge_counter = 0
                          set_pledge_bar(pledge_counter)
                          button = 'pledge/cov'
                          suffix = '({0}/{1})'.format(pledge_counter,pledge_counter_max)
                        else:
                          self.game.push_button(button)
                    elif button == 'nopledge':
                        reset_counter -= 1
                        if reset_counter < 0:
                            reset_counter = 0
                        if pledge_counter > 0:
                            pledge_counter -= 1
                            set_pledge_bar(pledge_counter)
                        suffix = '({0}/{1})'.format(pledge_counter,pledge_counter_max)
                    else:
                        reset_counter -= 1
                        if reset_counter < 0:
                            reset_counter = 0
                        
                        print button

                        self.set_message_buffer({'username': username, 'button': button})

                        self.game.push_button(button)
                    command(username, button + suffix)
                    set_reset_bar(reset_counter)
                else:
                    numclicks = button.count("click")
                    if numclicks > 0:
                      if numclicks > 9:
                        numclicks = 9
                      reset_counter -= 1 #numclicks?
                      if reset_counter < 0:
                              reset_counter = 0
                      self.game.push_button("click%d" % numclicks)
                      command(username, "click(%d)" % numclicks)
                      set_reset_bar(reset_counter)                        
开发者ID:starthal,项目名称:twitchplays-cookieclicker,代码行数:104,代码来源:bot.py


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