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_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_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_pig(self): phase = Phase() self.assertListEqual([], phase._pigs) pig = Pig() phase.add_pigs(pig) self.assertListEqual([pig], phase._pigs) pig1, pig2 = Pig(), Pig() phase.add_pigs(pig1, pig2) self.assertListEqual([pig, pig1, pig2], phase._pigs)
def teste_adicionar_porco(self): fase = Phase() self.assertListEqual([], fase._pigs) porco = Pig() fase.add_pigs(porco) self.assertListEqual([porco], fase._pigs) porco1, porco2 = Pig(), Pig() fase.add_pigs(porco1, porco2) self.assertListEqual([porco, porco1, porco2], fase._pigs)
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_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 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 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')
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)
from random import randint if __name__ == '__main__': fase = Phase(intervalo_de_colisao=32) # Adicionar Pássaros Amarelos for i in range(80): fase.add_birds(YellowBird(30, 30)) # Obstaculos theta = 270 h = 12 k = 7 step = 32 r = 50 while theta < 480: x = 600 + (h + r * math.cos(theta)) y = (k + r * math.sin(theta)) fase.add_obstacles(Obstacle(x, y)) theta += 32 # Porcos for i in range(30, 300, 32): x = randint(590, 631) y = randint(0, 21) fase.add_pigs(Pig(x, y)) rodar_fase(fase)
from actors import YellowBird, Pig from phase import Phase from graphics_tk import run_phase if __name__ == '__main__': fase = Phase(intervalo_de_colisao=10) deltax_gambi=80 # Adicionar Pássaros Amarelos for i in range(100): fase.add_birds(YellowBird(30, 30)) # linhas verticais for i in range(30, 300, 32): fase.add_pigs(Pig(700-deltax_gambi, i)) fase.add_pigs(Pig(200-deltax_gambi, i)) # linhas horizontais for i in range(240, 680, 32): fase.add_pigs(Pig(i-deltax_gambi, 30)) fase.add_pigs(Pig(i-deltax_gambi, 286)) x0 = 210-deltax_gambi # losango meio = 160 n = 9 delta_x = 28 delta_y = 12 for i in range(1, n): fase.add_pigs(Pig(x0 + delta_x * i, meio + delta_y * i))
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)
# -*- 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)
from phase import Phase from graphics_tk import run_phase from random import randint if __name__ == '__main__': fase = Phase(intervalo_de_colisao=32) # Adicionar Pássaros Amarelos for i in range(80): fase.add_birds(YellowBird(30, 30)) # Obstaculos theta = 270 h = 12 k = 7 step = 32 r = 50 while theta < 480: x = 600 + (h + r * math.cos(theta)) y = (k + r * math.sin(theta)) fase.add_obstacles(Obstacle(x, y)) theta += 32 # Porcos for i in range(30, 300, 32): x = randint(590, 631) y = randint(0, 21) fase.add_pigs(Pig(x, y)) run_phase(fase)
from actors import YellowBird, Pig from phase import Phase from graphics_tk import rodar_fase if __name__ == '__main__': fase = Phase(intervalo_de_colisao=10) deltax_gambi = 80 # Adicionar Pássaros Amarelos for i in range(100): fase.add_birds(YellowBird(30, 30)) # linhas verticais for i in range(30, 300, 32): fase.add_pigs(Pig(700 - deltax_gambi, i)) fase.add_pigs(Pig(200 - deltax_gambi, i)) # linhas horizontais for i in range(240, 680, 32): fase.add_pigs(Pig(i - deltax_gambi, 30)) fase.add_pigs(Pig(i - deltax_gambi, 286)) x0 = 210 - deltax_gambi # losango meio = 160 n = 9 delta_x = 28 delta_y = 12 for i in range(1, n): fase.add_pigs(Pig(x0 + delta_x * i, meio + delta_y * i))