From 96668a79cdaadaf63e67ea060683bf5857d53079 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Mon, 19 Feb 2018 10:46:50 -0300 Subject: [PATCH 01/49] Criada a classe Pessoa --- oo/__init__.py | 0 oo/pessoa.py | 2 ++ 2 files changed, 2 insertions(+) create mode 100644 oo/__init__.py create mode 100644 oo/pessoa.py diff --git a/oo/__init__.py b/oo/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/oo/pessoa.py b/oo/pessoa.py new file mode 100644 index 000000000..e1da50e22 --- /dev/null +++ b/oo/pessoa.py @@ -0,0 +1,2 @@ +class Pessoa: + pass \ No newline at end of file From 1c3dafc1ca9ef475ef2b919ee5833ab102207bcc Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Mon, 19 Feb 2018 11:01:23 -0300 Subject: [PATCH 02/49] =?UTF-8?q?Criado=20m=C3=A9todo=20cumprimentar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/pessoa.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index e1da50e22..f9cc586bb 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,2 +1,10 @@ class Pessoa: - pass \ No newline at end of file + def cumprimentar(self): + return f'Olá {id(self)}' + + +if __name__ == '__main__': + p = Pessoa() + print(Pessoa.cumprimentar(p)) + print(id(p)) + print(p.cumprimentar()) From e22f1c5f185b95a1543c26cbf7963574e46d8d14 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Wed, 21 Feb 2018 11:03:35 -0300 Subject: [PATCH 03/49] Criados attr de instancia - nome e idade --- oo/pessoa.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index f9cc586bb..ac8525d43 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,10 +1,20 @@ class Pessoa: + def __init__(self, nome=None, idade=35): + self.idade = idade + self.nome = nome + def cumprimentar(self): return f'Olá {id(self)}' if __name__ == '__main__': - p = Pessoa() + p = Pessoa('Luciano') print(Pessoa.cumprimentar(p)) print(id(p)) print(p.cumprimentar()) + print(p.nome) + p.nome = "Renzo" + print(p.nome) + print(p.idade) + + From c562aab66134513822f1952f2b7e20a76899d27c Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Wed, 21 Feb 2018 11:19:04 -0300 Subject: [PATCH 04/49] Criados attr complexo - filhos --- oo/pessoa.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index ac8525d43..e9bda719a 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,20 +1,25 @@ class Pessoa: - def __init__(self, nome=None, idade=35): + def __init__(self, *filhos, nome=None, idade=35): self.idade = idade self.nome = nome + self.filhos = list(filhos) def cumprimentar(self): return f'Olá {id(self)}' if __name__ == '__main__': - p = Pessoa('Luciano') - print(Pessoa.cumprimentar(p)) - print(id(p)) - print(p.cumprimentar()) - print(p.nome) - p.nome = "Renzo" - print(p.nome) - print(p.idade) + renzo = Pessoa(nome='Renzo', idade=30) + luciano = Pessoa(renzo, nome='Luciano') + + print(Pessoa.cumprimentar(luciano)) + print(id(luciano)) + print(luciano.cumprimentar()) + print(luciano.nome) + print(luciano.idade) + # print(luciano.filhos) + for filho in luciano.filhos: + print(filho.nome) + print(filho.idade) From 437fd6b28afc45dc188a3bf18f7555a434323091 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 22 Feb 2018 14:53:52 -0300 Subject: [PATCH 05/49] =?UTF-8?q?Criado=20e=20removido=20attr=20din=C3=A2m?= =?UTF-8?q?ico=20de=20objs=20do=20tipo=20Pessoa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/pessoa.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index e9bda719a..168aa3b83 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -17,9 +17,13 @@ def cumprimentar(self): print(luciano.cumprimentar()) print(luciano.nome) print(luciano.idade) - # print(luciano.filhos) for filho in luciano.filhos: print(filho.nome) print(filho.idade) + luciano.sobrenome = 'Ramalho' + print(luciano.sobrenome) + del luciano.sobrenome + print(luciano.__dict__) + print(renzo.__dict___) From 7cdb515515f3ea92df31f6b004a1263ef9981062 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 22 Feb 2018 15:44:21 -0300 Subject: [PATCH 06/49] =?UTF-8?q?Fixed=20renzo.=5F=5Fdict=5F=5F,=20attr=20?= =?UTF-8?q?e=20m=C3=A9todos=20da=20instancia=20e=20da=20classe=20com=20com?= =?UTF-8?q?ent=C3=A1rios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/pessoa.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 168aa3b83..90ef49c0b 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,4 +1,8 @@ class Pessoa: + # da classe + olhos = 2 + + # da instancia def __init__(self, *filhos, nome=None, idade=35): self.idade = idade self.nome = nome @@ -7,6 +11,14 @@ def __init__(self, *filhos, nome=None, idade=35): def cumprimentar(self): return f'Olá {id(self)}' + @staticmethod + def metodo_estatico(): + return 42 + + @classmethod + def nome_e_attr_de_classe(cls): + return f'{cls} - olhos {cls.olhos}' + if __name__ == '__main__': renzo = Pessoa(nome='Renzo', idade=30) @@ -20,10 +32,21 @@ def cumprimentar(self): for filho in luciano.filhos: print(filho.nome) print(filho.idade) + # da instância luciano.sobrenome = 'Ramalho' print(luciano.sobrenome) del luciano.sobrenome + # __dict__ - da instância print(luciano.__dict__) - print(renzo.__dict___) + print(renzo.__dict__) + print(f'antes da mudança luciano.olhos - {luciano.olhos}') + # da classe - vai todas as instancias + Pessoa.olhos = 3 + print(Pessoa.olhos) + print(luciano.olhos) + print(renzo.olhos) + print(id(Pessoa.olhos), id(luciano.olhos), id(renzo.olhos)) + print(Pessoa.metodo_estatico(), luciano.metodo_estatico()) + print(Pessoa.nome_e_attr_de_classe(), luciano.nome_e_attr_de_classe()) From ea0d01621f5eee472487709ee17e642a2c5281f8 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 25 Feb 2018 15:12:38 -0300 Subject: [PATCH 07/49] Classe Carro, composta pelas classes Direcao e Motor. doctest --- oo/carro.py | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 oo/carro.py diff --git a/oo/carro.py b/oo/carro.py new file mode 100644 index 000000000..5ec812fb8 --- /dev/null +++ b/oo/carro.py @@ -0,0 +1,190 @@ +"""VocÊ deve criar uma classe carro que vai possuir +dois atributos compostos por outras duas classe: + +1) Motor +2) Direção + +O Motor trá a responsabilidade de controlar a velocidade. +Ele oferece os seguintes attributos: + +1) Attr de dado velocidade +2) Method acelear, que deverá incrementar a velocidade de + uma unidade +3) Method frear que deverá decrementar a velocidade em duas + unidades. + +A Direção terá a responsabilidede de controlar a direção. + Ela oferacerá os seguintes attrs: + +1) Valor da direção com valores possíveis: Norte, Sul, Leste + Oeste. +2) Método girar_a_direita +3) Método girar_a_esquerda + + N +O L + S + + Exemplo: + >>> # Testando Motor + >>> motor = Motor() + >>> motor.velocidade + 0 + >>> motor.acelerar() + >>> motor.velocidade + 1 + >>> motor.acelerar() + >>> motor.velocidade + 2 + >>> motor.acelerar() + >>> motor.velocidade + 3 + >>> motor.frear() + >>> motor.velocidade + 1 + >>> motor.frear() + >>> motor.velocidade + 0 + >>> # Testando Direcao + >>> direcao = Direcao() + >>> direcao.valor + 'Norte' + >>> direcao.girar_a_direita() + >>> direcao.valor + 'Leste' + >>> direcao.girar_a_direita() + >>> direcao.valor + 'Sul' + >>> direcao.girar_a_direita() + >>> direcao.valor + 'Oeste' + >>> direcao.girar_a_direita() + >>> direcao.valor + 'Norte' + >>> direcao.girar_a_esquerda() + >>> direcao.valor + 'Oeste' + >>> direcao.girar_a_esquerda() + >>> direcao.valor + 'Sul' + >>> direcao.girar_a_esquerda() + >>> direcao.valor + 'Leste' + >>> direcao.girar_a_esquerda() + >>> direcao.valor + 'Norte' + >>> + >>> carro = Carro(direcao, motor) + >>> carro.calcular_velocidade() + 0 + >>> carro.acelerar() + >>> carro.calcular_velocidade() + 1 + >>> carro.acelerar() + >>> carro.calcular_velocidade() + 2 + >>> carro.frear() + >>> carro.calcular_velocidade() + 0 + >>> carro.calcular_direcao() + 'Norte' + >>> carro.girar_a_direita() + >>> carro.calcular_direcao() + 'Leste' + >>> carro.girar_a_esquerda() + >>> carro.calcular_direcao() + 'Norte' + >>> carro.girar_a_esquerda() + >>> carro.calcular_direcao() + 'Oeste' +""" + + +class Motor: + def __init__(self): + self.velocidade = 0 + + def acelerar(self): + self.velocidade += 1 + + def frear(self): + self.velocidade -= 2 + self.velocidade = max(0, self.velocidade) + # if self.velocidade > 2: + # self.velocidade -= 2 + # else: + # self.velocidade = 0 + +NORTE = 'Norte' +SUL = 'Sul' +LESTE = 'Leste' +OESTE = 'Oeste' + + +class Direcao: + rotacao_a_direita = { + NORTE: LESTE, + LESTE: SUL, + SUL: OESTE, + OESTE: NORTE + } + rotacao_a_esquerda = { + NORTE: OESTE, + OESTE: SUL, + SUL: LESTE, + LESTE:NORTE + } + + def __init__(self): + # self.direcao_valores = ['Norte', 'Leste', 'Sul', 'Oeste'] + # self.valor = 'Norte' + self.valor = NORTE + + def girar_a_direita(self): + # direcao_atual = self.direcao_valores.index(self.valor) + # if self.valor == 'Oeste': + # direcao_atual = 0 + # else: + # direcao_atual += 1 + # + # self.valor = self.direcao_valores[direcao_atual] + self.valor = self.rotacao_a_direita[self.valor] + + def girar_a_esquerda(self): + # direcao_atual = self.direcao_valores.index(self.valor) + # if self.valor == 'Norte': + # direcao_atual = 3 + # else: + # direcao_atual -= 1 + # + # self.valor = self.direcao_valores[direcao_atual] + self.valor = self.rotacao_a_esquerda[self.valor] + + +class Carro: + def __init__(self, direcao, motor): + self.direcao = direcao + self.motor = motor + + def calcular_velocidade(self): + return self.motor.velocidade + + def acelerar(self): + self.motor.acelerar() + + def frear(self): + self.motor.frear() + + def calcular_direcao(self): + return self.direcao.valor + + def girar_a_direita(self): + self.direcao.girar_a_direita() + + def girar_a_esquerda(self): + self.direcao.girar_a_esquerda() + + +if __name__ == '__main__': + import doctest + doctest.testmod() \ No newline at end of file From 2c4c7bd091d4a7761fe7a2995632e210a6934735 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 25 Feb 2018 15:47:26 -0300 Subject: [PATCH 08/49] extend _obstaculos, _porcos e _passaros --- fase.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fase.py b/fase.py index 3385175c6..1c8fd161f 100644 --- a/fase.py +++ b/fase.py @@ -43,7 +43,7 @@ def adicionar_obstaculo(self, *obstaculos): :param obstaculos: """ - pass + self._obstaculos.extend(obstaculos) def adicionar_porco(self, *porcos): """ @@ -51,7 +51,7 @@ def adicionar_porco(self, *porcos): :param porcos: """ - pass + self._porcos.extend(porcos) def adicionar_passaro(self, *passaros): """ @@ -59,7 +59,7 @@ def adicionar_passaro(self, *passaros): :param passaros: """ - pass + self._passaros.extend(passaros) def status(self): """ From d3d2accbc56ce6b523dc5887f9cc9b7e908f78f0 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 25 Feb 2018 16:20:03 -0300 Subject: [PATCH 09/49] =?UTF-8?q?Primeira=20heran=C3=A7a=20-=20class=20Hom?= =?UTF-8?q?em(Pessoa):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/pessoa.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 90ef49c0b..76b575b05 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -20,8 +20,12 @@ def nome_e_attr_de_classe(cls): return f'{cls} - olhos {cls.olhos}' +class Homem(Pessoa): + pass + + if __name__ == '__main__': - renzo = Pessoa(nome='Renzo', idade=30) + renzo = Homem(nome='Renzo', idade=30) luciano = Pessoa(renzo, nome='Luciano') print(Pessoa.cumprimentar(luciano)) @@ -48,5 +52,9 @@ def nome_e_attr_de_classe(cls): print(id(Pessoa.olhos), id(luciano.olhos), id(renzo.olhos)) print(Pessoa.metodo_estatico(), luciano.metodo_estatico()) print(Pessoa.nome_e_attr_de_classe(), luciano.nome_e_attr_de_classe()) + print(isinstance(luciano, Pessoa)) + print(isinstance(luciano, Homem)) + print(isinstance(renzo, Pessoa)) + print(isinstance(renzo, Homem)) From 9378cf516f763974eb56c4b490dd3791565b217c Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Mon, 26 Feb 2018 17:47:26 -0300 Subject: [PATCH 10/49] Testes para a classe Motor. Vel inicial e acelerar --- oo/test_carro.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 oo/test_carro.py diff --git a/oo/test_carro.py b/oo/test_carro.py new file mode 100644 index 000000000..4279546f3 --- /dev/null +++ b/oo/test_carro.py @@ -0,0 +1,14 @@ +from unittest import TestCase +from oo.carro import Motor + + +class CarroTestCase(TestCase): + def test_velocidade_inicial(self): + motor = Motor() + self.assertEqual(0, motor.velocidade) + + def test_acelerar(self): + motor = Motor() + motor.acelerar() + self.assertEqual(1, motor.velocidade) + From 68d4829dad123a96a47e24bed687ebde72107c0c Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 1 Mar 2018 13:03:38 -0300 Subject: [PATCH 11/49] Testes para a classe Motor completo. --- oo/test_carro.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/oo/test_carro.py b/oo/test_carro.py index 4279546f3..40888c35d 100644 --- a/oo/test_carro.py +++ b/oo/test_carro.py @@ -12,3 +12,9 @@ def test_acelerar(self): motor.acelerar() self.assertEqual(1, motor.velocidade) + def test_frear(self): + motor = Motor() + motor.acelerar() + motor.frear() + self.assertEqual(0, motor.velocidade) + From b40f49a03bbedc0e94c7ebdd915eeec100f13e32 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 1 Mar 2018 13:32:17 -0300 Subject: [PATCH 12/49] Testes para a classe Direcao completo. --- oo/test_carro.py | 55 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/oo/test_carro.py b/oo/test_carro.py index 40888c35d..bbe0e911a 100644 --- a/oo/test_carro.py +++ b/oo/test_carro.py @@ -1,20 +1,55 @@ from unittest import TestCase -from oo.carro import Motor +from oo.carro import Motor, Direcao, Carro class CarroTestCase(TestCase): + def setUp(self): + self.motor = Motor() + self.direcao = Direcao() + def test_velocidade_inicial(self): - motor = Motor() - self.assertEqual(0, motor.velocidade) + self.assertEqual(0, self.motor.velocidade) def test_acelerar(self): - motor = Motor() - motor.acelerar() - self.assertEqual(1, motor.velocidade) + self.motor.acelerar() + self.assertEqual(1, self.motor.velocidade) def test_frear(self): - motor = Motor() - motor.acelerar() - motor.frear() - self.assertEqual(0, motor.velocidade) + self.motor.acelerar() + self.motor.frear() + self.assertEqual(0, self.motor.velocidade) + + def test_direcao_inicial(self): + self.assertEqual('Norte', self.direcao.valor) + + def test_direcao_direita(self): + rumo = list(self.direcao.rotacao_a_direita.values()) + + with self.subTest(): + for i in rumo: + self.direcao.girar_a_direita() + self.assertEqual(i, self.direcao.valor) + + def test_direcao_esquerda(self): + rumo = list(self.direcao.rotacao_a_esquerda.values()) + + with self.subTest(): + for i in rumo: + self.direcao.girar_a_esquerda() + self.assertEqual(i, self.direcao.valor) + + + + + + + + + + + + + + + From 2d1ea1a6263b755d3dbc2e06c28de4348f983e30 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 1 Mar 2018 19:02:36 -0300 Subject: [PATCH 13/49] Refactor rename --- testes/{integracao.py => test_integracao.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename testes/{integracao.py => test_integracao.py} (100%) diff --git a/testes/integracao.py b/testes/test_integracao.py similarity index 100% rename from testes/integracao.py rename to testes/test_integracao.py From 93169403799679a60c23290becf328cf43b8248b Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 1 Mar 2018 19:03:19 -0300 Subject: [PATCH 14/49] Status em_andamento, vitoria e derrota --- fase.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fase.py b/fase.py index 1c8fd161f..6239f194e 100644 --- a/fase.py +++ b/fase.py @@ -73,7 +73,16 @@ def status(self): :return: """ - return EM_ANDAMENTO + + for passaro, porco in zip(self._passaros, self._porcos): + if porco.status == ATIVO and passaro.status == ATIVO: + return EM_ANDAMENTO + + for passaro, porco in zip(self._passaros, self._porcos): + if porco.status == ATIVO and passaro.status != ATIVO: + return DERROTA + + return VITORIA def lancar(self, angulo, tempo): """ From 0ed287fdaf2443839732c1137272dcab4722ab81 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 1 Mar 2018 19:03:44 -0300 Subject: [PATCH 15/49] Refactor rename --- testes/{fase_testes.py => test_fase.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename testes/{fase_testes.py => test_fase.py} (100%) diff --git a/testes/fase_testes.py b/testes/test_fase.py similarity index 100% rename from testes/fase_testes.py rename to testes/test_fase.py From 80b610cbb25a1a4aef25f1e6250e4e44a062b208 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Fri, 2 Mar 2018 08:49:51 -0300 Subject: [PATCH 16/49] test_atores.AtorTestes - all 8 OK. --- atores.py | 24 +++++++++++++++++---- testes/{atores_testes.py => test_atores.py} | 8 +++++++ 2 files changed, 28 insertions(+), 4 deletions(-) rename testes/{atores_testes.py => test_atores.py} (99%) diff --git a/atores.py b/atores.py index cfc2ef5ea..e63440c9e 100644 --- a/atores.py +++ b/atores.py @@ -38,7 +38,9 @@ def calcular_posicao(self, tempo): :param tempo: o tempo do jogo :return: posição x, y do ator """ - return 1, 1 + if tempo == 0: + return 0, 0 + return self.x * (tempo/10), self.y * (tempo/10) def colidir(self, outro_ator, intervalo=1): """ @@ -52,8 +54,18 @@ def colidir(self, outro_ator, intervalo=1): :param intervalo: Intervalo a ser considerado :return: """ - pass + lado = intervalo * 2 + d = ((outro_ator.x - self.x) ** 2) + ((outro_ator.y - self.y) ** 2) + d = math.sqrt(d) + + if self.status == ATIVO and outro_ator.status == ATIVO: + if self.x == outro_ator.x and self.y == outro_ator.y: + self.status = DESTRUIDO + outro_ator.status = DESTRUIDO + elif d < lado: + self.status = DESTRUIDO + outro_ator.status = DESTRUIDO class Obstaculo(Ator): @@ -101,7 +113,8 @@ def colidir_com_chao(self): o status dos Passaro deve ser alterado para destruido, bem como o seu caracter """ - pass + if self.y <= 0: + self.status = DESTRUIDO def calcular_posicao(self, tempo): """ @@ -129,7 +142,10 @@ def lancar(self, angulo, tempo_de_lancamento): :param tempo_de_lancamento: :return: """ - pass + + self._tempo_de_lancamento = tempo_de_lancamento + self._angulo_de_lancamento = math.radians(angulo) # radianos + class PassaroAmarelo(Passaro): diff --git a/testes/atores_testes.py b/testes/test_atores.py similarity index 99% rename from testes/atores_testes.py rename to testes/test_atores.py index f4254f29e..491716985 100644 --- a/testes/atores_testes.py +++ b/testes/test_atores.py @@ -148,6 +148,8 @@ class ObstaculoTestes(TestCase): """ def teste_status(self): obstaculo = Obstaculo() + obstaculo._caracter_ativo = 'O' + obstaculo._caracter_destruido = ' ' self.assertEqual('O', obstaculo.caracter()) outro_ator_na_mesma_posicao = Ator() obstaculo.colidir(outro_ator_na_mesma_posicao) @@ -160,6 +162,8 @@ class PorcoTestes(TestCase): """ def teste_status(self): porco = Porco() + porco._caracter_ativo = '@' + porco._caracter_destruido = '+' self.assertEqual('@', porco.caracter()) outro_ator_na_mesma_posicao = Ator() porco.colidir(outro_ator_na_mesma_posicao) @@ -197,6 +201,8 @@ class PassaroVermelhoTests(PassaroBaseTests): def teste_status(self): passaro_vermelho = PassaroVermelho(1, 1) + passaro_vermelho._caracter_ativo = 'V' + passaro_vermelho._caracter_destruido = 'v' self.assertEqual('V', passaro_vermelho.caracter()) outro_ator_na_mesma_posicao = Ator() passaro_vermelho.colidir(outro_ator_na_mesma_posicao) @@ -249,6 +255,8 @@ class PassaroAmareloTests(PassaroBaseTests): def teste_status(self): passaro_amarelo = PassaroAmarelo(1, 1) + passaro_amarelo._caracter_ativo = 'A' + passaro_amarelo._caracter_destruido = 'a' self.assertEqual('A', passaro_amarelo.caracter()) outro_ator_na_mesma_posicao = Ator() passaro_amarelo.colidir(outro_ator_na_mesma_posicao) From 35d96e65e7fff6c25b58c299ab9a12c1bae4642d Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Fri, 2 Mar 2018 08:59:43 -0300 Subject: [PATCH 17/49] Refatorando colidir() --- atores.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/atores.py b/atores.py index e63440c9e..eff90d19a 100644 --- a/atores.py +++ b/atores.py @@ -54,18 +54,17 @@ def colidir(self, outro_ator, intervalo=1): :param intervalo: Intervalo a ser considerado :return: """ - lado = intervalo * 2 - d = ((outro_ator.x - self.x) ** 2) + ((outro_ator.y - self.y) ** 2) - d = math.sqrt(d) - if self.status == ATIVO and outro_ator.status == ATIVO: if self.x == outro_ator.x and self.y == outro_ator.y: - self.status = DESTRUIDO - outro_ator.status = DESTRUIDO - - elif d < lado: self.status = DESTRUIDO outro_ator.status = DESTRUIDO + else: + lado = intervalo * 2 + d = ((outro_ator.x - self.x) ** 2) + ((outro_ator.y - self.y) ** 2) + d = math.sqrt(d) + if d < lado: + self.status = DESTRUIDO + outro_ator.status = DESTRUIDO class Obstaculo(Ator): From 95098c6b3dac87a398df1fe0c241108aa1c6ae15 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Fri, 2 Mar 2018 09:02:15 -0300 Subject: [PATCH 18/49] Renomeando lado -> limite --- atores.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atores.py b/atores.py index eff90d19a..ffba06516 100644 --- a/atores.py +++ b/atores.py @@ -59,10 +59,10 @@ def colidir(self, outro_ator, intervalo=1): self.status = DESTRUIDO outro_ator.status = DESTRUIDO else: - lado = intervalo * 2 + limite = intervalo * 2 d = ((outro_ator.x - self.x) ** 2) + ((outro_ator.y - self.y) ** 2) d = math.sqrt(d) - if d < lado: + if d < limite: self.status = DESTRUIDO outro_ator.status = DESTRUIDO From 2be685c2642b2ff8043377191212f12d3b75f459 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Fri, 2 Mar 2018 17:05:56 -0300 Subject: [PATCH 19/49] =?UTF-8?q?Coment=C3=A1rios=20sobre=20solu=C3=A7?= =?UTF-8?q?=C3=A3o=20para=20calcular=5Fposicao()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/atores.py b/atores.py index ffba06516..e71f0d8af 100644 --- a/atores.py +++ b/atores.py @@ -129,6 +129,21 @@ def calcular_posicao(self, tempo): :param tempo: tempo de jogo a ser calculada a posição :return: posição x, y """ + if not self._tempo_de_lancamento and not self._angulo_de_lancamento: + return self._x_inicial, self._y_inicial + + # componente vertical -> y + # componente horizontal -> x + # self.velocidade_escalar + # self._angulo_de_lancamento math.cos() horziontal, math.sin() altura max, vertical + # GRAVIDADE + # tempo + # + # alcance_horizontal = velocidade * math.cos(angulo) * tempo # x é por aí? + # altura_max = velocidade * math.sin(Angulo) * GRAVIDADE # y é por aí? + + if self.status == DESTRUIDO: + return ultima posicao calculada return 1, 1 From 6c88b3bf61f09fa2a8c94264092cb66c7289abce Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Fri, 2 Mar 2018 17:06:58 -0300 Subject: [PATCH 20/49] =?UTF-8?q?Coment=C3=A1rios=20sobre=20solu=C3=A7?= =?UTF-8?q?=C3=A3o=20para=20calcular=5Fposicao()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/atores.py b/atores.py index e71f0d8af..7aab926b6 100644 --- a/atores.py +++ b/atores.py @@ -142,8 +142,9 @@ def calcular_posicao(self, tempo): # alcance_horizontal = velocidade * math.cos(angulo) * tempo # x é por aí? # altura_max = velocidade * math.sin(Angulo) * GRAVIDADE # y é por aí? - if self.status == DESTRUIDO: - return ultima posicao calculada + #if self.status == DESTRUIDO: + # return ultima posicao calculada + return 1, 1 From 50a847bfc60d728f994664a5c228f43b487edf01 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sat, 3 Mar 2018 18:11:57 -0300 Subject: [PATCH 21/49] calcular_posicao() - parece que self.x esta certo --- atores.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/atores.py b/atores.py index 7aab926b6..a4fef2b95 100644 --- a/atores.py +++ b/atores.py @@ -80,7 +80,7 @@ class DuploLancamentoExcecao(Exception): class Passaro(Ator): - velocidade_escalar = 10 + velocidade_escalar = 30 def __init__(self, x=0, y=0): """ @@ -104,6 +104,9 @@ def foi_lancado(self): :return: booleano """ + if self._tempo_de_lancamento is None and self._angulo_de_lancamento is None: + return False + return True def colidir_com_chao(self): @@ -129,24 +132,27 @@ def calcular_posicao(self, tempo): :param tempo: tempo de jogo a ser calculada a posição :return: posição x, y """ - if not self._tempo_de_lancamento and not self._angulo_de_lancamento: + if not self.foi_lancado(): + print('nao lancado') return self._x_inicial, self._y_inicial + if self.status == DESTRUIDO: + print('destruido') + return self.x, self.y + # componente vertical -> y # componente horizontal -> x - # self.velocidade_escalar - # self._angulo_de_lancamento math.cos() horziontal, math.sin() altura max, vertical - # GRAVIDADE - # tempo - # - # alcance_horizontal = velocidade * math.cos(angulo) * tempo # x é por aí? - # altura_max = velocidade * math.sin(Angulo) * GRAVIDADE # y é por aí? - #if self.status == DESTRUIDO: - # return ultima posicao calculada + tempo = tempo / 10 - return 1, 1 + # alcance_horizontal + d = math.cos(self._angulo_de_lancamento) * tempo + self.x += d + # vertical considerando subida + self.y = (self.velocidade_escalar * tempo) - (0.5 * GRAVIDADE * (tempo ** 2)) + + return self.x, self.y def lancar(self, angulo, tempo_de_lancamento): """ @@ -162,7 +168,6 @@ def lancar(self, angulo, tempo_de_lancamento): self._angulo_de_lancamento = math.radians(angulo) # radianos - class PassaroAmarelo(Passaro): pass From 6ca79080d557b380bcbb956ca75f2b255ef7b431 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 11:46:36 -0300 Subject: [PATCH 22/49] =?UTF-8?q?Passaro=20amarelo=20-=204=20testes=20OK?= =?UTF-8?q?=20-=20uma=20bagun=C3=A7a=20at=C3=A9=20agora.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/atores.py b/atores.py index a4fef2b95..9b5531496 100644 --- a/atores.py +++ b/atores.py @@ -143,14 +143,15 @@ def calcular_posicao(self, tempo): # componente vertical -> y # componente horizontal -> x - tempo = tempo / 10 + tempo = tempo - self._tempo_de_lancamento # alcance_horizontal - d = math.cos(self._angulo_de_lancamento) * tempo - self.x += d + self.x = self._x_inicial + math.cos(self._angulo_de_lancamento) * tempo * self.velocidade_escalar # vertical considerando subida - self.y = (self.velocidade_escalar * tempo) - (0.5 * GRAVIDADE * (tempo ** 2)) + self.y = (self._y_inicial + + self.velocidade_escalar * tempo * math.sin(self._angulo_de_lancamento) - + 0.5 * GRAVIDADE * tempo ** 2) return self.x, self.y From 797f90f43143cb0934bb4322a38f18c667c493d9 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 11:47:59 -0300 Subject: [PATCH 23/49] Passaro vermelho - velocidade escalar OK --- atores.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atores.py b/atores.py index 9b5531496..4d00fbb31 100644 --- a/atores.py +++ b/atores.py @@ -174,4 +174,4 @@ class PassaroAmarelo(Passaro): class PassaroVermelho(Passaro): - pass \ No newline at end of file + velocidade_escalar = 20 \ No newline at end of file From d608f9ff4fca65ae7bd8df49ed27819ea2287091 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 14:16:07 -0300 Subject: [PATCH 24/49] =?UTF-8?q?atributo=20de=20classe=20na=20classe=20Ob?= =?UTF-8?q?staculo=20n=C3=A3o=20no=20teste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 3 ++- testes/test_atores.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/atores.py b/atores.py index 4d00fbb31..01ebd9ab3 100644 --- a/atores.py +++ b/atores.py @@ -68,7 +68,8 @@ def colidir(self, outro_ator, intervalo=1): class Obstaculo(Ator): - pass + _caracter_ativo = 'O' + _caracter_destruido = ' ' class Porco(Ator): diff --git a/testes/test_atores.py b/testes/test_atores.py index 491716985..471e016c2 100644 --- a/testes/test_atores.py +++ b/testes/test_atores.py @@ -148,8 +148,8 @@ class ObstaculoTestes(TestCase): """ def teste_status(self): obstaculo = Obstaculo() - obstaculo._caracter_ativo = 'O' - obstaculo._caracter_destruido = ' ' + #obstaculo._caracter_ativo = 'O' + #obstaculo._caracter_destruido = ' ' self.assertEqual('O', obstaculo.caracter()) outro_ator_na_mesma_posicao = Ator() obstaculo.colidir(outro_ator_na_mesma_posicao) From e444213644c5730a96f6f4522474589a1c60d0a5 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 14:17:29 -0300 Subject: [PATCH 25/49] =?UTF-8?q?atributo=20de=20classe=20na=20classe=20Po?= =?UTF-8?q?rco=20n=C3=A3o=20no=20teste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 3 ++- testes/test_atores.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/atores.py b/atores.py index 01ebd9ab3..f6b44ba02 100644 --- a/atores.py +++ b/atores.py @@ -73,7 +73,8 @@ class Obstaculo(Ator): class Porco(Ator): - pass + _caracter_ativo = '@' + _caracter_destruido = '+' class DuploLancamentoExcecao(Exception): diff --git a/testes/test_atores.py b/testes/test_atores.py index 471e016c2..f4fd73b1f 100644 --- a/testes/test_atores.py +++ b/testes/test_atores.py @@ -162,8 +162,8 @@ class PorcoTestes(TestCase): """ def teste_status(self): porco = Porco() - porco._caracter_ativo = '@' - porco._caracter_destruido = '+' + # porco._caracter_ativo = '@' + # porco._caracter_destruido = '+' self.assertEqual('@', porco.caracter()) outro_ator_na_mesma_posicao = Ator() porco.colidir(outro_ator_na_mesma_posicao) From d1ca9bdad0e5da4f330f58e024855828d67f26b2 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 14:20:08 -0300 Subject: [PATCH 26/49] =?UTF-8?q?atributo=20de=20classe=20na=20classe=20Pa?= =?UTF-8?q?ssaroAmarelo=20n=C3=A3o=20no=20teste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 3 +++ testes/test_atores.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/atores.py b/atores.py index f6b44ba02..d90e9e1c8 100644 --- a/atores.py +++ b/atores.py @@ -172,6 +172,9 @@ def lancar(self, angulo, tempo_de_lancamento): class PassaroAmarelo(Passaro): + _caracter_ativo = 'A' + _caracter_destruido = 'a' + pass diff --git a/testes/test_atores.py b/testes/test_atores.py index f4fd73b1f..1b1ecd348 100644 --- a/testes/test_atores.py +++ b/testes/test_atores.py @@ -255,8 +255,8 @@ class PassaroAmareloTests(PassaroBaseTests): def teste_status(self): passaro_amarelo = PassaroAmarelo(1, 1) - passaro_amarelo._caracter_ativo = 'A' - passaro_amarelo._caracter_destruido = 'a' + # passaro_amarelo._caracter_ativo = 'A' + # passaro_amarelo._caracter_destruido = 'a' self.assertEqual('A', passaro_amarelo.caracter()) outro_ator_na_mesma_posicao = Ator() passaro_amarelo.colidir(outro_ator_na_mesma_posicao) From 605b3df32ffa652b2e191ee0e0346826a8117e2a Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 14:21:46 -0300 Subject: [PATCH 27/49] =?UTF-8?q?atributo=20de=20classe=20na=20classe=20Pa?= =?UTF-8?q?ssaroVermelho=20n=C3=A3o=20no=20teste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 2 ++ testes/test_atores.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/atores.py b/atores.py index d90e9e1c8..a3cba07cf 100644 --- a/atores.py +++ b/atores.py @@ -179,4 +179,6 @@ class PassaroAmarelo(Passaro): class PassaroVermelho(Passaro): + _caracter_ativo = 'V' + _caracter_destruido = 'v' velocidade_escalar = 20 \ No newline at end of file diff --git a/testes/test_atores.py b/testes/test_atores.py index 1b1ecd348..c682de0c3 100644 --- a/testes/test_atores.py +++ b/testes/test_atores.py @@ -201,8 +201,8 @@ class PassaroVermelhoTests(PassaroBaseTests): def teste_status(self): passaro_vermelho = PassaroVermelho(1, 1) - passaro_vermelho._caracter_ativo = 'V' - passaro_vermelho._caracter_destruido = 'v' + # passaro_vermelho._caracter_ativo = 'V' + # passaro_vermelho._caracter_destruido = 'v' self.assertEqual('V', passaro_vermelho.caracter()) outro_ator_na_mesma_posicao = Ator() passaro_vermelho.colidir(outro_ator_na_mesma_posicao) From be29cb27c5f535baf8142d579c424e741df11726 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 14:38:04 -0300 Subject: [PATCH 28/49] =?UTF-8?q?Posi=C3=A7=C3=A3o=20do=20ator=20deve=20pe?= =?UTF-8?q?rmanecer=20inalterada.=20O=20tempo=20n=C3=A3o=20influi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/atores.py b/atores.py index a3cba07cf..665215a9a 100644 --- a/atores.py +++ b/atores.py @@ -40,7 +40,8 @@ def calcular_posicao(self, tempo): """ if tempo == 0: return 0, 0 - return self.x * (tempo/10), self.y * (tempo/10) + + return self.x, self.y # tempo/10, tempo/10 def colidir(self, outro_ator, intervalo=1): """ From 90278d788089dc3c7f000a1f709953b2592eb9f7 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 14:38:57 -0300 Subject: [PATCH 29/49] =?UTF-8?q?Posi=C3=A7=C3=A3o=20do=20ator=20deve=20pe?= =?UTF-8?q?rmanecer=20inalterada.=20O=20tempo=20n=C3=A3o=20influi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atores.py b/atores.py index 665215a9a..a9816b712 100644 --- a/atores.py +++ b/atores.py @@ -38,8 +38,8 @@ def calcular_posicao(self, tempo): :param tempo: o tempo do jogo :return: posição x, y do ator """ - if tempo == 0: - return 0, 0 + #if tempo == 0: + # return 0, 0 return self.x, self.y # tempo/10, tempo/10 From f6be4dd591f15b35dc705ae8c5daff52f244d62d Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 14:55:17 -0300 Subject: [PATCH 30/49] =?UTF-8?q?M=C3=A9todo=20colidir=20dividido.=20Mais?= =?UTF-8?q?=202=20m=C3=A9todos.=20=5Fmesma=5Fposicao=20e=20=5Fintersecao?= =?UTF-8?q?=5Fde=5Fatores?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/atores.py b/atores.py index a9816b712..70ad54f37 100644 --- a/atores.py +++ b/atores.py @@ -43,6 +43,15 @@ def calcular_posicao(self, tempo): return self.x, self.y # tempo/10, tempo/10 + def _mesma_posicao(self, outro_ator): + return self.x == outro_ator.x and self.y == outro_ator.y + + def _intersecao_de_atores(self, outro_ator, intervalo): + limite = intervalo * 2 + d = ((outro_ator.x - self.x) ** 2) + ((outro_ator.y - self.y) ** 2) + d = math.sqrt(d) + return d < limite + def colidir(self, outro_ator, intervalo=1): """ Método que executa lógica de colisão entre dois atores. @@ -56,16 +65,9 @@ def colidir(self, outro_ator, intervalo=1): :return: """ if self.status == ATIVO and outro_ator.status == ATIVO: - if self.x == outro_ator.x and self.y == outro_ator.y: + if self._mesma_posicao(outro_ator) or self._intersecao_de_atores(outro_ator, intervalo): self.status = DESTRUIDO outro_ator.status = DESTRUIDO - else: - limite = intervalo * 2 - d = ((outro_ator.x - self.x) ** 2) + ((outro_ator.y - self.y) ** 2) - d = math.sqrt(d) - if d < limite: - self.status = DESTRUIDO - outro_ator.status = DESTRUIDO class Obstaculo(Ator): From 4b59c611ca61e69a4fe673429ee1af58a51c7872 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 14:58:36 -0300 Subject: [PATCH 31/49] =?UTF-8?q?Se=20n=C3=A3o=20foi=20lan=C3=A7ado,=20val?= =?UTF-8?q?ores=20iniciais=20para=20a=20posi=C3=A7=C3=A3o;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/atores.py b/atores.py index 70ad54f37..4d0e653a2 100644 --- a/atores.py +++ b/atores.py @@ -138,8 +138,10 @@ def calcular_posicao(self, tempo): :return: posição x, y """ if not self.foi_lancado(): - print('nao lancado') - return self._x_inicial, self._y_inicial + # print('nao lancado') + self.x = self._x_inicial + self.y = self._y_inicial + # return self._x_inicial, self._y_inicial if self.status == DESTRUIDO: print('destruido') From aa6821aaffbdd83159bf094ec085bd2d7091fb13 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 15:00:43 -0300 Subject: [PATCH 32/49] =?UTF-8?q?Se=20status=20=C3=A9=20ATIVO,=20calcular?= =?UTF-8?q?=20posi=C3=A7=C3=A3o;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/atores.py b/atores.py index 4d0e653a2..48adfd9f9 100644 --- a/atores.py +++ b/atores.py @@ -143,23 +143,22 @@ def calcular_posicao(self, tempo): self.y = self._y_inicial # return self._x_inicial, self._y_inicial - if self.status == DESTRUIDO: - print('destruido') - return self.x, self.y + #if self.status == DESTRUIDO: + # print('destruido') + # return self.x, self.y # componente vertical -> y # componente horizontal -> x - tempo = tempo - self._tempo_de_lancamento - - # alcance_horizontal - self.x = self._x_inicial + math.cos(self._angulo_de_lancamento) * tempo * self.velocidade_escalar - - # vertical considerando subida - self.y = (self._y_inicial + - self.velocidade_escalar * tempo * math.sin(self._angulo_de_lancamento) - - 0.5 * GRAVIDADE * tempo ** 2) + if self.status == ATIVO: + tempo = tempo - self._tempo_de_lancamento + # alcance_horizontal + self.x = self._x_inicial + math.cos(self._angulo_de_lancamento) * tempo * self.velocidade_escalar + # vertical considerando subida + self.y = (self._y_inicial + + self.velocidade_escalar * tempo * math.sin(self._angulo_de_lancamento) - + 0.5 * GRAVIDADE * tempo ** 2) return self.x, self.y def lancar(self, angulo, tempo_de_lancamento): From 8214e64e8e8fe2400c61cf3423f02304469f7e71 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 15:02:27 -0300 Subject: [PATCH 33/49] =?UTF-8?q?Se=20checar=20status,=20n=C3=A3o=20precis?= =?UTF-8?q?a=20checar=20se=20foi=20lan=C3=A7ado.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/atores.py b/atores.py index 48adfd9f9..b94cb997b 100644 --- a/atores.py +++ b/atores.py @@ -137,10 +137,10 @@ def calcular_posicao(self, tempo): :param tempo: tempo de jogo a ser calculada a posição :return: posição x, y """ - if not self.foi_lancado(): - # print('nao lancado') - self.x = self._x_inicial - self.y = self._y_inicial + #if not self.foi_lancado(): + # # print('nao lancado') + # self.x = self._x_inicial + # self.y = self._y_inicial # return self._x_inicial, self._y_inicial #if self.status == DESTRUIDO: From cee5d233ed03053a3cc8cf90ad4289c9436a0a03 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 15:12:01 -0300 Subject: [PATCH 34/49] =?UTF-8?q?M=C3=A9todo=20calcular=5Fposicao=20refato?= =?UTF-8?q?rado.=20Passa=20testes=5Fatores?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/atores.py b/atores.py index b94cb997b..43eb5562b 100644 --- a/atores.py +++ b/atores.py @@ -123,6 +123,15 @@ def colidir_com_chao(self): if self.y <= 0: self.status = DESTRUIDO + def _posicao_de_x(self, tempo): + return self._x_inicial + math.cos(self._angulo_de_lancamento) * tempo * self.velocidade_escalar + + def _posicao_de_y(self, tempo): + """ considerando subida """ + return (self._y_inicial + + self.velocidade_escalar * tempo * math.sin(self._angulo_de_lancamento) - + 0.5 * GRAVIDADE * tempo ** 2) + def calcular_posicao(self, tempo): """ Método que cálcula a posição do passaro de acordo com o tempo. @@ -137,28 +146,13 @@ def calcular_posicao(self, tempo): :param tempo: tempo de jogo a ser calculada a posição :return: posição x, y """ - #if not self.foi_lancado(): - # # print('nao lancado') - # self.x = self._x_inicial - # self.y = self._y_inicial - # return self._x_inicial, self._y_inicial - - #if self.status == DESTRUIDO: - # print('destruido') - # return self.x, self.y - - # componente vertical -> y - # componente horizontal -> x - if self.status == ATIVO: tempo = tempo - self._tempo_de_lancamento + # lançamento horizontal + self.x = self._posicao_de_x(tempo) + # lançamento vertical + self.y = self._posicao_de_y(tempo) - # alcance_horizontal - self.x = self._x_inicial + math.cos(self._angulo_de_lancamento) * tempo * self.velocidade_escalar - # vertical considerando subida - self.y = (self._y_inicial + - self.velocidade_escalar * tempo * math.sin(self._angulo_de_lancamento) - - 0.5 * GRAVIDADE * tempo ** 2) return self.x, self.y def lancar(self, angulo, tempo_de_lancamento): From 78978a75645a41c23c5f399fff248a6464815172 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 15:15:13 -0300 Subject: [PATCH 35/49] =?UTF-8?q?M=C3=A9todo=20posicao=20de=20x=20-=20form?= =?UTF-8?q?ata=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/atores.py b/atores.py index 43eb5562b..519bf8494 100644 --- a/atores.py +++ b/atores.py @@ -124,7 +124,8 @@ def colidir_com_chao(self): self.status = DESTRUIDO def _posicao_de_x(self, tempo): - return self._x_inicial + math.cos(self._angulo_de_lancamento) * tempo * self.velocidade_escalar + return (self._x_inicial + + math.cos(self._angulo_de_lancamento) * tempo * self.velocidade_escalar) def _posicao_de_y(self, tempo): """ considerando subida """ From 67148466fa3b3c78f339ab591c1f0ce849939e34 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 17:28:56 -0300 Subject: [PATCH 36/49] =?UTF-8?q?M=C3=A9todos=20em=20produ=C3=A7=C3=A3o.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fase.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fase.py b/fase.py index 6239f194e..3aad2d3fd 100644 --- a/fase.py +++ b/fase.py @@ -36,7 +36,6 @@ def __init__(self, intervalo_de_colisao=1): self._porcos = [] self._obstaculos = [] - def adicionar_obstaculo(self, *obstaculos): """ Adiciona obstáculos em uma fase @@ -51,6 +50,9 @@ def adicionar_porco(self, *porcos): :param porcos: """ + for i in porcos: + i.intervalo_colisao = self.intervalo_de_colisao + self._porcos.extend(porcos) def adicionar_passaro(self, *passaros): @@ -59,6 +61,9 @@ def adicionar_passaro(self, *passaros): :param passaros: """ + for i in passaros: + i.intervalo_colisao = self.intervalo_de_colisao + self._passaros.extend(passaros) def status(self): @@ -78,8 +83,8 @@ def status(self): if porco.status == ATIVO and passaro.status == ATIVO: return EM_ANDAMENTO - for passaro, porco in zip(self._passaros, self._porcos): - if porco.status == ATIVO and passaro.status != ATIVO: + for porco in self._porcos: + if porco.status == ATIVO: return DERROTA return VITORIA @@ -95,8 +100,9 @@ def lancar(self, angulo, tempo): :param angulo: ângulo de lançamento :param tempo: Tempo de lançamento """ - pass - + for i in self._passaros: + if not i.foi_lancado(): + i.lancar(angulo, tempo) def calcular_pontos(self, tempo): """ From a09542e973d8d38125d324efc3455124395dcb81 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Sun, 4 Mar 2018 17:36:58 -0300 Subject: [PATCH 37/49] =?UTF-8?q?Lan=C3=A7a=20apenas=20o=20primeiro=20da?= =?UTF-8?q?=20lista=20que=20satisfaz=20a=20condicao=20de=20n=C3=A3o=20lan?= =?UTF-8?q?=C3=A7ado.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fase.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fase.py b/fase.py index 3aad2d3fd..ea896b7c4 100644 --- a/fase.py +++ b/fase.py @@ -103,6 +103,7 @@ def lancar(self, angulo, tempo): for i in self._passaros: if not i.foi_lancado(): i.lancar(angulo, tempo) + break def calcular_pontos(self, tempo): """ From febd4b593eded1d85fc323d0fcef6a963499c86e Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Wed, 7 Mar 2018 11:54:12 -0300 Subject: [PATCH 38/49] Chamando method colidir para determinar andamento do jogo. Faltam 3 testes --- fase.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fase.py b/fase.py index ea896b7c4..f7b37d748 100644 --- a/fase.py +++ b/fase.py @@ -78,11 +78,14 @@ def status(self): :return: """ - for passaro, porco in zip(self._passaros, self._porcos): if porco.status == ATIVO and passaro.status == ATIVO: return EM_ANDAMENTO + for passaro, porco in zip(self._passaros, self._porcos): + passaro.colidir(porco, passaro.intervalo_colisao) + + for porco in self._porcos: if porco.status == ATIVO: return DERROTA From 14a56df468feab8f8c974c8986a9d68afd6160c6 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 8 Mar 2018 10:48:39 -0300 Subject: [PATCH 39/49] Renzo com classe Mutante --- oo/pessoa.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 76b575b05..5c81222d4 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -23,9 +23,12 @@ def nome_e_attr_de_classe(cls): class Homem(Pessoa): pass +class Mutante(Pessoa): + olhos = 3 + if __name__ == '__main__': - renzo = Homem(nome='Renzo', idade=30) + renzo = Mutante(nome='Renzo', idade=30) luciano = Pessoa(renzo, nome='Luciano') print(Pessoa.cumprimentar(luciano)) @@ -45,7 +48,6 @@ class Homem(Pessoa): print(renzo.__dict__) print(f'antes da mudança luciano.olhos - {luciano.olhos}') # da classe - vai todas as instancias - Pessoa.olhos = 3 print(Pessoa.olhos) print(luciano.olhos) print(renzo.olhos) @@ -56,5 +58,6 @@ class Homem(Pessoa): print(isinstance(luciano, Homem)) print(isinstance(renzo, Pessoa)) print(isinstance(renzo, Homem)) + print(renzo.olhos) From e7b1cf6331feb8bfa9ce167c51fa32b8211c65f5 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 8 Mar 2018 10:53:04 -0300 Subject: [PATCH 40/49] =?UTF-8?q?Luciano=20na=20classe=20Homem:=20m=C3=A9t?= =?UTF-8?q?odo=20cumprimentar=20sobreescrito?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/pessoa.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 5c81222d4..314facc7b 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -9,7 +9,7 @@ def __init__(self, *filhos, nome=None, idade=35): self.filhos = list(filhos) def cumprimentar(self): - return f'Olá {id(self)}' + return f'Olá, meu nome é {self.nome}' @staticmethod def metodo_estatico(): @@ -21,7 +21,8 @@ def nome_e_attr_de_classe(cls): class Homem(Pessoa): - pass + def cumprimentar(self): + return 'Aperto de mão' class Mutante(Pessoa): olhos = 3 @@ -29,7 +30,7 @@ class Mutante(Pessoa): if __name__ == '__main__': renzo = Mutante(nome='Renzo', idade=30) - luciano = Pessoa(renzo, nome='Luciano') + luciano = Homem(renzo, nome='Luciano') print(Pessoa.cumprimentar(luciano)) print(id(luciano)) @@ -59,5 +60,7 @@ class Mutante(Pessoa): print(isinstance(renzo, Pessoa)) print(isinstance(renzo, Homem)) print(renzo.olhos) + print(luciano.cumprimentar()) + print(renzo.cumprimentar()) From 508b54334dc8b177ae188ac60632b510751ecff0 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 8 Mar 2018 11:03:46 -0300 Subject: [PATCH 41/49] =?UTF-8?q?M=C3=A9todo=20cumprimentar=20sobreescrito?= =?UTF-8?q?=20com=20'super()'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/pessoa.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 314facc7b..37d8f9098 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -22,7 +22,8 @@ def nome_e_attr_de_classe(cls): class Homem(Pessoa): def cumprimentar(self): - return 'Aperto de mão' + cumprimentar_da_classe = super().cumprimentar() + return f'{cumprimentar_da_classe}. Aperto de mão' class Mutante(Pessoa): olhos = 3 From c0090ffb294cb42bea72430811d3f3c4d0fcccf5 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 8 Mar 2018 15:41:12 -0300 Subject: [PATCH 42/49] =?UTF-8?q?Testes=20para=20Fase=20completos.=20Me=20?= =?UTF-8?q?faltou=20executar=20a=20coliz=C3=A3o=20aqui.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fase.py | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/fase.py b/fase.py index f7b37d748..ab38dc497 100644 --- a/fase.py +++ b/fase.py @@ -78,19 +78,12 @@ def status(self): :return: """ - for passaro, porco in zip(self._passaros, self._porcos): - if porco.status == ATIVO and passaro.status == ATIVO: - return EM_ANDAMENTO - - for passaro, porco in zip(self._passaros, self._porcos): - passaro.colidir(porco, passaro.intervalo_colisao) - - - for porco in self._porcos: - if porco.status == ATIVO: - return DERROTA - - return VITORIA + if not self._possui_porco_ativo(): + return VITORIA + elif self._possui_passaro_ativo(): + return EM_ANDAMENTO + else: + return DERROTA def lancar(self, angulo, tempo): """ @@ -103,9 +96,9 @@ def lancar(self, angulo, tempo): :param angulo: ângulo de lançamento :param tempo: Tempo de lançamento """ - for i in self._passaros: - if not i.foi_lancado(): - i.lancar(angulo, tempo) + for passaro in self._passaros: + if not passaro.foi_lancado(): + passaro.lancar(angulo, tempo) break def calcular_pontos(self, tempo): @@ -117,6 +110,12 @@ def calcular_pontos(self, tempo): :param tempo: tempo para o qual devem ser calculados os pontos :return: objeto do tipo Ponto """ + for passaro in self._passaros: + passaro.calcular_posicao(tempo) + for alvo in self._porcos+self._obstaculos: + passaro.colidir(alvo, self.intervalo_de_colisao) + passaro.colidir_com_chao() + pontos=[self._transformar_em_ponto(a) for a in self._passaros+self._obstaculos+self._porcos] return pontos @@ -124,3 +123,14 @@ def calcular_pontos(self, tempo): def _transformar_em_ponto(self, ator): return Ponto(ator.x, ator.y, ator.caracter()) + def _possui_porco_ativo(self): + for porco in self._porcos: + if porco.status == ATIVO: + return True + return False + + def _possui_passaro_ativo(self): + for passaro in self._passaros: + if passaro.status == ATIVO: + return True + return False From b5fb4c9a5c2f807881abf9bd20969c1baaa9ca4c Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 8 Mar 2018 15:52:14 -0300 Subject: [PATCH 43/49] Alguma limpeza e adicionado 'foi_lancado()' no if de calcular_posicao --- atores.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/atores.py b/atores.py index 519bf8494..6e5d804ee 100644 --- a/atores.py +++ b/atores.py @@ -38,18 +38,17 @@ def calcular_posicao(self, tempo): :param tempo: o tempo do jogo :return: posição x, y do ator """ - #if tempo == 0: - # return 0, 0 - - return self.x, self.y # tempo/10, tempo/10 + return self.x, self.y def _mesma_posicao(self, outro_ator): return self.x == outro_ator.x and self.y == outro_ator.y def _intersecao_de_atores(self, outro_ator, intervalo): limite = intervalo * 2 + d = ((outro_ator.x - self.x) ** 2) + ((outro_ator.y - self.y) ** 2) d = math.sqrt(d) + return d < limite def colidir(self, outro_ator, intervalo=1): @@ -64,6 +63,7 @@ def colidir(self, outro_ator, intervalo=1): :param intervalo: Intervalo a ser considerado :return: """ + if self.status == ATIVO and outro_ator.status == ATIVO: if self._mesma_posicao(outro_ator) or self._intersecao_de_atores(outro_ator, intervalo): self.status = DESTRUIDO @@ -147,7 +147,7 @@ def calcular_posicao(self, tempo): :param tempo: tempo de jogo a ser calculada a posição :return: posição x, y """ - if self.status == ATIVO: + if self.status == ATIVO and self.foi_lancado(): tempo = tempo - self._tempo_de_lancamento # lançamento horizontal self.x = self._posicao_de_x(tempo) From 89fa48ea911025b1ebc9db8d5d8c877693352e41 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Thu, 8 Mar 2018 15:53:34 -0300 Subject: [PATCH 44/49] =?UTF-8?q?Corrigindo=20ordem=20da=20condi=C3=A7?= =?UTF-8?q?=C3=A3o=20no=20'if'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atores.py b/atores.py index 6e5d804ee..43af0a4ec 100644 --- a/atores.py +++ b/atores.py @@ -147,7 +147,7 @@ def calcular_posicao(self, tempo): :param tempo: tempo de jogo a ser calculada a posição :return: posição x, y """ - if self.status == ATIVO and self.foi_lancado(): + if self.foi_lancado() and self.status == ATIVO: tempo = tempo - self._tempo_de_lancamento # lançamento horizontal self.x = self._posicao_de_x(tempo) From 25c48fb556eb628fd2440ec2e988f9c88f7a1429 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Tue, 20 Mar 2018 15:41:02 -0300 Subject: [PATCH 45/49] =?UTF-8?q?Calculo=20de=20colis=C3=A3o=20mais=20simp?= =?UTF-8?q?les?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/atores.py b/atores.py index 43af0a4ec..c934ef04f 100644 --- a/atores.py +++ b/atores.py @@ -40,16 +40,16 @@ def calcular_posicao(self, tempo): """ return self.x, self.y - def _mesma_posicao(self, outro_ator): - return self.x == outro_ator.x and self.y == outro_ator.y - - def _intersecao_de_atores(self, outro_ator, intervalo): - limite = intervalo * 2 - - d = ((outro_ator.x - self.x) ** 2) + ((outro_ator.y - self.y) ** 2) - d = math.sqrt(d) - - return d < limite + # def _mesma_posicao(self, outro_ator): + # return self.x == outro_ator.x and self.y == outro_ator.y + # + # def _intersecao_de_atores(self, outro_ator, intervalo): + # limite = intervalo * 2 + # + # d = ((outro_ator.x - self.x) ** 2) + ((outro_ator.y - self.y) ** 2) + # d = math.sqrt(d) + # + # return d < limite def colidir(self, outro_ator, intervalo=1): """ @@ -65,7 +65,10 @@ def colidir(self, outro_ator, intervalo=1): """ if self.status == ATIVO and outro_ator.status == ATIVO: - if self._mesma_posicao(outro_ator) or self._intersecao_de_atores(outro_ator, intervalo): + # if self._mesma_posicao(outro_ator) or self._intersecao_de_atores(outro_ator, intervalo): + delta_x = abs(self.x - outro_ator.x) + delta_y = abs(self.y - outro_ator.y) + if delta_x <= intervalo and delta_y <= intervalo: self.status = DESTRUIDO outro_ator.status = DESTRUIDO From b7e96c2c2d382aa815da42d4a0880fd0070802b6 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Tue, 20 Mar 2018 16:20:41 -0300 Subject: [PATCH 46/49] =?UTF-8?q?M=C3=A9todo=20foi=5Flancado=20mais=20simp?= =?UTF-8?q?les?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/atores.py b/atores.py index c934ef04f..f6366cec5 100644 --- a/atores.py +++ b/atores.py @@ -112,10 +112,11 @@ def foi_lancado(self): :return: booleano """ - if self._tempo_de_lancamento is None and self._angulo_de_lancamento is None: - return False - - return True + return not self._tempo_de_lancamento is None + # if self._tempo_de_lancamento is None and self._angulo_de_lancamento is None: + # return False + # + #return True def colidir_com_chao(self): """ From 6fc1f2ccf6029ed50ff8593a2c1c2d35ea625df6 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Wed, 21 Mar 2018 14:14:36 -0300 Subject: [PATCH 47/49] velocidade escalar ajustada para cada Passaro --- atores.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/atores.py b/atores.py index f6366cec5..c6eb176e5 100644 --- a/atores.py +++ b/atores.py @@ -88,7 +88,7 @@ class DuploLancamentoExcecao(Exception): class Passaro(Ator): - velocidade_escalar = 30 + velocidade_escalar = 10 def __init__(self, x=0, y=0): """ @@ -177,6 +177,7 @@ def lancar(self, angulo, tempo_de_lancamento): class PassaroAmarelo(Passaro): _caracter_ativo = 'A' _caracter_destruido = 'a' + velocidade_escalar = 30 pass From beda18b99b330504f46c57acc904ee0587f54915 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Wed, 21 Mar 2018 14:32:53 -0300 Subject: [PATCH 48/49] =?UTF-8?q?Simplificado=20m=C3=A9todos=20para=20calc?= =?UTF-8?q?ular=20posi=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/atores.py b/atores.py index c6eb176e5..2e5ae4843 100644 --- a/atores.py +++ b/atores.py @@ -127,15 +127,23 @@ def colidir_com_chao(self): if self.y <= 0: self.status = DESTRUIDO - def _posicao_de_x(self, tempo): - return (self._x_inicial + - math.cos(self._angulo_de_lancamento) * tempo * self.velocidade_escalar) - - def _posicao_de_y(self, tempo): + def _posicao_de_x(self, delta_tempo): + # return (self._x_inicial + + # math.cos(self._angulo_de_lancamento) * tempo * self.velocidade_escalar) + x_atual = self._x_inicial + x_atual += math.cos(self._angulo_de_lancamento) * delta_tempo * self.velocidade_escalar + self.x = x_atual + + def _posicao_de_y(self, delta_tempo): """ considerando subida """ - return (self._y_inicial + - self.velocidade_escalar * tempo * math.sin(self._angulo_de_lancamento) - - 0.5 * GRAVIDADE * tempo ** 2) + # return (self._y_inicial + + # self.velocidade_escalar * tempo * math.sin(self._angulo_de_lancamento) - + # 0.5 * GRAVIDADE * tempo ** 2) + y_atual = self._y_inicial + y_atual += self.velocidade_escalar * delta_tempo * math.sin(self._angulo_de_lancamento) + y_atual -= 0.5 * GRAVIDADE * delta_tempo ** 2 + self.y = y_atual + def calcular_posicao(self, tempo): """ @@ -152,11 +160,13 @@ def calcular_posicao(self, tempo): :return: posição x, y """ if self.foi_lancado() and self.status == ATIVO: - tempo = tempo - self._tempo_de_lancamento + delta_tempo = tempo - self._tempo_de_lancamento # lançamento horizontal - self.x = self._posicao_de_x(tempo) + # self.x = self._posicao_de_x(delta_tempo) + self._posicao_de_x(delta_tempo) # lançamento vertical - self.y = self._posicao_de_y(tempo) + #self.y = self._posicao_de_y(tempo) + self._posicao_de_y(delta_tempo) return self.x, self.y From e04a5f01ffa0a77141a8b4e6b48bccff5a53fe60 Mon Sep 17 00:00:00 2001 From: Herbert Parentes Fortes Neto Date: Wed, 21 Mar 2018 14:43:39 -0300 Subject: [PATCH 49/49] =?UTF-8?q?Metodo=20calcular=20posi=C3=A7=C3=A3o=20c?= =?UTF-8?q?hamando=20metodo=20da=20classe=20pai?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atores.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/atores.py b/atores.py index 2e5ae4843..d7e7493cd 100644 --- a/atores.py +++ b/atores.py @@ -168,7 +168,8 @@ def calcular_posicao(self, tempo): #self.y = self._posicao_de_y(tempo) self._posicao_de_y(delta_tempo) - return self.x, self.y + return super().calcular_posicao(tempo) + # return self.x, self.y def lancar(self, angulo, tempo_de_lancamento): """