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


Python Control.update方法代码示例

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


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

示例1: datagramReceived

# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import update [as 别名]
    def datagramReceived(self, data, addr):
        """Event handler of receiving a UDP request.
        Verify the identity of the client and assign a Control
        to it if it is trusted.
        """
        logging.debug("received DNS request from %s:%d" % (addr[0], addr[1]))

        if not self.transmit:
            try:
                dnsq = dnslib.DNSRecord.parse(data)
                query_data = str(dnsq.q.qname).split('.')
                # Give a NXDOMAIN response
                self.answer(dnsq, addr)
            except KeyError:
                logging.info("Corrupt request")

        try:
            # One control corresponds to one client (with a unique SHA1)

            # TODO: get obfs level from query length

            if self.transmit:
                main_pw, client_sha1, number, tcp_port, remote_ip, certs_str, signature = \
                    self.parse_udp_msg_transmit(data)
            else:
                main_pw, client_sha1, number, tcp_port, remote_ip, certs_str, signature = \
                    self.parse_udp_msg(*query_data[:6])
            if (client_sha1 + main_pw) not in self.controls:
                cert = self.certs_db.query(client_sha1)
                control = Control(self, signature, client_sha1, cert[0], cert[1],
                                  remote_ip, tcp_port,
                                  main_pw, number, certs_str)
                self.controls[client_sha1 + main_pw] = control
            else:
                control = self.controls[client_sha1 + main_pw]
                control.update(remote_ip, tcp_port, number)

            control.connect()

        except CorruptedReq:
            logging.debug("corrupt request")
        except KeyError:
            logging.warning("untrusted client attempting to connect")
        except AssertionError:
            logging.debug("authentication failed or corrupt request")
        except BlacklistReq:
            logging.debug("request or salt on blacklist")
        except IllegalReq:
            logging.debug("request for too many connections")
开发者ID:projectarkc,项目名称:arkc-server,代码行数:51,代码来源:coordinator.py

示例2: datagramReceived

# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import update [as 别名]
    def datagramReceived(self, data, addr):
        """Event handler of receiving a UDP request.
        Verify the identity of the client and assign a Control
        to it if it is trusted.
        """
        logging.debug("received DNS request from %s:%d" % (addr[0], addr[1]))
        try:
            dnsq = dnslib.DNSRecord.parse(data)
            query_data = str(dnsq.q.qname).split('.')
            # Give a NXDOMAIN response
            self.answer(dnsq, addr)
        except KeyError:
            logging.info("Corrupt request")

        try:
            # One control corresponds to one client (with a unique SHA1)

            # TODO: get obfs level from query length

            main_pw, client_sha1, number, tcp_port, remote_ip, certs_str = \
                self.parse_udp_msg(*query_data[:6])
            if client_sha1 is None:
                raise DuplicateError
            if client_sha1 not in self.controls:
                client_pub = self.certs[client_sha1][0]
                control = Control(self, client_pub, self.certs[client_sha1][1],
                                  remote_ip, tcp_port,
                                  main_pw, number, certs_str)
                self.controls[client_sha1] = control
            else:
                control = self.controls[client_sha1]
                control.update(remote_ip, tcp_port, main_pw, number)

            control.connect()

        except CorruptedReq:
            logging.info("Corrupt request")
        except KeyError:
            logging.error("untrusted client")
        except AssertionError:
            logging.error("authentication failed or corrupt request")
        except ClientAddrChanged:
            logging.error("client address or port changed")
开发者ID:CheckMySoul,项目名称:arkc-server,代码行数:45,代码来源:coordinator.py

示例3: __init__

# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import update [as 别名]
class Shapescape:
    # Initialize the boid view
    def __init__(self):
        self.win_width = 1024
        self.win_height = 768
        pygame.init()
        self.init_window()
        
        #title screen
        title_screen = TitleScreen(self.screen)
        title_screen.do_loop()

        self.game_loop()
        
        #gameover screen
        if globalvars.failed:
            gameover_screen = GameOver(self.screen, self.scoreboard)
            gameover_screen.do_loop()
    
    # Prepares the boid view
    def init_window(self): 
        # Initialize window
        self.screen = pygame.display.set_mode((self.win_width, self.win_height))
        pygame.display.set_caption('Shapescape')
        
        pygame.mouse.set_visible(1)
        
    # Continuesly renders the boid swarm
    def game_loop(self):
        clock = pygame.time.Clock()

        #Initialize
        self.scoreboard = Scoreboard()
        self.timer = CountDown()
        self.control = Control()
        self.graphics = Graphics(self.scoreboard, self.timer);
        self.player = Player(self.graphics)
        self.world = World(self.graphics, self.player) 
        self.logic = Logic(self.player, self.world, self.graphics, self.scoreboard, self.timer, self.control)
        
        while globalvars.run_game:
            delta = clock.tick(30) # fps

            # Catch input event
            for event in pygame.event.get():
                if event.type == QUIT:
                    return
                else:
                    self.control.update(event)
                
            # Update 
            self.logic.update(delta)
            self.world.update(delta)
            self.graphics.update(self.screen, delta)
            
            # Render
            self.graphics.draw(self.screen, delta);
            self.screen.blit(self.player.speedmsg, (0, 35))
            self.screen.blit(self.player.rotmsg, (0, 55))            
              
            pygame.display.flip()        
开发者ID:ivanvenosdel,项目名称:colored-shapes,代码行数:63,代码来源:main.py

示例4: __init__

# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import update [as 别名]
class Matrix:

    def __init__(self):
        engine.display.set_caption('Nexus')
        self.screen = engine.display.get_surface()
        self.width = self.screen.get_width()
        self.height = self.screen.get_height()
        self.background = engine.Surface((self.width, self.height))
        self.control = Control(self)
        if env.platform in ('pc','jvm'):
            self.adjust = False
        else:
            self.adjust = False
        self.collide_mask = engine.sprite.collide_mask
        self.data = engine.sprite.RenderUpdates()
        self.network = engine.sprite.RenderUpdates()    #nodes
        self.network_node = engine.sprite.RenderUpdates()   #nodes to update
        self.level = 1
        self.bot = None
        self.bots = engine.sprite.RenderUpdates()
        self.avatar = Avatar(self, 250, 550)
        self.avatars = engine.sprite.RenderUpdates(self.avatar)
        self.pulses = engine.sprite.RenderUpdates()
        self.charges = engine.sprite.RenderUpdates()
        self.data_construct = []
        engine.display.set_icon(self.avatar.image)
        self.quit = False
        self.update_rect = []
        self.nodes = [(x,y) for x in range(50,self.width,50) for y in range(50,self.height+50,50)]
        self.node_id = [(x,y) for x in range(1,int(self.width/50)) for y in range(1,int((self.height+50)/50))]
        self.nodex = [(x,-20) for x in range(50,self.width,50)]
        self.node = {}
        for i in range(len(self.nodes)):
            node_pos = self.nodes[i]
            identity = self.node_id[i]
            if identity == (5,10):
                node = Core(self,node_pos[0],node_pos[1],identity)
                self.nexus = node
            else:
                node = Node(self,node_pos[0],node_pos[1],identity)
            self.node[identity] = node
            self.network.add(node)
        self.directions = ['u','d','l','r']
        self.data_count = 0
        self.data_max = 25
        self.time_prev = 0
        self.time_diff = 0
        self.data_event = engine.USEREVENT
        self.data_event_time = 500
        self.surge_event = engine.USEREVENT+1
        self.surge_event_time = 15555
        self.spike_event = engine.USEREVENT+2
        self.spike_event_time = 21500
        self.bot_event = engine.USEREVENT+3
        self.bot_event_time = 5000
        self.level_event = engine.USEREVENT+4
        self.level_event_time = 60000
        if env.platform == 'pc':
            self.set_timer = engine.time.set_timer
        else:
            from util import set_timer
            self.set_timer = set_timer
        self.draw_grid()
        self.active = True

    def draw_grid(self):
        self.background.fill((20,20,20))
        for line in range(0,self.width+50,50):
            engine.draw.line(self.background, (43,50,58), (0,line), (self.height,line), 3)
        for line in range(0,self.height+50,50):
            engine.draw.line(self.background, (43,50,58), (line,0), (line,self.width), 3)
        self.network.update()
        self.update_rect.extend( self.network.draw(self.background) )
        self.screen.blit(self.background, (0,0))
        self.update_rect.append(self.screen.get_rect())

    def init(self):
        self.data_generator()
        self.set_timer(self.data_event,self.data_event_time)
        self.set_timer(self.surge_event,self.surge_event_time)
        self.set_timer(self.spike_event,self.spike_event_time)
        self.set_timer(self.bot_event,self.bot_event_time)
        self.set_timer(self.level_event,self.level_event_time)

    def set_active(self, state):
        self.active = state

    def node_check(self, entity):
        thread = int(entity.x)
        for i, node in enumerate(self.nodes):
            if node[0] == thread:
                if node[1] == int(entity.y):
                    return self.node[self.node_id[i]]
        return None

    def node_offset_check(self, entity, offset=(0,0)):
        pos_offset_x = offset[0] * 50
        pos_offset_y = offset[1] * 50
        thread = int(entity.x) + pos_offset_x
        for i, node in enumerate(self.nodes):
