예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
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)
예제 #7
0
 def test_launched(self):
     red_bird = RedBird(1, 1)
     self.assertFalse(red_bird.launched(),
                      'Once launch method was not executed, should return False')
     red_bird.launch(0, 0)
     self.assertTrue(red_bird.launched(),
                     'Once launch method was executed on previous line, should return True')
예제 #8
0
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
예제 #9
0
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
예제 #10
0
 def teste_foi_lancado(self):
     """
     Teste de lançamento. Enquanto o método lançar do passaro não for chamado, o méotod foi_lancado deve retornar
     Falso
     :return:
     """
     passaro_vermelho = RedBird(1, 1)
     self.assertFalse(passaro_vermelho.launched(),
                      'Se o método lançar ainda não foi executado, deve retornar falso')
     passaro_vermelho.launch(0, 0)
     self.assertTrue(passaro_vermelho.launched(),
                     'Se o método lançar foi executado, deve retornar verdadeiro')
예제 #11
0
 def teste_ground_clash(self):
     red_bird = RedBird(0, 0)
     red_bird.ground_clash()
     self.assertEqual(DESTROYED, red_bird.status, 'Must clash with ground once y<=0')
     red_bird = RedBird(1, 0)
     red_bird.ground_clash()
     self.assertEqual(DESTROYED, red_bird.status, 'Must clash with ground once y<=0')
     red_bird = RedBird(2, 0)
     red_bird.ground_clash()
     self.assertEqual(DESTROYED, red_bird.status, 'Must clash with ground once y<=0')
     red_bird = RedBird(2, -0.1)
     red_bird.ground_clash()
     self.assertEqual(DESTROYED, red_bird.status, 'Must clash with ground once y<=0')
     red_bird = RedBird(2, -5)
     red_bird.ground_clash()
     self.assertEqual(DESTROYED, red_bird.status, 'Must clash with ground once y<=0')
예제 #12
0
 def test_status(self):
     red_bird = RedBird(1, 1)
     self.assertEqual('R', red_bird.character())
     actor_on_same_position = Actor()
     red_bird.clash(actor_on_same_position)
     self.assertEqual('r', red_bird.character())
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)
예제 #14
0
 def teste_colisao_com_chao(self):
     """
     Testando que o passáro colido quando sua posição y é menor ou igual a 0
     :return:
     """
     passaro = RedBird(0, 0)
     passaro.ground_clash()
     self.assertEqual(DESTROYED, passaro.status, 'Deve colidir com chão sempre que y<=0')
     passaro = RedBird(1, 0)
     passaro.ground_clash()
     self.assertEqual(DESTROYED, passaro.status, 'Deve colidir com chão sempre que y<=0')
     passaro = RedBird(2, 0)
     passaro.ground_clash()
     self.assertEqual(DESTROYED, passaro.status, 'Deve colidir com chão sempre que y<=0')
     passaro = RedBird(2, -0.1)
     passaro.ground_clash()
     self.assertEqual(DESTROYED, passaro.status, 'Deve colidir com chão sempre que y<=0')
     passaro = RedBird(2, -5)
     passaro.ground_clash()
     self.assertEqual(DESTROYED, passaro.status, 'Deve colidir com chão sempre que y<=0')
예제 #15
0
 def teste_status(self):
     passaro_amarelo = RedBird(1, 1)
     self.assertEqual('R', passaro_amarelo.character())
     outro_ator_na_mesma_posicao = Actor()
     passaro_amarelo.clash(outro_ator_na_mesma_posicao)
     self.assertEqual('r', passaro_amarelo.character())
예제 #16
0
# -*- 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)