-
Notifications
You must be signed in to change notification settings - Fork 0
/
dia2.py
53 lines (41 loc) · 1.01 KB
/
dia2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
lista = []
with open("dia2.txt","r") as arquivo:
for i in arquivo:
lista.append(i[:-1])
print(lista)
# forward X does two things:
# It increases your horizontal position by X units.
# It increases your depth by your aim multiplied by X.
def forward(n):
global horizontal
global vertical
global aim
horizontal = horizontal + n
vertical = vertical+(aim*n)
# up X decreases your aim by X units.
def up(n):
global vertical
global aim
#vertical = vertical - n
aim = aim - n
# down X increases your aim by X units.
def down(n):
global vertical
global aim
#vertical = vertical + n
aim = aim + n
options = {"forward":forward,"up":up,"down":down}
horizontal = 0
vertical = 0
aim = 0
for i in lista:
print("i: ",i)
direcao = i.split(" ")[0]
valor = int(i.split(" ")[1])
options[direcao](valor)
print("vertical: ",vertical)
print("horizontal: ",horizontal)
print("aim: ",aim )
print("===")
res = horizontal*vertical
print(res)