Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions fase.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ 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]

return pontos
return [
self._transformar_em_ponto(a)
for a in self._passaros + self._obstaculos + self._porcos
]
Comment on lines -101 to +104
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Fase.calcular_pontos refactored with the following changes:


def _transformar_em_ponto(self, ator):
return Ponto(ator.x, ator.y, ator.caracter())
Expand Down
2 changes: 1 addition & 1 deletion fases/brasil.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

deltax_gambi=80
# Adicionar Pássaros Amarelos
for i in range(100):
for _ in range(100):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 19-19 refactored with the following changes:

fase.adicionar_passaro(PassaroAmarelo(30, 30))

# linhas verticais
Expand Down
10 changes: 3 additions & 7 deletions fases/escudo_espartano.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 20-38 refactored with the following changes:

This removes the following comments ( why? ):

# Obstaculos

x = randint(590, 631)
y = randint(0, 21)
fase.adicionar_porco(Porco(x, y))
Expand Down
4 changes: 2 additions & 2 deletions fases/rodar_fase_exemplo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 18-21 refactored with the following changes:

fase.adicionar_passaro(PassaroAmarelo(30, 30))


Expand Down
35 changes: 20 additions & 15 deletions placa_grafica.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ouvir_teclado_fn refactored with the following changes:

  • Use any() instead of for loop (use-any)



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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 29-33 refactored with the following changes:

LARGURA = 80
ALTURA = 20

Expand All @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _jogar refactored with the following changes:

while True:
try:
if not eh_windows:
Expand All @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function animar refactored with the following changes:

apagar_tela()
print(fase.status(tempo_final))
print(FIM)
Expand All @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function escolher_caracter_limitrofe refactored with the following changes:

return '|'
if y == 0:
return '-'
Expand Down
18 changes: 2 additions & 16 deletions placa_grafica_tkinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function animar._animar refactored with the following changes:

camada_de_atores.create_image(192, 211, image=img, anchor=NW)
else:
camada_de_atores.delete(ALL)
Expand 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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function animar._ouvir_comandos_lancamento refactored with the following changes:

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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function animar._replay refactored with the following changes:



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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function animar._jogar_novamente refactored with the following changes:


def _finalizar(event):
root.destroy()
Expand Down
16 changes: 13 additions & 3 deletions testes/atores_testes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PassaroBaseTests.assert_passaro_posicao refactored with the following changes:



class PassaroVermelhoTests(PassaroBaseTests):
Expand Down
61 changes: 44 additions & 17 deletions testes/integracao.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FaseTestes.teste_acabou_com_porcos_e_passaros refactored with the following changes:

This removes the following comments ( why? ):

# criando 2 porcos
# criando 2 pássaros

fase.adicionar_porco(*porcos)
fase.adicionar_passaro(*passaros)

Expand All @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FaseTestes.teste_status refactored with the following changes:

fase.adicionar_porco(*porcos)
fase.adicionar_passaro(*passaros)
self.assertEqual(EM_ANDAMENTO, fase.status())
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FaseTestes.teste_calcular_pontos refactored with the following changes:


self.assertSetEqual(expected, set(fase_exemplo.calcular_pontos(8.5)))

Expand Down