#.........这里部分代码省略.........
开发者ID:jggatc,项目名称:nexus,代码行数:103,代码来源:matrix.py

示例5: __init__

# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import update [as 别名]
class Game:
    "Representa la escena de pelea, donde el shaolin camina por el escenario."
    
    def __init__(self, world):
        self.world = world
        self.enemies = []

        self.sprites = group.Group()
        self.stage = Stage(self, self.sprites)
        self.sprites.camera = self.stage

        self.sprites_in_front = pygame.sprite.RenderPlain()
        self._create_player()
        self.stage.object_to_follow = self.player
        self.stage.load_level(1)

        if VISIBLE_DEBUG:
            # Visor de rendimiento
            self.text = Text(world.font, world.fps, "FPS: %d")
            self.sprites_in_front.add(self.text)

    def _create_player(self):
        self.control = Control()
        self.player = Player(self, self.control, self.sprites, DATADIR)
        self.sprites.add(self.player)
        self.sprites.add(self.player.shadow)
        self.sprites.add(self.player.bandage)

        self.energy = energy.EnergyView(10, 10, self.world.font)
        self.energy.set_model(self.player.energy_model)
        self.sprites_in_front.add(self.energy)

        self.enemy_energy = energy.EnergyView(440, 10, self.world.font)
        self.sprites_in_front.add(self.enemy_energy)

    def handle_event(self, event):
        if event.type == pygame.KEYDOWN:
            self.control.update(event, True)
            if event.key == pygame.K_ESCAPE:
                new_scene = scenes.mainmenu.MainMenu(self.world)
                self.world.change_state(new_scene)
        elif event.type == pygame.KEYUP:
            self.control.update(event, False)
        
    def update(self):
        self.stage.update()
        self.sprites.update()
        self.sprites_in_front.update()

        if DEBUG:
            b1, b2, b3 = pygame.mouse.get_pressed()

            if b1:
                self.stage.do_camera_effect()
            elif b2:
                self.stage.do_camera_effect(10)
            elif b3:
                self.world.fps.slow()

        self.control.post_update()

    def draw(self, screen):
        self.stage.draw(screen)
        self.sprites.draw(screen)
        self.sprites_in_front.draw(screen)
        self.stage.last_draw(screen)
        pygame.display.flip()

    def on_player_energy_model_change(self, model):
        pass

    def on_enemy_energy_model_change(self, model):
        self.enemy_energy.set_model(model)
开发者ID:HieuLsw,项目名称:sbfury,代码行数:75,代码来源:game.py


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