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 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 addSnails(self, numberOfSnails): """ Add a number of snails to the teams, this creates snails objects. """ for i in range(0, numberOfSnails): snail = Snail(self) snail.id = i self.add(snail) self.orderedSnailList.append(snail) self.orderedSnailList[len(self.orderedSnailList) - 1].hasTurn = True
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))
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 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()
def setUp(self): """ set up data used in the tests. setUp is called before each test function execution. """ pygame.init() pygame.display.set_mode([Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT]) self.input = Input() self.terrain = Terrain() self.teamName = "EJteam" self.team = Team(self.teamName) self.team.setGravity(Direction.DOWN) self.team.hasTurn = True TurnManager().status = TurnStatus.CURRENTTURN TurnManager().teams = [] TurnManager().teams.append(self.team) self.snail = Snail(self.team) self.snail.hasTurn = True
def test_it_raises_InvalidParameterError_with_string_in_array(self): with self.assertRaises(InvalidParameterError): Snail([[1, 1], [2, 'a']])
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))
class testSnail(unittest.TestCase): """ A test class for the Snail module. """ def setUp(self): """ set up data used in the tests. setUp is called before each test function execution. """ pygame.init() pygame.display.set_mode([Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT]) self.input = Input() self.terrain = Terrain() self.teamName = "EJteam" self.team = Team(self.teamName) self.team.setGravity(Direction.DOWN) self.team.hasTurn = True TurnManager().status = TurnStatus.CURRENTTURN TurnManager().teams = [] TurnManager().teams.append(self.team) self.snail = Snail(self.team) self.snail.hasTurn = True def testInitialized(self): self.assertEqual(self.snail.team.name, self.teamName) # self.assertEqual(self.snail.hasTurn, False) def testFollowMouse(self): self.input.mouse_x = 100 self.input.mouse_y = 100 self.snail.update(self.input, self.terrain) self.assertEqual(self.snail.rect.centerx, 100) self.assertEqual(self.snail.rect.centery, 100) self.input.mouse_x = 150 self.input.mouse_y = 150 self.terrain.addBlock(150, 150) self.snail.update(self.input, self.terrain) self.assertNotEqual(self.snail.rect.centerx, 150) self.assertNotEqual(self.snail.rect.centery, 150) def testSnailPlaceSnailCorrect(self): self.input.mouse_x = 100 self.input.mouse_y = 100 self.input.mouse_left = True self.input.mouse_left_click = True self.snail.update(self.input, self.terrain) self.assertTrue(self.snail.isPlaced) def testSnailPlaceSnailWrong(self): self.input.mouse_x = 150 self.input.mouse_y = 150 self.terrain.addBlock(150, 150) self.input.mouse_left = True self.snail.update(self.input, self.terrain) self.assertFalse(self.snail.isPlaced) def testGravityDown(self): self.testSnailPlaceSnailCorrect() self.team.setGravity(Direction.DOWN) old_y = self.snail.rect.centery for i in range(0,10): self.snail.update(self.input, self.terrain) self.assertTrue(self.snail.rect.centery > old_y) def testGravityDownSpeed(self): self.testSnailPlaceSnailCorrect() self.assertEqual(self.snail.direction['jump'], 0) self.snail.updateGravity() self.assertEqual(self.snail.direction['jump'], self.snail.speed['fall']) waitTurns = 5 / self.snail.speed['fall'] for i in range(0, waitTurns + 5): self.snail.updateGravity() self.assertEqual(self.snail.direction['jump'], 5) def testGravityUp(self): self.testSnailPlaceSnailCorrect() self.snail.gravity_direction = Direction.UP old_y = self.snail.rect.centery for i in range(0,10): self.snail.update(self.input, self.terrain) self.assertTrue(self.snail.rect.centery < old_y) def testGravityRight(self): self.testSnailPlaceSnailCorrect() self.snail.gravity_direction = Direction.RIGHT old_x = self.snail.rect.centerx for i in range(0,10): self.snail.update(self.input, self.terrain) self.assertTrue(self.snail.rect.centerx > old_x) def testGravityLeft(self): self.testSnailPlaceSnailCorrect() self.snail.gravity_direction = Direction.LEFT old_x = self.snail.rect.centerx for i in range(0,10): self.snail.update(self.input, self.terrain) self.assertTrue(self.snail.rect.centerx < old_x) def testAiming(self): pass def testShooting(self): pass def testMoving(self): pass def testJumping(self): pass def testDie(self): self.assertEquals(self.snail.hitpoints, 100) def testCollision(self): pass def testTouchingSalt(self): pass
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)])
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)])
def test_it_raises_InvalidParameterError_with_none_square_array(self): with self.assertRaises(InvalidParameterError): Snail([[2, 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)]
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])
def test_it_raises_InvalidParameterError_with_empty_array(self): with self.assertRaises(InvalidParameterError): Snail([])
def test_when_square_1x1_result_is_its_value(self): snail = Snail([[3]]) self.assertEqual(snail.process(), [3])
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])
def test_when_square_0x0_result_is_empty_array_array(self): snail = Snail([[]]) self.assertEqual(snail.process(), [])
def getSnailSprites(self): i = Image.open(Snail.url) i = i.resize((int(self.width / 30), int(self.width / 30)), Image.ANTIALIAS) sprites = Snail.getSprites(int(self.width / 30), int(self.width / 30)) return (self.getSprites(i, sprites))
def test_it_raises_InvalidParameterError_with_string(self): with self.assertRaises(InvalidParameterError): Snail('a')
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_solution_1_matrix_size_1(self): in_matrix = [[0]] snail = Snail() self.assertEqual(in_matrix, snail.solution_1(in_matrix))