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


Python Game.is_valid_button方法代码示例

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


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

示例1: __init__

# 需要导入模块: from lib.game import Game [as 别名]
# 或者: from lib.game.Game import is_valid_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 is_valid_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 is_valid_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 is_valid_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 is_valid_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

示例6: __init__

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

#.........这里部分代码省略.........
#        print "max votes = %s" % max_votes
        moves_choices = []
        counter = 0
        for item in templist:
            if item == max_votes and max_votes>0:
                moves_choices.append(counter)
            counter+=1
        self.reset_message_buffer()
        print moves_choices
        if len(moves_choices) == 0:		
            return self.choose_random_move()
        else:
            return choice(moves_choices)
		
    def choose_move(self):
        if len(self.message_buffer) == 0:
            random_move = self.choose_random_move()
            print("random move")
            print random_move
            return random_move
        else:
            user_move = self.choose_user_move()
       #     print user_move
            return user_move
			
    def make_move(self):
        if self.winner == True or self.is_cats == True:
            self.games+=1
            self.reset_game()
        elif self.winner == False:
            count = 0
            for move in self.game_tracker:
                if move == 0:
                    count+=1
                    break
            if count > 0:
                self.game_tracker[self.choose_move()]=self.whos_move+1
                if calculate_win_condition(self.game_tracker):
                    self.winner = True
                    if self.whos_move == 0:
                        self.owins+=1
                    else:
                        self.xwins+=1
            elif calculate_win_condition(self.game_tracker):
                self.winner = True
                if self.whos_move == 0:
                    self.owins+=1
                else:
                    self.xwins+=1
            else:
                self.is_cats = True
                self.cats_games+=1
				
    def alternate_turn(self):
        if self.whos_move == 0:
            self.whos_move = 1
        else:
            self.whos_move = 0
    def run(self):
		# created by Aidan Thomson
        #throttle_timers = {button:0 for button in config['throttled_buttons'].keys()}
        #get new messages from chat. Store valid messages only in the message buffer list 
		#after 5-10 seconds calculate the move that was chosen. If no move was chosen automatically choose an open one.
		#update the board.
		#calculate an end game condition
		#
        self.reset_game()
        #self.music.play(-1)

        while True:
           # self.draw_game()
            timer = time.clock() - self.game_timer
            if((timer-self.old_time)>.90):
                self.old_time = timer
                timer = int(timer)
 #
                self.draw_game()
                # every 10 seconds make a move and check for a win
                if timer > 0 and timer%3 == 0:
                    self.make_move()
                    self.alternate_turn()
				
            new_messages = None
            new_messages = self.irc.recv_messages(1024)   
            if new_messages != None: 
                for message in new_messages: 		
                    button = message['message'].lower()
                    username = message['username'].lower()
               #     print username + " " + button
                    if self.game.is_valid_button(button): 
                #        print button
                        self.message_buffer.append(button)
                        self.chat_buffer.append(str(username + ': ' + button))
                self.get_scrolling_chat()
#                self.reset_message_buffer()
            
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
开发者ID:travman89,项目名称:TwitchPlaysTicTacToe,代码行数:104,代码来源:bot.py

示例7: __init__

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

#.........这里部分代码省略.........
                    if upgrade_name == 'undefined':
                        self.irc.say('Invalid Upgrade')
                    else:
                        numdivs = 0
                        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:
开发者ID:starthal,项目名称:twitchplays-cookieclicker,代码行数:70,代码来源:bot.py


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