コード例 #1
0
def _get_simple_diamond():
    d = Diamond()
    d.set_shape("round")
    d.set_size(2.10)
    d.set_color("E")
    d.set_clarity("VS2")
    return d
コード例 #2
0
def _get_simple_diamond():
	d = Diamond()
	d.set_shape("round")
	d.set_size(2.10)
	d.set_color("E")
	d.set_clarity("VS2")
	return d
コード例 #3
0
ファイル: functions.py プロジェクト: psitronic/Wages_Of_Fear
def create_diamonds(wof_settings,screen,diamonds,levelMap):
    """
    Create a set of diamonds
    """
       
    diamond_width = wof_settings.element_width
    diamond_height = wof_settings.element_height
    
    # Place the diamonds to the field
    for diamond_position in levelMap['diamond']:
        diamond = Diamond(screen)
        diamond.x = diamond_position[1] * diamond_width
        diamond.y = diamond_position[0] * diamond_height
        diamond.rect.x = diamond.x
        diamond.rect.y = diamond.y
        diamonds.add(diamond)            
コード例 #4
0
    def test_when_c_given_it_returns_expected_list(self):
        expected = [
            '  ', 'a', '\n', ' ', 'b', ' ', 'b', '\n', 'c', '   ', 'c', '\n',
            ' ', 'b', ' ', 'b', '\n', '  ', 'a', '\n'
        ]

        res = Diamond().get_chars_list('c')

        self.assertListEqual(res, expected)
コード例 #5
0
ファイル: test_diamond.py プロジェクト: Mehdi-H/diamond_kata
class TestDiamond(TestCase):

    def setUp(self):
        self.diamond = Diamond()

    def test_create_diamond_should_return_diamond_size_1_when_up_to_A(self):
        # Given
        stop_letter = 'A'

        # When
        result = self.diamond.up_to(stop_letter)

        # Then
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0], 'A')
コード例 #6
0
def read_data(file_name):
    """
    Reads data from file
    :param file_name: File name
    :return: Diamonds data, header row cell's names
    """
    _diamonds = []
    file = open(file_name, 'r')
    _header = [
        item.replace('"', '').rstrip('\n')
        for item in file.readline().split(',')
    ]

    while True:
        line = file.readline()

        if not line:
            return _diamonds, _header

        new_diamond = Diamond().parse(line)
        _diamonds.append(new_diamond)
コード例 #7
0
    def test_when_b_given_it_returns_empty_string(self):
        res = Diamond().indent(current='b', limit='b')

        self.assertEqual(res, '')
コード例 #8
0
def gameLoop():
    gameExit = False
    gameOver = False

    points = 0
    speed = FPS

    lead_x = display_width / 2
    lead_y = display_height / 2
    lead_x_change = block_size
    lead_y_change = 0

    snake = Snake(lead_x, lead_y)
    stones = Stones()
    apple = Apple(stones, snake)
    diamond = Diamond()
    trimer = Diamond()

    while not gameExit:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = True

            if event.type == pygame.KEYDOWN:
                if (event.key == pygame.K_LEFT) and snake.direction != "right":
                    snake.direction = "left"
                elif (event.key == pygame.K_RIGHT) and snake.direction != "left":
                    snake.direction = "right"
                elif (event.key == pygame.K_UP) and snake.direction != "down":
                    snake.direction = "up"
                elif (event.key == pygame.K_DOWN) and snake.direction != "up":
                    snake.direction = "down"

                if event.key == pygame.K_p:
                    pause()

        if snake.direction == "left":
            lead_x_change = -block_size
            lead_y_change = 0
        elif snake.direction == "right":
            lead_x_change = block_size
            lead_y_change = 0
        elif snake.direction == "up":
            lead_y_change = -block_size
            lead_x_change = 0
        elif snake.direction == "down":
            lead_y_change = block_size
            lead_x_change = 0

        lead_x += lead_x_change
        lead_y += lead_y_change

        if lead_x == apple.x and lead_y == apple.y:
            apple = Apple(stones, snake)
            snake.length += 1
            points += 10
            POINT.play()

            if (points) % 40 == 0:
                stones.add(snake)

            if (points) % 70 == 0:
                speed += 1
                print(speed)

            if (points) % 150 == 0:
                diamond.renew(stones, snake, speed)

            if (points) % 280 == 0:
                trimer.renew(Stones, snake, speed)

        if lead_x == diamond.x and lead_y == diamond.y:
            points += 50
            diamond.kill()
            snake.superSnake(speed)
            EVOLUTION.play()

            if points % 280 == 0:
                trimer.renew(stones, snake, speed)

        if lead_x == trimer.x and lead_y == trimer.y:
            points += 50
            trimer.kill()
            snake.trim()

            if points % 150 == 0:
                diamond.renew(stones, snake, speed)

        if snake.superTimer > 0:
            if 15 <= snake.superTimer:
                pygame.mixer.music.set_volume(0.05)
            if 15 > snake.superTimer >= 10:
                pygame.mixer.music.set_volume(0.10)
            elif 10 > snake.superTimer >= 5:
                pygame.mixer.music.set_volume(0.15)
            elif 5 > snake.superTimer:
                pygame.mixer.music.set_volume(0.2)
            for stone in Stones.list:
                if stone[0] == snake.head[1] and stone[1] == snake.head[2]:
                    points += 20
                    Stones.destroy(stone)
                    STONEDESTROY.play()

            if lead_x >= display_width - block_size:
                lead_x = block_size
            elif lead_x < block_size:
                lead_x = display_width - 2 * block_size
            elif lead_y >= display_height - block_size:
                lead_y = block_size
            elif lead_y < block_size:
                lead_y = display_height - 2 * block_size

        snake.update(lead_x, lead_y)
        gameOver = snake.isDead(stones)

        gameDisplay.blit(background, (0, 0))
        apple.show(gameDisplay)
        stones.show(gameDisplay)
        diamond.show(gameDisplay, 'black')
        trimer.show(gameDisplay, 'white')
        snake.show(gameDisplay, FPS)
        gameDisplay.blit(wall, (0, 0))
        score(gameDisplay, points)

        pygame.display.update()
        clock.tick(speed)

        while gameOver == True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gameExit = True
                    gameOver = False
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        gameExit = True
                        gameOver = False
                    if event.key == pygame.K_c:
                        gameLoop()

            gameDisplay.blit(GAMEOVER, (0, 0))
            draw_text(gameDisplay, "SCORE: " + str(points), czarny, 50, display_width / 2, display_height / 2 - 25)

            button("MENU", 100, 450, 200, 70, czerwony, LIGHT_RED, action='menu')
            button("PLAY AGAIN", 350, 450, 200, 70, czerwony, LIGHT_RED, action='again')
            button("QUIT", 600, 450, 200, 70, czerwony, LIGHT_RED, action='quit')

            pygame.display.update()
            clock.tick(15)

    pygame.quit()
    pygame.font.quit()
    quit()
