Compare commits

..

No commits in common. "26645d8d0b16316aa9006f096ecea6faa468a3ba" and "c900d39454ad5e4db2d3f0ae3c58f588c8bb6f8d" have entirely different histories.

1 changed files with 37 additions and 41 deletions

View File

@ -2,13 +2,14 @@
import turtle as tl import turtle as tl
import random import random
posx = [0, 1, 2, 3, 4] posx = [-200, -100, 0, 100, 200]
posy = [0, 1, 2, 3, 4] posy = [-200, -100, 0, 100, 200]
postiro = [] postiro = []
for i in range(len(posx)): for i in range(5):
for j in range(len(posy)): for j in range(5):
postiro.append(f"{i-2} {j-2}") postiro.append(f"{(i-2) * 100} {(j-2) * 100}")
print((i-2) * 100, (j-2) * 100)
#postiro = ['-200 -200', '-200 -100', '-200 0', '-200 100', '-200 200', '-100 -200', '-100 -100', '-100 0', '-100 100', '-100 200', '0 -200', '0 -100', '0 0', '0 100', '0 200', '100 -200', '100 -100', '100 0', '100 100', '100 200', '200 -200', '200 -100', '200 0', '200 100', '200 200']
tl.setup(650,650,None,None) tl.setup(650,650,None,None)
tl.title("Naval Battle 1943 Loading...") tl.title("Naval Battle 1943 Loading...")
@ -38,63 +39,58 @@ linhax(-300,300)
#linhas X #linhas X
for i in range(5): for i in range(5):
linhax(-300, (i-2)*100) linhax(-300, (i-2)*100)
tl.write(str(i), False, align="right") tl.write(str((i-2) * 100), False, align="right")
#linhas Y #linhas Y
for i in range(5): for i in range(5):
linhay((i-2)*100, -300) linhay((i-2)*100, -300)
tl.write(str(i), False, align="right") tl.write(str((i-2) * 100), False, align="right")
#Tabuleiro pronto #Tabuleiro pronto
tl.title("Naval Battle 1943") tl.title("Naval Battle 1943")
tl.hideturtle() tl.hideturtle()
boat = tl.Turtle() boat = tl.Turtle()
boat.shapesize(3, 3)
boat.up(); boat.goto(0,0); boat.left(90) boat.up(); boat.goto(0,0); boat.left(90)
#Enemies #Enemies
AMOUNT_OF_ENEMIES = 3 e1 = tl.Turtle()
enemies = [] e1.up()
e1.color("red")
e1.goto(-100,-100)
for i in range(AMOUNT_OF_ENEMIES):
enemy = tl.Turtle() e2 = tl.Turtle()
enemy.up() e2.up()
enemy.hideturtle() e2.color("red")
enemy.color("red") e2.goto(random.choice(posx), random.choice(posy))
pos = [random.choice(posy), random.choice(posy)] if e1.pos() == e2.pos():
enemy.goto((pos[0] - 2) * 100, (pos[1] - 2) * 100) e2.goto(random.choice(posx), random.choice(posy))
enemies.append([enemy, pos])
e3 = tl.Turtle()
e3.up()
e3.color("red")
e3.goto(random.choice(posx), random.choice(posy))
if e1.pos() == e3.pos():
e3.goto(random.choice(posx), random.choice(posy))
if e2.pos() == e3.pos():
e3.goto(random.choice(posx), random.choice(posy))
#partidas #partidas
win = False win = False
while win == False: while win == False:
tirox = tl.numinput("linha X do disparo","Em qual quadrante X devemos disparar a artilharia") tirox = tl.numinput("linha X do disparo","Em qual quadrante X devemos disparar a artilharia")
tiroy = tl.numinput("linha Y do disparo","Em qual quadrante Y devemos disparar a artilharia") tiroy = tl.numinput("linha Y do disparo","Em qual quadrante Y devemos disparar a artilharia")
if (tirox,tiroy) == e1.pos():
if tirox == None or tiroy == None: boat.goto(tirox,tiroy)
tl.exitonclick()
boat.goto((tirox - 2) * 100, (tiroy - 2) * 100)
acerto = False
for enemy in enemies:
if [tirox,tiroy] == enemy[1]:
hit_enemy: list[tl.Turtle, list[int, int]] = enemy
acerto = True
break
if acerto:
print("Acerto!") print("Acerto!")
boat.write("U-boat Afundado\n Capitão!",False,align="center") boat.write("U-boat Afundado\n Capitão!",False,align="center")
hit_enemy[0].hideturtle() break
enemies.remove(hit_enemy)
else: else:
boat.goto(tirox,tiroy)
print("errou!") print("errou!")
boat.write("Erramos o alvo\n Capitão!",False,align="center") boat.write("Erramos o alvo\n Capitão!",False,align="center")
acerto = False continue
if len(enemies) <= 0: # tamanho negativo???
win = True
print("Você ganhou!!") #Execução
tl.mainloop()
tl.exitonclick() tl.exitonclick()