Skip to content

Commit d542741

Browse files
committed
Implementação das classes Motor, Direcao e Carro.
1 parent 86b0885 commit d542741

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

oo/carro.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def velocidade(self):
106106

107107
@velocidade.setter
108108
def velocidade(self, vel):
109-
self._velocidade = 0 if vel < 0 else vel
109+
# Se velocidade for negativa, velocidade recebe 0
110+
self._velocidade = max(0, vel)
110111

111112
def acelerar(self):
112113
self.velocidade += 1
@@ -127,14 +128,10 @@ def valor(self):
127128
return self._valores[self._cursor]
128129

129130
def girar_a_direita(self):
130-
self._cursor += 1
131-
if self._cursor == len(self._valores):
132-
self._cursor = 0
131+
self._cursor = (self._cursor + 1) % len(self._valores)
133132

134133
def girar_a_esquerda(self):
135-
self._cursor -= 1
136-
if self._cursor < 0:
137-
self._cursor = len(self._valores)-1
134+
self._cursor = (self._cursor - 1) % len(self._valores)
138135

139136

140137
# ------------------------------------------------------------------

0 commit comments

Comments
 (0)