def getSnails(self):
     x = int(self.backgroundWidth / self.width)
     n = random.randint(4 * x, 6 * x)
     for i in range(n):
         self.snails.append(
             Snail(self.width, self.height, self.skylineDict,
                   self.backgroundWidth))
Beispiel #2
0
def run_game():
    # Initialize game and create a screen object.
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Garden Game")
    # Make a snail.
    snail = Snail(settings, screen)
    # make a group to store bullets in.
    bullets = Group()
    # Make a mushroom group.
    mushrooms = Group()
    # Create instance to store game statistics and create a scoreboard.
    stats = GameStats(settings)
    sb = Scoreboard(settings, screen, stats)

    # Make the Play button
    play_button = Button(settings, screen, "Play")

    # Create grouping of mushrooms.
    gf.create_fleet(settings, screen, snail, mushrooms)

    # Start the main loop for the game.
    while True:
        gf.check_events(settings, screen, stats, sb, play_button, snail, mushrooms, bullets)
        
        gf.update_screen(settings, screen, stats, sb, snail, mushrooms, bullets, play_button)

        if stats.game_active:
            snail.update()
            gf.update_bullets(settings, screen, stats, sb, snail, mushrooms, bullets)
            gf.update_mushrooms(settings, stats, screen, sb, snail, mushrooms, bullets)
 def prep_snails(self):
     '''Show how many snails are left.'''
     self.snails = Group()
     for snail_number in range(self.stats.snails_left):
         snail = Snail(self.settings, self.screen)
         snail.rect.x = 10 + snail_number * snail.rect.width
         snail.rect.y = 10
         self.snails.add(snail)
 def test_solution_1_matrix_size_3(self):
     in_matrix = [[x for x in range(0, 3)] for _ in range(3)]
     out_matrix = [
         [0, 2, 6],
         [0, 9, 8],
         [0, 6, 10]
     ]
     snail = Snail()
     self.assertEqual(out_matrix, snail.solution_1(in_matrix), f'in_matrix:{in_matrix}')
 def test_update_submatrix_in_matrix_size_3_and_submatrix_size_1(self):
     out_matrix = [
         [0, 2, 6],
         [0, 9, 8],
         [0, 6, 10]
     ]
     in_matrix = copy.deepcopy(out_matrix)
     in_matrix[1][1] = 1
     in_submatrix = [[9]]
     snail = Snail()
     self.assertEqual(out_matrix, snail._update_submatrix_in_matrix(in_matrix, in_submatrix))
 def test_solution_1_matrix_size_2(self):
     in_matrix = [
         [0, 1],
         [0, 1]
     ]
     out_matrix = [
         [0, 2],
         [0, 3]
     ]
     snail = Snail()
     self.assertEqual(out_matrix, snail.solution_1(in_matrix))
 def appStarted(self):
     self.colors = getColors()
     self.backgroundUrl = self.app.url
     self.background = self.resizeBackground(self.backgroundUrl)
     self.lines = self.getLines()
     self.skyline = findSkyline(self.lines)
     self.skylineDict = skylineDict(self.skyline)
     self.getBackground(self.background)
     self.backgroundWidth = len(self.background[0]) - 1
     self.backgroundSlice = findScreen(self.background, 0, self.width)
     self.parrots = []
     self.foxes = []
     self.foxSprites = self.getFoxSprites()
     self.flipFoxSprites = self.getFlipSprites(self.foxSprites)
     self.getFoxes()
     self.snails = [
         Snail(self.width, self.height, self.skylineDict,
               self.backgroundWidth)
     ]
     #self.getSnails()
     self.parrotSprites = self.getParrotSprites()
     self.flipParrotSprites = self.getFlipSprites(self.parrotSprites)
     self.getParrots()
     self.player = Player(50, self.skylineDict[37])
     self.scrollX = self.scrollY = 0
     self.sprites = self.getPlayerSprites()
     self.gameOver = False
     self.score = 0
     self.lineArray = self.getLineArray()
     self.coinSprites = self.getCoinSprites()
     self.snailSprites = self.getSnailSprites()
     self.flipSnailSprites = self.getFlipSprites(self.snailSprites)
     self.coins = []
     self.getCoins()
     self.difficulty = self.getDifficulty()
     self.oldX, self.oldY = self.player.x, self.player.y
     self.time = 0
     self.g = 2
     self.getPolygons()
     self.building = None
     self.time = 0
     self.maxScore = self.getMaxScore()