コード例 #9
0
ファイル: test_diamond.py プロジェクト: glossopm/diamond-kata
 def test_B(self):
     output = """ A\nB B\n A"""
     printer = Printer(Diamond('B').draw())
     self.assertEqual(output, printer.text)
コード例 #10
0
    def test_when_a_given_it_returns_expected_diamond(self):
        expected = 'a\n'

        res = Diamond().create('a')

        self.assertEqual(res, expected)
コード例 #11
0
    def test_when_a_given_it_returns_a(self):
        expected = ['a', '\n']

        res = Diamond().get_chars_list('a')

        self.assertEqual(res, expected)
コード例 #12
0
ファイル: test_diamond.py プロジェクト: glossopm/diamond-kata
 def test_E(self):
     output = """    A\n   B B\n  C   C\n D     D\nE       E\n D     D\n  C   C\n   B B\n    A"""
     printer = Printer(Diamond('E').draw())
     self.assertEqual(output, printer.text)
コード例 #13
0
    def test_when_c_given_and_current_is_a_it_returns_two_spaces(self):
        res = Diamond().indent(current='a', limit='c')

        self.assertEqual(res, '  ')
コード例 #14
0
    def test_when_c_given_it_returns_expected_list(self):
        res = Diamond().get_letters_from(limit='c')

        self.assertEqual([c for c in res], ['a', 'b', 'c', 'b', 'a'])
コード例 #15
0
ファイル: test_diamond.py プロジェクト: Mehdi-H/diamond_kata
 def setUp(self):
     self.diamond = Diamond()
コード例 #16
0
    def test_when_b_given_and_current_is_a_it_returns_one_space(self):
        res = Diamond().indent(current='a', limit='b')

        self.assertEqual(res, ' ')
コード例 #17
0
    def test_when_c_given_it_returns_three_spaces(self):
        res = Diamond().separator('c')

        self.assertEqual(res, '   ')
コード例 #18
0
    def test_when_b_given_it_returns_one_spaces(self):
        res = Diamond().separator('b')

        self.assertEqual(res, ' ')
コード例 #19
0
    def test_when_a_given_it_returns_empty_string(self):
        res = Diamond().separator('a')

        self.assertEqual(res, '')
コード例 #20
0
ファイル: test_diamond.py プロジェクト: glossopm/diamond-kata
 def test_A(self):
     output = "A"
     printer = Printer(Diamond('A').draw())
     self.assertEqual(output, printer.text)
コード例 #21
0
ファイル: test_diamond.py プロジェクト: glossopm/diamond-kata
 def test_multi_chars(self):
     output = "Enter a valid letter in the Alphabet, looking at you Ben."
     printer = Printer(Diamond('AA').draw())
     self.assertEqual(output, printer.text)