當前位置: 首頁>>代碼示例>>Python>>正文


Python HelperFunctions.random_rgb方法代碼示例

本文整理匯總了Python中HelperFunctions.random_rgb方法的典型用法代碼示例。如果您正苦於以下問題:Python HelperFunctions.random_rgb方法的具體用法?Python HelperFunctions.random_rgb怎麽用?Python HelperFunctions.random_rgb使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在HelperFunctions的用法示例。


在下文中一共展示了HelperFunctions.random_rgb方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import HelperFunctions [as 別名]
# 或者: from HelperFunctions import random_rgb [as 別名]
    def __init__(self, colour=None, size=None, position=None):
        pygame.sprite.Sprite.__init__(self)
        # Make sure snake valid parameters
        if colour == None:
            colour = Snake._DEFAULT_COLOUR
        if size == None:
            size = Snake._DEFAULT_SIZE
        #if size[0] != size[1]:
        #    raise Exception('Invalid tile size. Width and height must be equal.')
        if position == None:
            position = Snake._DEFAULT_POSITION

        self.color = colour
        self.size = size
        #self.head = Snake._SnakeHead(colour, size, position)
        self.segments.append(Snake._SnakeSegment(colour, size, position))

        self.head = self.segments[0]
        #self.tail = Snake._SnakeTail()

        self.curseTail = 0

        self.direction = Snake.SnakeMove.UP


        print "TODO: make this use self.adjust_tail_size()"

        for x in range(1, Config.INITIAL_LENGTH): # Initial Length
            tailposition = [(position[0] - x*size[0]), position[1]]
            # self.tail.add_tail_section(colour, size, tailposition)
            self.segments.append(Snake._SnakeSegment(HelperFunctions.random_rgb(), size, tailposition))
開發者ID:jamietanna,項目名稱:PySnake,代碼行數:33,代碼來源:Snake_Module.py

示例2: adjust_tail_size

# 需要導入模塊: import HelperFunctions [as 別名]
# 或者: from HelperFunctions import random_rgb [as 別名]
    def adjust_tail_size(self, number):
        size = self.size[0]

        current_direction = self.direction

        if number > 0:
            for count in range(number):
            # ### TODO - randomly generate from the colour of the food eaten
                if self.curseTail > 0:
                    colour = Config.BACKGROUND_COLOUR
                else:
                    colour = HelperFunctions.random_rgb()
                # Randomise colour of new tail section

                lastindex = len(self.segments) - 1
                X = self.segments[lastindex].rect.topleft[0]
                Y = self.segments[lastindex].rect.topleft[1]
                
                # New tail section position
                if current_direction == Snake.SnakeMove.RIGHT:
                    X = X - size + (count*size)
                elif current_direction == Snake.SnakeMove.LEFT:
                    X = X + size + (count*size)
                elif current_direction == Snake.SnakeMove.UP:
                    Y = Y - size + (count*size)
                elif current_direction == Snake.SnakeMove.DOWN:
                    Y = Y + size + (count*size)

                self.segments.append(Snake._SnakeSegment(colour, self.size, [X, Y]))
        else:
            for count in range(abs(number)):
                # leave at least the head
                if(len(self.segments) > 1):
                    del self.segments[-1]
開發者ID:jamietanna,項目名稱:PySnake,代碼行數:36,代碼來源:Snake_Module.py

示例3: curse_tail

# 需要導入模塊: import HelperFunctions [as 別名]
# 或者: from HelperFunctions import random_rgb [as 別名]
    def curse_tail(self):

        self.randomize_snake_colour()
        
        
        self.curseTail = Config.FOOD_CURSE_TIME_TO_WEAR_OFF * Config.FPS
        for (idx, s) in enumerate(self.segments):
            if idx > 0:
                s.set_colour(Config.BACKGROUND_COLOUR)
            else:
                s.set_colour(HelperFunctions.random_rgb())
開發者ID:jamietanna,項目名稱:PySnake,代碼行數:13,代碼來源:Snake_Module.py

示例4: randomize_snake_colour

# 需要導入模塊: import HelperFunctions [as 別名]
# 或者: from HelperFunctions import random_rgb [as 別名]
 def randomize_snake_colour(self):
     for s in self.segments:
         s.set_colour(HelperFunctions.random_rgb())
開發者ID:jamietanna,項目名稱:PySnake,代碼行數:5,代碼來源:Snake_Module.py


注:本文中的HelperFunctions.random_rgb方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。