From 921c9da7c2047b7502a23c036e733b54b533bfde Mon Sep 17 00:00:00 2001 From: Ari Sobel Date: Tue, 21 Apr 2020 13:23:41 -0300 Subject: [PATCH 01/11] metodo adicionado --- oo/__init__.py | 0 oo/pessoa.py | 9 +++++++++ 2 files changed, 9 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..3732514bd --- /dev/null +++ b/oo/pessoa.py @@ -0,0 +1,9 @@ +class Pessoa: + def cumprimentar(self): + return f"olá id({id(self)})" + +if __name__ == "__main__": + p = Pessoa() + print(Pessoa.cumprimentar(p)) + print(id(p)) + print(p.cumprimentar()) \ No newline at end of file From ecbd167b5baa590555716c0e4823a9b0ddfcf0e8 Mon Sep 17 00:00:00 2001 From: Ari Sobel Date: Tue, 21 Apr 2020 13:44:07 -0300 Subject: [PATCH 02/11] criado atributos de instancia nome e idade --- oo/pessoa.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 3732514bd..8bac03bb2 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,9 +1,14 @@ class Pessoa: + def __init__(self, nome=None, idade=10): + self.nome = nome + self.idade = idade def cumprimentar(self): - return f"olá id({id(self)})" + return f"olá {self.nome} id({id(self)})" if __name__ == "__main__": - p = Pessoa() + p = Pessoa('João') print(Pessoa.cumprimentar(p)) print(id(p)) - print(p.cumprimentar()) \ No newline at end of file + p.nome= "Ari" + print(p.cumprimentar()) + print(p.idade) \ No newline at end of file From e9aaffd078ea84ee310c31ba30969f09a898b43d Mon Sep 17 00:00:00 2001 From: Ari Sobel Date: Tue, 21 Apr 2020 14:19:51 -0300 Subject: [PATCH 03/11] criado atributo complexo filhos --- oo/pessoa.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 8bac03bb2..5e2487ad3 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,14 +1,15 @@ class Pessoa: - def __init__(self, nome=None, idade=10): + def __init__(self, *filhos, nome=None, idade=10): self.nome = nome self.idade = idade + self.filhos = list(filhos) def cumprimentar(self): return f"olá {self.nome} id({id(self)})" if __name__ == "__main__": - p = Pessoa('João') - print(Pessoa.cumprimentar(p)) - print(id(p)) - p.nome= "Ari" - print(p.cumprimentar()) - print(p.idade) \ No newline at end of file + joao = Pessoa(nome='João') + pedro = Pessoa(joao,nome='Pedro') + print(Pessoa.cumprimentar(pedro)) + print(id(joao)) + for filho in pedro.filhos: + print(filho.nome) \ No newline at end of file From 2190e110f668b3f1a40a1848a768873b7ebf494f Mon Sep 17 00:00:00 2001 From: Ari Sobel Date: Tue, 21 Apr 2020 14:36:42 -0300 Subject: [PATCH 04/11] criado e removido atributo dinamico de objeto do tipo Pessoa --- oo/pessoa.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 5e2487ad3..209578dc6 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -12,4 +12,8 @@ def cumprimentar(self): print(Pessoa.cumprimentar(pedro)) print(id(joao)) for filho in pedro.filhos: - print(filho.nome) \ No newline at end of file + print(filho.nome) + joao.sobrenome = "Silva" + del pedro.filhos + print(joao.__dict__) + print(pedro.__dict__) \ No newline at end of file From 14ec5fdf61b3bde1ed4354739a7bbc326f26bb29 Mon Sep 17 00:00:00 2001 From: Ari Sobel Date: Tue, 21 Apr 2020 16:05:45 -0300 Subject: [PATCH 05/11] criado atributo de classe olhos --- oo/pessoa.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 209578dc6..98c523859 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,4 +1,5 @@ class Pessoa: + olhos = 2 def __init__(self, *filhos, nome=None, idade=10): self.nome = nome self.idade = idade @@ -15,5 +16,11 @@ def cumprimentar(self): print(filho.nome) joao.sobrenome = "Silva" del pedro.filhos + joao.olhos = 1 + Pessoa.olhos = 3 print(joao.__dict__) - print(pedro.__dict__) \ No newline at end of file + print(pedro.__dict__) + print(Pessoa.olhos) + print(joao.olhos) + print(pedro.olhos) + print(id(Pessoa.olhos),id(joao.olhos),id(pedro.olhos)) \ No newline at end of file From 7e7f74047d34ac3dbf0e45c41e7bdec6e2bf4f03 Mon Sep 17 00:00:00 2001 From: Ari Sobel Date: Tue, 21 Apr 2020 16:19:19 -0300 Subject: [PATCH 06/11] criado metodo de classe e metodos estaticos --- oo/pessoa.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 98c523859..8d2b0dcfb 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -6,6 +6,14 @@ def __init__(self, *filhos, nome=None, idade=10): self.filhos = list(filhos) def cumprimentar(self): return f"olá {self.nome} id({id(self)})" + @staticmethod + def metodo_estatico(): + return 42 + @classmethod + def nome_e_atributo_de_clsse(cls): + return f"{cls} olhos {cls.olhos}" + + if __name__ == "__main__": joao = Pessoa(nome='João') @@ -23,4 +31,6 @@ def cumprimentar(self): print(Pessoa.olhos) print(joao.olhos) print(pedro.olhos) - print(id(Pessoa.olhos),id(joao.olhos),id(pedro.olhos)) \ No newline at end of file + print(id(Pessoa.olhos),id(joao.olhos),id(pedro.olhos)) + print(Pessoa.metodo_estatico(),joao.metodo_estatico()) + print(Pessoa.nome_e_atributo_de_clsse(),joao.nome_e_atributo_de_clsse()) \ No newline at end of file From 81547942172e4c9a2c11c4d030f550b982ef4885 Mon Sep 17 00:00:00 2001 From: "ari.sobel" Date: Tue, 28 Apr 2020 10:33:07 -0300 Subject: [PATCH 07/11] Birsd, testes de Fase --- fase.py | 28 ++++++++++++++++--- testes/{integracao.py => teste_integracao.py} | 0 testes/{atores_testes.py => testes_atores.py} | 0 testes/{fase_testes.py => testes_fase.py} | 0 4 files changed, 24 insertions(+), 4 deletions(-) rename testes/{integracao.py => teste_integracao.py} (100%) rename testes/{atores_testes.py => testes_atores.py} (100%) rename testes/{fase_testes.py => testes_fase.py} (100%) diff --git a/fase.py b/fase.py index 3385175c6..275441064 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): """ @@ -73,7 +73,14 @@ def status(self): :return: """ - return EM_ANDAMENTO + + + if not self._possui_porco_ativo(): + return VITORIA + elif self._possui_passaro_ativo(): + return EM_ANDAMENTO + else: + return DERROTA def lancar(self, angulo, tempo): """ @@ -105,3 +112,16 @@ 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 + + diff --git a/testes/integracao.py b/testes/teste_integracao.py similarity index 100% rename from testes/integracao.py rename to testes/teste_integracao.py diff --git a/testes/atores_testes.py b/testes/testes_atores.py similarity index 100% rename from testes/atores_testes.py rename to testes/testes_atores.py diff --git a/testes/fase_testes.py b/testes/testes_fase.py similarity index 100% rename from testes/fase_testes.py rename to testes/testes_fase.py From bfd06ea3997585a555e9ad1e192d6941a29caace Mon Sep 17 00:00:00 2001 From: "ari.sobel" Date: Wed, 29 Apr 2020 20:28:19 -0300 Subject: [PATCH 08/11] Birsd, testes de Fase --- fase.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fase.py b/fase.py index 275441064..c1b78d2ef 100644 --- a/fase.py +++ b/fase.py @@ -2,7 +2,6 @@ from itertools import chain from atores import ATIVO - VITORIA = 'VITORIA' DERROTA = 'DERROTA' EM_ANDAMENTO = 'EM_ANDAMENTO' @@ -36,7 +35,6 @@ def __init__(self, intervalo_de_colisao=1): self._porcos = [] self._obstaculos = [] - def adicionar_obstaculo(self, *obstaculos): """ Adiciona obstáculos em uma fase @@ -74,7 +72,6 @@ def status(self): :return: """ - if not self._possui_porco_ativo(): return VITORIA elif self._possui_passaro_ativo(): @@ -93,8 +90,10 @@ def lancar(self, angulo, tempo): :param angulo: ângulo de lançamento :param tempo: Tempo de lançamento """ - pass - + for passaro in self._passaros: + if not passaro.foi_lancado(): + passaro.lancar(angulo=angulo, tempo=tempo) + break def calcular_pontos(self, tempo): """ @@ -105,7 +104,7 @@ def calcular_pontos(self, tempo): :param tempo: tempo para o qual devem ser calculados os pontos :return: objeto do tipo Ponto """ - pontos=[self._transformar_em_ponto(a) for a in self._passaros+self._obstaculos+self._porcos] + pontos = [self._transformar_em_ponto(a) for a in self._passaros + self._obstaculos + self._porcos] return pontos @@ -116,12 +115,10 @@ def _possui_porco_ativo(self): for porco in self._porcos: if porco.status == ATIVO: return True - return False + return False def _possui_passaro_ativo(self): for passaro in self._passaros: if passaro.status == ATIVO: return True - return False - - + return False From 033e8e9b6233932c9f59a4efe5d40fbf12f901dd Mon Sep 17 00:00:00 2001 From: "ari.sobel" Date: Thu, 30 Apr 2020 10:09:42 -0300 Subject: [PATCH 09/11] Birds, testes de Atores --- atores.py | 11 ++++++++--- fase.py | 5 +++++ testes/testes_atores.py | 1 + testes/testes_fase.py | 4 ++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/atores.py b/atores.py index cfc2ef5ea..4c693b226 100644 --- a/atores.py +++ b/atores.py @@ -38,7 +38,7 @@ def calcular_posicao(self, tempo): :param tempo: o tempo do jogo :return: posição x, y do ator """ - return 1, 1 + return self.x, self.y def colidir(self, outro_ator, intervalo=1): """ @@ -52,8 +52,13 @@ def colidir(self, outro_ator, intervalo=1): :param intervalo: Intervalo a ser considerado :return: """ - pass - + if self.status == ATIVO and outro_ator.status == ATIVO: + if self.x - outro_ator.x <=1: + self.status = DESTRUIDO + outro_ator.status = DESTRUIDO + elif self.y - outro_ator.y <=1: + self.status = DESTRUIDO + outro_ator.status = DESTRUIDO class Obstaculo(Ator): diff --git a/fase.py b/fase.py index c1b78d2ef..0910ca309 100644 --- a/fase.py +++ b/fase.py @@ -104,6 +104,11 @@ 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 diff --git a/testes/testes_atores.py b/testes/testes_atores.py index f4254f29e..337e045b7 100644 --- a/testes/testes_atores.py +++ b/testes/testes_atores.py @@ -61,6 +61,7 @@ def teste_colisao_entre_atores_ativos(self): self.assert_colisao_atores_ativos(Ator(2, 2), Ator(1, 1)) self.assert_colisao_atores_ativos(Ator(2, 2), Ator(1, 2)) self.assert_colisao_atores_ativos(Ator(2, 2), Ator(1, 3)) + self.assert_colisao_atores_ativos(Ator(2, 2), Ator(4, 4)) def teste_colisao_entre_atores_ativos_com_intervalo(self): # Com intervalo 2, diferente do padrão 1, essa colisão deveria acontecer diff --git a/testes/testes_fase.py b/testes/testes_fase.py index 8158a43f5..d4c0ba216 100644 --- a/testes/testes_fase.py +++ b/testes/testes_fase.py @@ -180,10 +180,10 @@ def teste_lancar_passaro_sem_erro_quando_nao_existe_passaro(self): self.assertTrue(passaros[1].foi_lancado()) def teste_intervalo_de_colisao_padrão(self): - ''' + """ Método que testa se o intervalo de colisão da Fase é repassado aos atores. Padrão de intervalo é 1 - ''' + """ fase = Fase() passaro = PassaroFake(1, 1) fase.adicionar_passaro(passaro) From 0009c0e21c6b7267d1d267cb807381ab2a9fc093 Mon Sep 17 00:00:00 2001 From: "ari.sobel" Date: Thu, 30 Apr 2020 10:38:24 -0300 Subject: [PATCH 10/11] Birds, testes de Atores - alterando o codigo para dar certo os testes e finalizando a aula --- atores.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/atores.py b/atores.py index 4c693b226..084a05d99 100644 --- a/atores.py +++ b/atores.py @@ -53,12 +53,11 @@ def colidir(self, outro_ator, intervalo=1): :return: """ if self.status == ATIVO and outro_ator.status == ATIVO: - if self.x - outro_ator.x <=1: - self.status = DESTRUIDO - outro_ator.status = DESTRUIDO - elif self.y - outro_ator.y <=1: - self.status = DESTRUIDO - outro_ator.status = DESTRUIDO + delta_x = abs(self.x - outro_ator.x) + delta_y = abs(self.y - outro_ator.y) + if (delta_x <= intervalo) and (delta_y <= intervalo): + outro_ator.status = self.status = DESTRUIDO + class Obstaculo(Ator): From c37985488ccd4492f2e9fde3271011384db59e3e Mon Sep 17 00:00:00 2001 From: "ari.sobel" Date: Fri, 1 May 2020 16:58:22 -0300 Subject: [PATCH 11/11] estapa do Curso finalizada --- atores.py | 49 ++++++++++++++++++++++++++++++++++------- fase.py | 2 +- testes/testes_atores.py | 2 +- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/atores.py b/atores.py index 084a05d99..ed786c310 100644 --- a/atores.py +++ b/atores.py @@ -61,11 +61,12 @@ def colidir(self, outro_ator, intervalo=1): class Obstaculo(Ator): - pass + _caracter_ativo = 'O' class Porco(Ator): - pass + _caracter_ativo = '@' + _caracter_destruido = '+' class DuploLancamentoExcecao(Exception): @@ -91,13 +92,14 @@ def __init__(self, x=0, y=0): self._tempo_de_lancamento = None self._angulo_de_lancamento = None # radianos + def foi_lancado(self): """ Método que retorna verdaeira se o pássaro já foi lançado e falso caso contrário :return: booleano """ - return True + return not self._tempo_de_lancamento is None def colidir_com_chao(self): """ @@ -105,7 +107,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): """ @@ -121,7 +124,13 @@ def calcular_posicao(self, tempo): :param tempo: tempo de jogo a ser calculada a posição :return: posição x, y """ - return 1, 1 + # Fórmula Y=Y0+v*sen(teta)delta_t-(G*delta_t^2)/2. + # Fórmula X=X0+v*cos(teta)*delta_t. + if self._esta_voando(): + delta_t = tempo - self._tempo_de_lancamento + self._cacular_posicao_vertial(delta_t) + self._cacular_posicao_horizontal(delta_t) + return super().calcular_posicao(tempo) def lancar(self, angulo, tempo_de_lancamento): @@ -133,12 +142,36 @@ def lancar(self, angulo, tempo_de_lancamento): :param tempo_de_lancamento: :return: """ - pass + self._angulo_de_lancamento = math.radians(angulo) + self._tempo_de_lancamento = tempo_de_lancamento + self.foi_lancado() + + def _cacular_posicao_vertial(self, delta_t): + # Fórmula Y=Y0+v*sen(teta)delta_t-(G*delta_t^2)/2. + y_atual = self._y_inicial + angulo_radiano = self._angulo_de_lancamento + y_atual += self.velocidade_escalar * delta_t * math.sin(angulo_radiano) + y_atual -= (GRAVIDADE * (delta_t ** 2)) / 2 + self.y = y_atual + + def _cacular_posicao_horizontal(self, delta_t): + # Fórmula X=X0+v*cos(teta)*delta_t + x_atual = self._x_inicial + angulo_radiano = self._angulo_de_lancamento + x_atual += self.velocidade_escalar * delta_t * math.cos(angulo_radiano) + self.x = x_atual + + def _esta_voando(self): + return self.foi_lancado() and self.status==ATIVO class PassaroAmarelo(Passaro): - pass + _caracter_ativo = "A" + _caracter_destruido = "a" + velocidade_escalar = 30 class PassaroVermelho(Passaro): - pass \ No newline at end of file + _caracter_ativo = "V" + _caracter_destruido = "v" + velocidade_escalar = 20 \ No newline at end of file diff --git a/fase.py b/fase.py index 0910ca309..85c9b4a11 100644 --- a/fase.py +++ b/fase.py @@ -92,7 +92,7 @@ def lancar(self, angulo, tempo): """ for passaro in self._passaros: if not passaro.foi_lancado(): - passaro.lancar(angulo=angulo, tempo=tempo) + passaro.lancar(angulo, tempo) break def calcular_pontos(self, tempo): diff --git a/testes/testes_atores.py b/testes/testes_atores.py index 337e045b7..e97811356 100644 --- a/testes/testes_atores.py +++ b/testes/testes_atores.py @@ -61,7 +61,7 @@ def teste_colisao_entre_atores_ativos(self): self.assert_colisao_atores_ativos(Ator(2, 2), Ator(1, 1)) self.assert_colisao_atores_ativos(Ator(2, 2), Ator(1, 2)) self.assert_colisao_atores_ativos(Ator(2, 2), Ator(1, 3)) - self.assert_colisao_atores_ativos(Ator(2, 2), Ator(4, 4)) + # self.assert_colisao_atores_ativos(Ator(2, 2), Ator(4, 4)) def teste_colisao_entre_atores_ativos_com_intervalo(self): # Com intervalo 2, diferente do padrão 1, essa colisão deveria acontecer