-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored simples branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: simples
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
|
|
||
| deltax_gambi=80 | ||
| # Adicionar Pássaros Amarelos | ||
| for i in range(100): | ||
| for _ in range(100): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| fase.adicionar_passaro(PassaroAmarelo(30, 30)) | ||
|
|
||
| # linhas verticais | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,25 +17,21 @@ | |
|
|
||
|
|
||
| # Adicionar Pássaros Amarelos | ||
| for i in range(80): | ||
| for _ in range(80): | ||
| fase.adicionar_passaro(PassaroAmarelo(30, 30)) | ||
|
|
||
|
|
||
| # Obstaculos | ||
| theta = 270 | ||
| h = 12 | ||
| k = 7 | ||
| step = 32 | ||
| r = 50 | ||
|
|
||
| while theta < 480: | ||
| for theta in range(270, 480, 32): | ||
| x = 600 + (h + r * math.cos(theta)) | ||
| y = (k + r * math.sin(theta)) | ||
| fase.adicionar_obstaculo(Obstaculo(x, y)) | ||
| theta += 32 | ||
|
|
||
| # Porcos | ||
| for i in range(30, 300, 32): | ||
| for _ in range(30, 300, 32): | ||
|
Comment on lines
-20
to
+34
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
This removes the following comments ( why? ): |
||
| x = randint(590, 631) | ||
| y = randint(0, 21) | ||
| fase.adicionar_porco(Porco(x, y)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,10 @@ | |
|
|
||
|
|
||
| # Adicionar Pássaros Vermelhos | ||
| for i in range(5): | ||
| for _ in range(5): | ||
| fase.adicionar_passaro(PassaroVermelho(30, 30)) | ||
| # Adicionar Pássaros Amarelos | ||
| for i in range(30): | ||
| for _ in range(30): | ||
|
Comment on lines
-18
to
+21
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| fase.adicionar_passaro(PassaroAmarelo(30, 30)) | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,17 +20,10 @@ | |
|
|
||
| def ouvir_teclado_fn(): | ||
| i, o, e = select.select([sys.stdin], [], [], 0.0001) | ||
| for s in i: | ||
| if s == sys.stdin: | ||
| return True | ||
| return False | ||
| return any(s == sys.stdin for s in i) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| if eh_windows: | ||
| ouvir_teclado = msvcrt.kbhit | ||
| else: | ||
| ouvir_teclado = ouvir_teclado_fn | ||
|
|
||
| ouvir_teclado = msvcrt.kbhit if eh_windows else ouvir_teclado_fn | ||
|
Comment on lines
-29
to
+26
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| LARGURA = 80 | ||
| ALTURA = 20 | ||
|
|
||
|
|
@@ -54,8 +47,7 @@ def _animar(delta_t, fase, passo, tempo, msg): | |
| def _jogar(delta_t, fase, passo, tempo, msg): | ||
| while not fase.acabou(): | ||
| tempo = desenhar_e_esperar(delta_t, fase, passo, tempo, msg) | ||
| entrada = ouvir_teclado() | ||
| if entrada: | ||
| if entrada := ouvir_teclado(): | ||
|
Comment on lines
-57
to
+50
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| while True: | ||
| try: | ||
| if not eh_windows: | ||
|
|
@@ -79,10 +71,23 @@ def animar(fase, passo=0.1, delta_t=0.1): | |
| tempo_final = _jogar(delta_t, fase, passo, tempo, 'Play!') | ||
| if input('Deseja ver o Replay? (s para sim): ').lower() == 's': | ||
| velocidade_rebobina = 10 | ||
| rebobina(delta_t, fase, passo / velocidade_rebobina, tempo_final, | ||
| 'Rebobinando %s vezes mais rápido!' % velocidade_rebobina) | ||
| rebobina( | ||
| delta_t, | ||
| fase, | ||
| passo / velocidade_rebobina, | ||
| tempo_final, | ||
| f'Rebobinando {velocidade_rebobina} vezes mais rápido!', | ||
| ) | ||
|
|
||
| velocidade_replay = 1 | ||
| _animar(delta_t, fase, passo / velocidade_replay, tempo, 'Replay %s vezes mais rápido!' % velocidade_replay) | ||
| _animar( | ||
| delta_t, | ||
| fase, | ||
| passo / velocidade_replay, | ||
| tempo, | ||
| f'Replay {velocidade_replay} vezes mais rápido!', | ||
| ) | ||
|
|
||
|
Comment on lines
-82
to
+90
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| apagar_tela() | ||
| print(fase.status(tempo_final)) | ||
| print(FIM) | ||
|
|
@@ -97,7 +102,7 @@ def esta_dentro_da_tela(x, y): | |
|
|
||
|
|
||
| def escolher_caracter_limitrofe(x, y): | ||
| if x == 0 or x == LARGURA - 1: | ||
| if x in [0, LARGURA - 1]: | ||
|
Comment on lines
-100
to
+105
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return '|' | ||
| if y == 0: | ||
| return '-' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,10 +62,7 @@ def _animar(): | |
| if fase.status() != EM_ANDAMENTO: | ||
| camada_de_atores.create_image(162, 55, image=PYTHONBIRDS_LOGO, anchor=NW) | ||
| camada_de_atores.create_image(54, 540, image=MENU, anchor=NW) | ||
| if fase.status() == VITORIA: | ||
| img = VOCE_GANHOU | ||
| else: | ||
| img = VOCE_PERDEU | ||
| img = VOCE_GANHOU if fase.status() == VITORIA else VOCE_PERDEU | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| camada_de_atores.create_image(192, 211, image=img, anchor=NW) | ||
| else: | ||
| camada_de_atores.delete(ALL) | ||
|
|
@@ -92,26 +89,15 @@ def _ouvir_comandos_lancamento(evento): | |
| angulo -= 1 | ||
| if angulo < 0: | ||
| angulo = 359 | ||
| elif evento.keysym == 'Return' or evento.keysym == 'space': | ||
| elif evento.keysym in ['Return', 'space']: | ||
|
Comment on lines
-95
to
+92
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| fase.lancar(angulo, tempo) | ||
|
|
||
| def _replay(event): | ||
| return | ||
| nonlocal tempo | ||
| nonlocal delta_t | ||
| if fase.acabou(tempo): | ||
| delta_t *= -multiplicador_rebobinar | ||
| _animar() | ||
|
Comment on lines
-100
to
-104
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def _jogar_novamente(event): | ||
| return | ||
| nonlocal tempo | ||
| nonlocal delta_t | ||
| if fase.acabou(tempo): | ||
| tempo = delta_t | ||
| fase.resetar() | ||
| _animar() | ||
|
Comment on lines
-109
to
-114
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def _finalizar(event): | ||
| root.destroy() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,9 +185,19 @@ def assert_passaro_posicao(self, x_esperado, y_esperado, status_esperado, passar | |
| :param tempo: tempo do jogo | ||
| """ | ||
| x_calculado, y_calculado = passaro.calcular_posicao(tempo) | ||
| self.assertEqual(x_esperado, round(x_calculado), 'valor real de x = %s' % x_calculado) | ||
| self.assertEqual(y_esperado, round(y_calculado), 'valor real de y = %s' % y_calculado) | ||
| self.assertEqual(status_esperado, passaro.status, '(x = %s, y = %s)' % (x_calculado, y_calculado)) | ||
| self.assertEqual( | ||
| x_esperado, round(x_calculado), f'valor real de x = {x_calculado}' | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| y_esperado, round(y_calculado), f'valor real de y = {y_calculado}' | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| status_esperado, | ||
| passaro.status, | ||
| f'(x = {x_calculado}, y = {y_calculado})', | ||
| ) | ||
|
Comment on lines
-188
to
+200
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class PassaroVermelhoTests(PassaroBaseTests): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,8 @@ | |
| class FaseTestes(TestCase): | ||
| def teste_acabou_com_porcos_e_passaros(self): | ||
| fase = Fase() | ||
| porcos = [Porco(1, 1) for i in range(2)] # criando 2 porcos | ||
| passaros = [PassaroAmarelo(1, 1) for i in range(2)] # criando 2 pássaros | ||
| porcos = [Porco(1, 1) for _ in range(2)] | ||
| passaros = [PassaroAmarelo(1, 1) for _ in range(2)] | ||
|
Comment on lines
-26
to
+27
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| fase.adicionar_porco(*porcos) | ||
| fase.adicionar_passaro(*passaros) | ||
|
|
||
|
|
@@ -48,8 +48,8 @@ def teste_acabou_com_porcos_e_passaros(self): | |
|
|
||
| def teste_status(self): | ||
| fase = Fase() | ||
| porcos = [Porco(1, 1) for i in range(2)] | ||
| passaros = [PassaroAmarelo(1, 1) for i in range(2)] | ||
| porcos = [Porco(1, 1) for _ in range(2)] | ||
| passaros = [PassaroAmarelo(1, 1) for _ in range(2)] | ||
|
Comment on lines
-51
to
+52
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| fase.adicionar_porco(*porcos) | ||
| fase.adicionar_passaro(*passaros) | ||
| self.assertEqual(EM_ANDAMENTO, fase.status()) | ||
|
|
@@ -123,46 +123,73 @@ def teste_intervalo_de_colisao_nao_padrao(self): | |
|
|
||
| def teste_calcular_pontos(self): | ||
| fase_exemplo = criar_fase_exemplo() | ||
| expected = set([Ponto(3, 3, 'A'), Ponto(3, 3, 'A'), Ponto(31, 10, 'O'), Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '@'), Ponto(3, 3, 'V')]) | ||
| expected = { | ||
| Ponto(3, 3, 'A'), | ||
| Ponto(3, 3, 'A'), | ||
| Ponto(31, 10, 'O'), | ||
| Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '@'), | ||
| Ponto(3, 3, 'V'), | ||
| } | ||
|
|
||
| self.assertSetEqual(expected, set(fase_exemplo.calcular_pontos(0))) | ||
|
|
||
| fase_exemplo.lancar(45, 1) | ||
|
|
||
| # i variando de 1 até 2.9 | ||
| for i in range(100, 300, 1): | ||
| for i in range(100, 300): | ||
| fase_exemplo.calcular_pontos(i / 100) | ||
|
|
||
| fase_exemplo.lancar(63, 3) | ||
|
|
||
| # i variando de 3 até 3.9 | ||
| for i in range(300, 400, 1): | ||
| for i in range(300, 400): | ||
| fase_exemplo.calcular_pontos(i / 100) | ||
|
|
||
| fase_exemplo.lancar(23, 4) | ||
|
|
||
| expected = set([Ponto(32, 11, 'v'), Ponto(17, 25, 'A'), Ponto(3, 3, 'A'), Ponto(31, 10, ' '), Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '@')]) | ||
| expected = { | ||
| Ponto(32, 11, 'v'), | ||
| Ponto(17, 25, 'A'), | ||
| Ponto(3, 3, 'A'), | ||
| Ponto(31, 10, ' '), | ||
| Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '@'), | ||
| } | ||
|
|
||
|
|
||
| self.assertSetEqual(expected, set(fase_exemplo.calcular_pontos(4))) | ||
|
|
||
| # i variando de 4 até 6.9 | ||
| for i in range(400, 700, 1): | ||
| for i in range(400, 700): | ||
| fase_exemplo.calcular_pontos(i / 100) | ||
|
|
||
| expected = set( | ||
| [Ponto(32, 11, 'v'), Ponto(57, 30, 'A'), Ponto(70, 2, 'a'), Ponto(31, 10, ' '), Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '+')]) | ||
| expected = { | ||
| Ponto(32, 11, 'v'), | ||
| Ponto(57, 30, 'A'), | ||
| Ponto(70, 2, 'a'), | ||
| Ponto(31, 10, ' '), | ||
| Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '+'), | ||
| } | ||
|
|
||
|
|
||
| self.assertSetEqual(expected, set(fase_exemplo.calcular_pontos(7))) | ||
|
|
||
| # i variando de 7 até 8.49 | ||
| for i in range(700, 849, 1): | ||
| for i in range(700, 849): | ||
| fase_exemplo.calcular_pontos(i / 100) | ||
| print(fase_exemplo.calcular_pontos(8.5)) | ||
|
|
||
| expected = set([Ponto(32, 11, 'v'), Ponto(77, 0, 'a'), Ponto(70, 2, 'a'), Ponto(31, 10, ' '), Ponto(78, 1, '+'), | ||
| Ponto(70, 1, '+')]) | ||
| expected = { | ||
| Ponto(32, 11, 'v'), | ||
| Ponto(77, 0, 'a'), | ||
| Ponto(70, 2, 'a'), | ||
| Ponto(31, 10, ' '), | ||
| Ponto(78, 1, '+'), | ||
| Ponto(70, 1, '+'), | ||
| } | ||
|
|
||
|
Comment on lines
-126
to
+192
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| self.assertSetEqual(expected, set(fase_exemplo.calcular_pontos(8.5))) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
Fase.calcular_pontosrefactored with the following changes:inline-immediately-returned-variable)