def test_game_over_with_pigs_and_birds(self): phase = Phase() pigs = [Pig(1, 1) for i in range(2)] # creating 2 pigs birds = [YellowBird(1, 1) for i in range(2)] # criating 2 birds phase.add_pigs(*pigs) phase.add_birds(*birds) self.assertEqual(ON_GOING, phase.status()) # clashing bird against pig on time 3 for bird, pig in zip(birds, pigs): bird.clash(pig, 3) self.assertEqual(VICTORY, phase.status()) phase.add_obstacles(Obstacle()) self.assertEqual(VICTORY, phase.status(), 'Obstacle must not interfere on game result') phase.add_pigs(Pig()) self.assertEqual( DEFEAT, phase.status(), 'With no active birds and one Pig active, player should lose') phase.add_birds(YellowBird()) self.assertEqual( ON_GOING, phase.status(), 'With one pig and bird both active, game should still going on')
def test_status(self): phase = Phase() pigs = [Pig(1, 1) for i in range(2)] birds = [YellowBird(1, 1) for i in range(2)] phase.add_pigs(*pigs) phase.add_birds(*birds) self.assertEqual(ON_GOING, phase.status()) for bird, pig in zip(birds, pigs): bird.clash(pig, 3) self.assertEqual(VICTORY, phase.status(), 'Without active pigs game should end with victory') phase.add_obstacles(Obstacle()) self.assertEqual(VICTORY, phase.status(), 'Obstacle must not interfere on game result') pig = Pig() phase.add_pigs(pig) self.assertEqual(DEFEAT, phase.status(), 'With Active Pig and with no Active bird, game should end with defeat') phase.add_birds(YellowBird()) self.assertEqual(ON_GOING, phase.status(), 'With active pig and birds, game should not end') pig.clash(pig, 3) self.assertEqual(VICTORY, phase.status(), 'Without active pigs game should end with victory')
def test_status(self): phase = Phase() pigs = [Pig(1, 1) for i in range(2)] birds = [YellowBird(1, 1) for i in range(2)] phase.add_pigs(*pigs) phase.add_birds(*birds) self.assertEqual(ON_GOING, phase.status()) for bird, pig in zip(birds, pigs): bird.clash(pig, 3) self.assertEqual(VICTORY, phase.status(), 'Without active pigs game should end with victory') phase.add_obstacles(Obstacle()) self.assertEqual(VICTORY, phase.status(), 'Obstacle must not interfere on game result') pig = Pig() phase.add_pigs(pig) self.assertEqual( DEFEAT, phase.status(), 'With Active Pig and with no Active bird, game should end with defeat' ) phase.add_birds(YellowBird()) self.assertEqual(ON_GOING, phase.status(), 'With active pig and birds, game should not end') pig.clash(pig, 3) self.assertEqual(VICTORY, phase.status(), 'Without active pigs game should end with victory')
def teste_status(self): fase = Phase() porcos = [Pig(1, 1) for i in range(2)] passaros = [YellowBird(1, 1) for i in range(2)] fase.add_pigs(*porcos) fase.add_birds(*passaros) self.assertEqual(ON_GOING, fase.status()) for passaro, porco in zip(passaros, porcos): passaro.clash(porco, 3) self.assertEqual(VICTORY, fase.status(), 'Sem porcos ativos o jogo deveria terminar com vitória') fase.add_obstacles(Obstacle()) self.assertEqual(VICTORY, fase.status(), 'Obstáculo não interfere para definir vitória') porco = Pig() fase.add_pigs(porco) self.assertEqual(DEFEAT, fase.status(), 'Com Pig ativo e sem pássaro para lançar, o jogo deveria acabar em derrota') fase.add_birds(YellowBird()) self.assertEqual(ON_GOING, fase.status(), 'Com Pig ativo e com pássaro para lançar, o jogo não deveria acabar') porco.clash(porco, 3) self.assertEqual(VICTORY, fase.status(), 'Sem porco ativo, o jogo deveria acabar com vitória')
def test_non_default_clash_interval(self): phase = Phase(30) bird = YellowBird(1, 1) phase.add_birds(bird) pig = Pig(31, 31) phase.add_pigs(pig) phase.calculate_points(0) self.assertEqual(DESTROYED, bird.status) self.assertEqual(DESTROYED, pig.status)
def main(): global fase, passaros, porcos, obstaculos fase = Phase(clash_interval=32) passaros = [RedBird(30, 30), YellowBird(30, 30), YellowBird(30, 30)] porcos = [Pig(750, 1), Pig(700, 1)] obstaculos = [Obstacle(310, 100)] fase.add_obstacles(*obstaculos) fase.add_birds(*passaros) fase.add_pigs(*porcos) rodar_fase(fase)
def test_add_bird(self): phase = Phase() self.assertListEqual([], phase._birds) bird = RedBird() phase.add_birds(bird) self.assertListEqual([bird], phase._birds) bird1, bird2 = RedBird(), YellowBird() phase.add_birds(bird1, bird2) self.assertListEqual([bird, bird1, bird2], phase._birds)
def test_default_clash_interval(self): phase = Phase() bird = YellowBird(1, 1) phase.add_birds(bird) porco = Pig(2, 2) phase.add_pigs(porco) phase.calculate_points(0) self.assertEqual(DESTROYED, bird.status) self.assertEqual(DESTROYED, porco.status)
def teste_adicionar_passaro(self): fase = Phase() self.assertListEqual([], fase._birds) passaro = RedBird() fase.add_birds(passaro) self.assertListEqual([passaro], fase._birds) passaro1, passaro2 = RedBird(), YellowBird() fase.add_birds(passaro1, passaro2) self.assertListEqual([passaro, passaro1, passaro2], fase._birds)
def teste_intervalo_de_colisao_nao_padrao(self): ''' Método que testa se o intervalo de colisão da Phase é repassado aos atores. valor testado: 31 ''' fase = Phase(30) passaro = YellowBird(1, 1) fase.add_birds(passaro) porco = Pig(31, 31) fase.add_pigs(porco) fase.calculate_points(0) self.assertEqual(DESTROYED, passaro.status) self.assertEqual(DESTROYED, porco.status)
def create_phase(multplier=1): example_phase = Phase(1 if multplier == 1 else 32) birds = [RedBird(3 * multplier, 3 * multplier), YellowBird(3 * multplier, 3 * multplier), YellowBird(3 * multplier, 3 * multplier)] pigs = [Pig(78 * multplier, multplier), Pig(70 * multplier, multplier)] obstacles = [Obstacle(31 * multplier, 10 * multplier)] example_phase.add_birds(*birds) example_phase.add_pigs(*pigs) example_phase.add_obstacles(*obstacles) return example_phase
def criar_fase_exemplo(multiplicador=1): fase_exemplo = Phase(1 if multiplicador == 1 else 32) passaros = [RedBird(3 * multiplicador, 3 * multiplicador), YellowBird(3 * multiplicador, 3 * multiplicador), YellowBird(3 * multiplicador, 3 * multiplicador)] porcos = [Pig(78 * multiplicador, multiplicador), Pig(70 * multiplicador, multiplicador)] obstaculos = [Obstacle(31 * multiplicador, 10 * multiplicador)] fase_exemplo.add_birds(*passaros) fase_exemplo.add_pigs(*porcos) fase_exemplo.add_obstacles(*obstaculos) return fase_exemplo
def create_phase(multplier=1): example_phase = Phase(1 if multplier == 1 else 32) birds = [ RedBird(3 * multplier, 3 * multplier), YellowBird(3 * multplier, 3 * multplier), YellowBird(3 * multplier, 3 * multplier) ] pigs = [Pig(78 * multplier, multplier), Pig(70 * multplier, multplier)] obstacles = [Obstacle(31 * multplier, 10 * multplier)] example_phase.add_birds(*birds) example_phase.add_pigs(*pigs) example_phase.add_obstacles(*obstacles) return example_phase
def teste_lancar_passaro_sem_erro_quando_nao_existe_passaro(self): passaro_vermelho, passaro_amarelo = RedBird(1, 1), YellowBird(1, 1) fase = Phase() fase.add_birds(passaro_vermelho, passaro_amarelo) self.assertFalse(passaro_vermelho.launched()) self.assertFalse(passaro_amarelo.launched()) fase.launch(90, 1) fase.launch(45, 3) fase.launch(31, 5) # testando que lançar passaros depios de todos lançados não causa erro self.assertTrue(passaro_vermelho.launched()) self.assertEqual(math.radians(90), passaro_vermelho._launch_angle) self.assertEqual(1, passaro_vermelho._launch_time) self.assertTrue(passaro_amarelo.launched()) self.assertEqual(math.radians(45), passaro_amarelo._launch_angle) self.assertEqual(3, passaro_amarelo._launch_time)
def test_launch_without_error_when_there_is_no_bird_to_be_launch(self): red_bird, yellow_bird = RedBird(1, 1), YellowBird(1, 1) phase = Phase() phase.add_birds(red_bird, yellow_bird) self.assertFalse(red_bird.launched()) self.assertFalse(yellow_bird.launched()) phase.launch(90, 1) phase.launch(45, 3) phase.launch(31, 5) # There is no bird to launch here self.assertTrue(red_bird.launched()) self.assertEqual(math.radians(90), red_bird._launch_angle) self.assertEqual(1, red_bird._launch_time) self.assertTrue(yellow_bird.launched()) self.assertEqual(math.radians(45), yellow_bird._launch_angle) self.assertEqual(3, yellow_bird._launch_time)
def teste_acabou_com_porcos_e_passaros(self): fase = Phase() porcos = [Pig(1, 1) for i in range(2)] # criando 2 porcos passaros = [YellowBird(1, 1) for i in range(2)] # criando 2 pássaros fase.add_pigs(*porcos) fase.add_birds(*passaros) self.assertEqual(ON_GOING, fase.status()) # colidindo cada passaro com um porco no tempo 3 for passaro, porco in zip(passaros, porcos): passaro.clash(porco, 3) self.assertEqual(VICTORY, fase.status()) fase.add_obstacles(Obstacle()) self.assertEqual(VICTORY, fase.status(), 'Obstáculo não interfere no fim do jogo') fase.add_pigs(Pig()) self.assertEqual(DEFEAT, fase.status(), 'Com Pig ativo e sem pássaro para lançar, o jogo deveria acabar') fase.add_birds(YellowBird()) self.assertEqual(ON_GOING, fase.status(), 'Com Pig ativo e com pássaro para lançar, o jogo não deveria acabar')
def test_game_over_with_pigs_and_birds(self): phase = Phase() pigs = [Pig(1, 1) for i in range(2)] # creating 2 pigs birds = [YellowBird(1, 1) for i in range(2)] # criating 2 birds phase.add_pigs(*pigs) phase.add_birds(*birds) self.assertEqual(ON_GOING, phase.status()) # clashing bird against pig on time 3 for bird, pig in zip(birds, pigs): bird.clash(pig, 3) self.assertEqual(VICTORY, phase.status()) phase.add_obstacles(Obstacle()) self.assertEqual(VICTORY, phase.status(), 'Obstacle must not interfere on game result') phase.add_pigs(Pig()) self.assertEqual(DEFEAT, phase.status(), 'With no active birds and one Pig active, player should lose') phase.add_birds(YellowBird()) self.assertEqual(ON_GOING, phase.status(), 'With one pig and bird both active, game should still going on')
import sys project_dir = path.dirname(__file__) project_dir = path.join('..') sys.path.append(project_dir) from actors import YellowBird, RedBird, Obstacle, Pig from phase import Phase from graphics_tk import rodar_fase if __name__ == '__main__': fase = Phase(intervalo_de_colisao=32) # Adicionar Pássaros Vermelhos for i in range(5): fase.add_birds(RedBird(30, 30)) # Adicionar Pássaros Amarelos for i in range(30): fase.add_birds(YellowBird(30, 30)) # Obstaculos for i in range(30, 480, 32): fase.add_obstacles(Obstacle(300, i)) # Porcos for i in range(30, 300, 32): fase.add_pigs(Pig(600, i)) rodar_fase(fase)
# -*- coding: utf-8 -*- from actors import RedBird, YellowBird, Pig, Obstacle from phase import Phase import placa_grafica fase_exemplo = Phase() passaros = [RedBird(3, 3), YellowBird(3, 3), YellowBird(3, 3)] porcos = [Pig(78, 1), Pig(70, 1)] obstaculos = [Obstacle(31, 10)] fase_exemplo.add_birds(*passaros) fase_exemplo.add_pigs(*porcos) fase_exemplo.add_obstacles(*obstaculos) # Solução para ganhar # fase_exemplo.lancar(45, 1) # fase_exemplo.lancar(63, 3) # fase_exemplo.lancar(23, 4) if __name__ == '__main__': placa_grafica.animar(fase_exemplo)
import sys project_dir = path.dirname(__file__) project_dir = path.join('..') sys.path.append(project_dir) from actors import YellowBird, RedBird, Obstacle, Pig from phase import Phase from graphics_tk import run_phase if __name__ == '__main__': fase = Phase(intervalo_de_colisao=32) # Adicionar Pássaros Vermelhos for i in range(5): fase.add_birds(RedBird(30, 30)) # Adicionar Pássaros Amarelos for i in range(30): fase.add_birds(YellowBird(30, 30)) # Obstaculos for i in range(30, 480, 32): fase.add_obstacles(Obstacle(300, i)) # Porcos for i in range(30, 300, 32): fase.add_pigs(Pig(600, i)) run_phase(fase)