Skip to content

Commit 9f85102

Browse files
author
renzon
committed
Funcionando com input no Windows, falta testar no Linux
1 parent 289fed9 commit 9f85102

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

placa_grafica.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import os
22
import platform
33
import time
4+
import sys
5+
import msvcrt
6+
import select
47
from templates import FIM
58

69

10+
apagar_tela = lambda: os.system('cls') if platform.system() == 'Windows' else lambda: os.system('clear')
11+
12+
13+
def ouvir_teclado():
14+
i, o, e = select.select([sys.stdin], [], [], 0.0001)
15+
for s in i:
16+
if s == sys.stdin:
17+
return True
18+
return False
19+
20+
21+
if platform.system() == 'Windows':
22+
ouvir_teclado = msvcrt.kbhit
23+
724
LARGURA = 80
825
ALTURA = 20
926

10-
apagar_tela = lambda: os.system('cls') if platform.system() == 'Windows' else lambda: os.system('clear')
11-
1227

1328
def desenhar_e_esperar(delta_t, fase, passo, tempo, msg):
1429
time.sleep(passo)
@@ -26,6 +41,16 @@ def _animar(delta_t, fase, passo, tempo, msg):
2641
return tempo
2742

2843

44+
def _jogar(delta_t, fase, passo, tempo, msg):
45+
while not fase.acabou(tempo):
46+
tempo = desenhar_e_esperar(delta_t, fase, passo, tempo, msg)
47+
if ouvir_teclado():
48+
input()
49+
angulo = float(input('Digite o Ângulo de Lançamento: '))
50+
fase.lancar(angulo, tempo)
51+
return tempo
52+
53+
2954
def rebobina(delta_t, fase, passo, tempo, msg):
3055
while tempo > 0:
3156
tempo = desenhar_e_esperar(-delta_t, fase, passo, tempo, msg)
@@ -34,7 +59,7 @@ def rebobina(delta_t, fase, passo, tempo, msg):
3459

3560
def animar(fase, passo=0.1, delta_t=0.1):
3661
tempo = 0
37-
tempo_final = _animar(delta_t, fase, passo, tempo, 'Play!')
62+
tempo_final = _jogar(delta_t, fase, passo, tempo, 'Play!')
3863
if input('Deseja ver o Replay? (s para sim): ').lower() == 's':
3964
velocidade_rebobina = 10
4065
rebobina(delta_t, fase, passo / velocidade_rebobina, tempo_final,

python_birds.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
fase_exemplo.adicionar_porco(*porcos)
1313
fase_exemplo.adicionar_obstaculo(*obstaculos)
1414

15-
fase_exemplo.lancar(45, 1)
16-
fase_exemplo.lancar(63, 3)
17-
fase_exemplo.lancar(23, 4)
15+
# Solução para ganhar
16+
# fase_exemplo.lancar(45, 1)
17+
# fase_exemplo.lancar(63, 3)
18+
# fase_exemplo.lancar(23, 4)
1819

1920
if __name__ == '__main__':
2021
placa_grafica.animar(fase_exemplo)

0 commit comments

Comments
 (0)