Beispiel #8
0
 def test_4x1(self):
     snail = Snail(4, 2)
     self.assertEqual(snail.get_way(), [(0, 0), (0, 1), (1, 1), (2, 1),
                                        (3, 1), (3, 0), (2, 0), (1, 0)])
Beispiel #9
0
#new predator fish
bivis = PredatorFish(10, 'Bivis')
bathed = PredatorFish(10, 'Bathed')

#include fish in aquarium
for fish in range(QUANTITY_FISH):
    deep_house.add_resident(Fish(randint(1, 9)))

#include seaweed in aquarium
for seaweed in range(QUANTITY_SEAWEED):
    deep_house.add_resident(Seaweed(randint(1, 3)))

#include snail in aquarium
for snail in range(QUANTITY_SNAIL):
    deep_house.add_resident(Snail(randint(1, 5)))


#include predator fish in aquarium
def add_predator():
    yield deep_house.add_resident(bivis)
    yield deep_house.add_resident(bathed)


next(add_predator())
next(add_predator())

#let's start begin
while len(deep_house.current_auqarium) > QUANTITY_SNAIL + 2:
    count = len(deep_house.current_auqarium)
    resident = deep_house.current_auqarium[randint(0, count - 1)]
Beispiel #10
0
 def test_it_raises_InvalidParameterError_with_none_square_array(self):
     with self.assertRaises(InvalidParameterError):
         Snail([[2, 0]])
Beispiel #11
0
 def test_it_raises_InvalidParameterError_with_empty_array(self):
     with self.assertRaises(InvalidParameterError):
         Snail([])
Beispiel #12
0
    def test_when_square_3x3_result_is_its_values_in_snail_order(self):
        snail = Snail([[4, 2, 9], [1, 5, 5], [5, 4, 6]])

        self.assertEqual(snail.process(), [4, 2, 9, 5, 6, 4, 5, 1, 5])
Beispiel #13
0
    def test_when_square_2x2_result_is_its_values_in_snail_order(self):
        snail = Snail([[4, 2], [1, 5]])

        self.assertEqual(snail.process(), [4, 2, 5, 1])
Beispiel #14
0
    def test_when_square_0x0_result_is_empty_array_array(self):
        snail = Snail([[]])

        self.assertEqual(snail.process(), [])
Beispiel #15
0
 def test_it_raises_InvalidParameterError_with_string(self):
     with self.assertRaises(InvalidParameterError):
         Snail('a')
 def test_solution_1_matrix_size_1(self):
     in_matrix = [[0]]
     snail = Snail()
     self.assertEqual(in_matrix, snail.solution_1(in_matrix))
 def test_update_perimetr_with_matrix_size_1(self):
     in_matrix = [[1]]
     start_multiply = 2
     out_result = ([[2]], 3)
     snail = Snail()
     self.assertEqual(out_result, snail._update_perimeter(in_matrix, start_multiply))
 def test_get_submatrix_without_perimeter_size_3(self):
     in_matrix = [[x for x in range(0, 3)] for _ in range(3)]
     out_matrix = [[1]]
     snail = Snail()
     self.assertEqual(out_matrix, snail._get_submatrix_without_perimeter(in_matrix))
Beispiel #19
0
 def test_3x3(self):
     snail = Snail(3, 3)
     self.assertEqual(snail.get_way(), [(2, 1), (0, 1), (0, 2), (1, 2),
                                        (2, 2), (2, 1), (2, 0), (1, 0),
                                        (1, 1)])
Beispiel #20
0
 def test_it_raises_InvalidParameterError_with_string_in_array(self):
     with self.assertRaises(InvalidParameterError):
         Snail([[1, 1], [2, 'a']])
Beispiel #21
0
    def test_when_square_1x1_result_is_its_value(self):
        snail = Snail([[3]])

        self.assertEqual(snail.process(), [3])