forked from 20241144010013/20241144010013
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ad3602ba8b | |||
| 1720f77f00 | |||
| 19a9d1fafa | |||
| 8f05eb6d2c | |||
| c055b048df | |||
| 74f77706c9 | |||
| bffbecab78 | |||
| ba9aa38055 | |||
| 1e6459eece | |||
| 6387992312 | |||
| b62d22aa4c | |||
| 93eda0f85f | |||
| 92a6efc621 |
@@ -0,0 +1,207 @@
|
||||
import turtle as tl
|
||||
import random as rd
|
||||
#setup
|
||||
tl.setup(600,600,None,None)
|
||||
tl.hideturtle()
|
||||
tl.colormode(255)
|
||||
t = tl.Turtle()
|
||||
t.color("Blue")
|
||||
t.goto(-100,0)
|
||||
t2 = tl.Turtle()
|
||||
t2.color("Red")
|
||||
t2.goto(100,0)
|
||||
tl.tracer(1)
|
||||
cheese = tl.Turtle()
|
||||
cheese.color("Yellow")
|
||||
cheese.shape("square")
|
||||
cheese.up()
|
||||
cheese.goto(-600,600)
|
||||
|
||||
#CENÁRIO
|
||||
|
||||
#moldura
|
||||
tl.tracer(0)
|
||||
tl.color("black")
|
||||
tl.up()
|
||||
tl.goto(-300,-300)
|
||||
tl.down()
|
||||
tl.goto(-300,300)
|
||||
tl.goto(300,300)
|
||||
tl.goto(300,-300)
|
||||
|
||||
#queijo
|
||||
possible_pos = [(200,250),(-100,-250), (250,-250),(-50,200),(100,-150),(100,0)]
|
||||
|
||||
#linhas
|
||||
tl.bgcolor((205, 133, 63))
|
||||
for _ in range(-6, 6):
|
||||
tl.color((139, 69, 19))
|
||||
tl.up()
|
||||
tl.goto(-300, _ * 50)
|
||||
tl.down()
|
||||
tl.goto(300, _ * 50)
|
||||
tl.up()
|
||||
|
||||
tl.color("light blue")
|
||||
tl.goto(-300, 300)
|
||||
tl.down()
|
||||
tl.begin_fill()
|
||||
|
||||
#parede
|
||||
tl.goto(-300, 250)
|
||||
tl.goto(300, 250)
|
||||
tl.goto(300,300)
|
||||
tl.end_fill()
|
||||
|
||||
#casa de rato
|
||||
tl.up()
|
||||
tl.goto(170, 250)
|
||||
tl.color("black")
|
||||
tl.down()
|
||||
tl.begin_fill()
|
||||
tl.goto(190,250)
|
||||
tl.goto(190,260)
|
||||
tl.left(90)
|
||||
tl.circle(10, 180)
|
||||
tl.end_fill()
|
||||
|
||||
#FIM-CENÁRIO
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
|
||||
|
||||
#funções
|
||||
global tem_queijo
|
||||
tem_queijo = False
|
||||
|
||||
#pass
|
||||
|
||||
def colide():
|
||||
global tem_queijo
|
||||
rng = rd.randint(0,5)
|
||||
chance_tocheese = rd.randint(0,100)
|
||||
if t.distance(t2) < 10 and tem_queijo == False:
|
||||
print("Vitoria do Gato")
|
||||
tl.bye()
|
||||
elif t.pos()[1] > 250 or t.pos()[1] < -300 or t.pos()[0] > 300 or t.pos()[0] <- 300:
|
||||
t.goto(0,0)
|
||||
|
||||
elif t2.pos()[1] > 250 or t2.pos()[1] < -300 or t2.pos()[0] > 300 or t2.pos()[0] < -300:
|
||||
t2.goto(0,0)
|
||||
|
||||
elif t.distance(t2) < 10 and tem_queijo == True:
|
||||
print("Vitoria do Rato")
|
||||
tl.bye()
|
||||
|
||||
if chance_tocheese <= 5:
|
||||
tl.tracer(0)
|
||||
cheese.goto(possible_pos[rng])
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
if t.distance(cheese) < 10:
|
||||
print("queijo coletado!")
|
||||
tem_queijo = True
|
||||
cheese.hideturtle()
|
||||
|
||||
|
||||
|
||||
def godir():
|
||||
tl.tracer(0)
|
||||
t.seth(0)
|
||||
t.forward(50)
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
colide()
|
||||
|
||||
|
||||
#pass
|
||||
def goleft():
|
||||
tl.tracer(0)
|
||||
t.seth(180)
|
||||
t.forward(50)
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
colide()
|
||||
|
||||
|
||||
#pass
|
||||
def goup():
|
||||
tl.tracer(0)
|
||||
t.seth(90)
|
||||
t.forward(50)
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
colide()
|
||||
|
||||
|
||||
#pass
|
||||
def godown():
|
||||
tl.tracer(0)
|
||||
t.seth(270)
|
||||
t.forward(50)
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
colide()
|
||||
|
||||
|
||||
# pass
|
||||
|
||||
|
||||
|
||||
#segunda tartaruga
|
||||
def godir2():
|
||||
tl.tracer(0)
|
||||
t2.seth(0)
|
||||
t2.forward(50)
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
colide()
|
||||
|
||||
|
||||
#pass
|
||||
def goleft2():
|
||||
tl.tracer(0)
|
||||
t2.seth(180)
|
||||
t2.forward(50)
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
colide()
|
||||
|
||||
|
||||
#pass
|
||||
def goup2():
|
||||
tl.tracer(0)
|
||||
t2.seth(90)
|
||||
t2.forward(50)
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
colide()
|
||||
|
||||
|
||||
#pass
|
||||
def godown2():
|
||||
tl.tracer(0)
|
||||
t2.seth(270)
|
||||
t2.forward(50)
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
colide()
|
||||
#pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#execução
|
||||
tl.onkeypress(godir,"d")
|
||||
tl.onkeypress(goleft,"a")
|
||||
tl.onkeypress(goup,"w")
|
||||
tl.onkeypress(godown, "s")
|
||||
tl.onkeypress(godir2,"Right")
|
||||
tl.onkeypress(goleft2,"Left")
|
||||
tl.onkeypress(goup2,"Up")
|
||||
tl.onkeypress(godown2, "Down")
|
||||
tl.listen()
|
||||
|
||||
#loop
|
||||
tl.mainloop()
|
||||
@@ -0,0 +1,316 @@
|
||||
#esse jogo ainda está sob teste... e não deve ser considerado completo
|
||||
#setup
|
||||
import turtle as tl
|
||||
import random
|
||||
|
||||
posx = [-200, -100, 0, 100, 200]
|
||||
posy = [-200, -100, 0, 100, 200]
|
||||
tl.setup(650,650,None,None)
|
||||
tl.title("Naval Battle 1943 Loading...")
|
||||
tl.speed(0)
|
||||
|
||||
#posições possiveis
|
||||
tiro_pos = {
|
||||
"A1": (200,200),
|
||||
"A2": (200,100),
|
||||
"A3": (200,0),
|
||||
"A4": (200,-100),
|
||||
"A5": (200,-200),
|
||||
"B1": (100,200),
|
||||
"B2": (100,100),
|
||||
"B3": (100,0),
|
||||
"B4": (100,-100),
|
||||
"B5": (100,-200),
|
||||
"C1": (0,200),
|
||||
"C2": (0,100),
|
||||
"C3": (0,0),
|
||||
"C4": (0,-100),
|
||||
"C5": (0,-200),
|
||||
"D1": (-100,200),
|
||||
"D2": (-100,100),
|
||||
"D3": (-100,0),
|
||||
"D4": (-100,-100),
|
||||
"D5": (-100,-200),
|
||||
"E1": (-200,200),
|
||||
"E2": (-200,100),
|
||||
"E3": (-200,0),
|
||||
"E4": (-200,-100),
|
||||
"E5": (-200,-200),
|
||||
"QUIT": (1000, 1000),
|
||||
}
|
||||
|
||||
#funções
|
||||
def linhax(x,y):
|
||||
tl.up(); tl.goto(x,y)
|
||||
tl.down(); tl.goto(x+600,y)
|
||||
#pass
|
||||
|
||||
def linhay(x,y):
|
||||
tl.up(); tl.goto(x,y)
|
||||
tl.down(); tl.goto(x,y+600)
|
||||
#pass
|
||||
|
||||
#radar screen
|
||||
tl.bgcolor("lime green")
|
||||
#moldura
|
||||
tl.tracer(0)
|
||||
linhax(-300,-300)
|
||||
linhay(-300,-300)
|
||||
linhay(300,-300)
|
||||
linhax(-300,300)
|
||||
|
||||
#linhas X
|
||||
linhax(-300,-200); tl.write("5",False,align="right")
|
||||
linhax(-300,-100); tl.write("4",False,align="right")
|
||||
linhax(-300,0); tl.write("3",False,align="right")
|
||||
linhax(-300,100); tl.write("2",False,align="right")
|
||||
linhax(-300,200); tl.write("1",False,align="right")
|
||||
|
||||
#linhas Y
|
||||
linhay(-200,-300); tl.write("E",False,align="right")
|
||||
linhay(-100,-300); tl.write("D",False,align="right")
|
||||
linhay(0,-300); tl.write("C",False,align="right")
|
||||
linhay(100,-300); tl.write("B",False,align="right")
|
||||
linhay(200,-300); tl.write("A",False,align="right")
|
||||
#Tabuleiro pronto
|
||||
tl.update()
|
||||
tl.tracer(1)
|
||||
tl.title("Naval Battle 1943")
|
||||
tl.hideturtle()
|
||||
|
||||
bullet = tl.Turtle()
|
||||
bullet.color("Yellow")
|
||||
bullet.hideturtle()
|
||||
bullet.up()
|
||||
|
||||
#gamemode SinglePlayer
|
||||
gmode = tl.textinput("Modo de Jogo","Qual Modo Deseja jogar?\ndigite multi para jogar com um amigo do lado\ne single para jogar sozinho")
|
||||
if gmode == "single":
|
||||
win = False
|
||||
print("Modo Solitario Selecionado! escolha onde ficaram seus navios")
|
||||
#Player 1
|
||||
p1 = tl.Turtle()
|
||||
p1.up()
|
||||
spawnp1 = "A1" #str(input("Senhor, Onde Nosso Submarino Deve Ficar? "))
|
||||
p1.goto(tiro_pos[spawnp1])
|
||||
|
||||
p2 = tl.Turtle()
|
||||
p2.up()
|
||||
spawnp2 = "A2" #str(input("Senhor, Onde Nosso Crusador Deve Ficar? "))
|
||||
p2.goto(tiro_pos[spawnp2])
|
||||
|
||||
p3 = tl.Turtle()
|
||||
p3.up()
|
||||
spawnp3 = "A3" #str(input("Senhor, Onde Nosso Destroyer Deve Ficar? "))
|
||||
p3.goto(tiro_pos[spawnp3])
|
||||
#pass
|
||||
|
||||
#inimigos
|
||||
e1 = tl.Turtle()
|
||||
e1.up()
|
||||
e1.color("red")
|
||||
e1.goto(random.choice(posx), random.choice(posy))
|
||||
|
||||
|
||||
e2 = tl.Turtle()
|
||||
e2.up()
|
||||
e2.color("red")
|
||||
e2.goto(random.choice(posx), random.choice(posy))
|
||||
if e1.pos() == e2.pos():
|
||||
e2.goto(random.choice(posx), random.choice(posy))
|
||||
|
||||
|
||||
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))
|
||||
#pass
|
||||
while win == False:
|
||||
tiro = tl.textinput("Onde Devemos Disparar?","Em Qual Intersecão Devemos Disparar?\nDigite (quit) Para Sair").upper()
|
||||
while tiro not in tiro_pos:
|
||||
tiro = tl.textinput("linha X do disparo","Em qual quadrante X devemos disparar a artilharia")
|
||||
#acerto Submarino
|
||||
if (tiro_pos[tiro]) == e1.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro])
|
||||
print("Acerto!")
|
||||
bullet.write("U-boat Afundado\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
e1.goto(-1000,-1000)
|
||||
#acerto Crusador
|
||||
elif (tiro_pos[tiro]) == e2.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro])
|
||||
print("Acerto!")
|
||||
bullet.write("Crusador Afundado\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
e2.goto(-1000,-1000)
|
||||
#acerto Destroyer
|
||||
elif(tiro_pos[tiro]) == e3.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro])
|
||||
print("Acerto!")
|
||||
bullet.write("Destroyer Afundado\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
e3.goto(-1000,-1000)
|
||||
#erro
|
||||
elif (tiro_pos[tiro]) != e1.pos() and (tiro_pos[tiro]) != e2.pos() and (tiro_pos[tiro]) != e3.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro])
|
||||
print("errou!")
|
||||
bullet.write("Erramos o alvo\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
#vencer
|
||||
if (e1.pos() == (-1000, -1000)) and (e2.pos() == (-1000, -1000)) and (e3.pos() == (-1000, -1000)):
|
||||
print("voçe ganhou")
|
||||
break
|
||||
#sair
|
||||
if bullet.pos() == (1000, 1000):
|
||||
break
|
||||
|
||||
#tiro inimigo
|
||||
tiro_e = tl.Turtle()
|
||||
tiro_e.hideturtle()
|
||||
|
||||
#acerto Submarino
|
||||
if (tiro_pos[tiro_e]) == p1.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro_e])
|
||||
print("Acerto!")
|
||||
bullet.write("U-boat Afundado\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
e1.goto(-1000,-1000)
|
||||
#acerto Crusador
|
||||
elif (tiro_pos[tiro]) == p2.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro])
|
||||
print("Acerto!")
|
||||
bullet.write("Crusador Afundado\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
e2.goto(-1000,-1000)
|
||||
#acerto Destroyer
|
||||
elif(tiro_pos[tiro_e]) == p3.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro_e])
|
||||
print("Acerto!")
|
||||
bullet.write("Destroyer Afundado\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
e3.goto(-1000,-1000)
|
||||
#erro
|
||||
elif (tiro_pos[tiro_e]) != p1.pos() and (tiro_pos[tiro_e]) != p2.pos() and (tiro_pos[tiro_e]) != p3.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro_e])
|
||||
print("errou!")
|
||||
bullet.write("Erramos o alvo\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
#vencer
|
||||
if (p1.pos() == (-1000, -1000)) and (p2.pos() == (-1000, -1000)) and (p3.pos() == (-1000, -1000)):
|
||||
print("voçe ganhou")
|
||||
break
|
||||
#sair
|
||||
if tiro_e.pos() == (1000, 1000):
|
||||
break
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#Multiplayer
|
||||
elif gmode == "multi":
|
||||
win = False
|
||||
print("Modo Multiplayer Selecionado! Fique ao lado de seu amigo\nnão olhe os navios dele e vice-versa")
|
||||
#Player 1
|
||||
p1 = tl.Turtle()
|
||||
p1.up()
|
||||
spawnp1 = str(input("Senhor, Onde Nosso Submarino Deve Ficar? "))
|
||||
p1.goto(tiro_pos[spawnp1])
|
||||
|
||||
p2 = tl.Turtle()
|
||||
p2.up()
|
||||
spawnp2 = str(input("Senhor, Onde Nosso Crusador Deve Ficar? "))
|
||||
p2.goto(tiro_pos[spawnp2])
|
||||
|
||||
p3 = tl.Turtle()
|
||||
p3.up()
|
||||
spawnp3 = str(input("Senhor, Onde Nosso Destroyer Deve Ficar? "))
|
||||
p3.goto(tiro_pos[spawnp3])
|
||||
#pass
|
||||
|
||||
#player 2
|
||||
p1_2 = tl.Turtle()
|
||||
p1_2.up()
|
||||
spawnp1_2 = str(input("Senhor, Onde Nosso Submarino Deve Ficar? "))
|
||||
p1_2.goto(tiro_pos[spawnp1_2])
|
||||
|
||||
p2_2 = tl.Turtle()
|
||||
p2_2.up()
|
||||
spawnp2_2 = str(input("Senhor, Onde Nosso Crusador Deve Ficar? "))
|
||||
p2_2.goto(tiro_pos[spawnp2_2])
|
||||
|
||||
p3_2 = tl.Turtle()
|
||||
p3_2.up()
|
||||
spawnp3_2 = str(input("Senhor, Onde Nosso Destroyer Deve Ficar? "))
|
||||
p3_2.goto(tiro_pos[spawnp3_2])
|
||||
#pass
|
||||
|
||||
while win == False:
|
||||
tiro = tl.textinput("linha X do disparo","Em qual quadrante X devemos disparar a artilharia")
|
||||
if (tiro_pos[tiro]) == p1.pos() or (tiro_pos[tiro]) == p1_2.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro])
|
||||
print("Acerto!")
|
||||
bullet.write("U-boat Afundado\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
break
|
||||
elif (tiro_pos[tiro]) == p2.pos() or (tiro_pos[tiro]) == p2_2.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro])
|
||||
print("Acerto!")
|
||||
bullet.write("Crusador Afundado\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
break
|
||||
elif(tiro_pos[tiro]) == p3.pos() or (tiro_pos[tiro]) == p3_2.pos():
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro])
|
||||
print("Acerto!")
|
||||
bullet.write("Destroyer Afundado\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
break
|
||||
else:
|
||||
bullet.showturtle()
|
||||
bullet.goto(tiro_pos[tiro])
|
||||
print("errou!")
|
||||
bullet.write("Erramos o alvo\n Capitão!",False,align="center")
|
||||
bullet.hideturtle()
|
||||
continue
|
||||
#partidas
|
||||
|
||||
#TELA DE VITORIA
|
||||
|
||||
#Execução
|
||||
tl.mainloop()
|
||||
tl.exitonclick()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Sobre
|
||||
Repositorio que contem uma versão **MELHORADA** de batalha naval.
|
||||
# 20241144010013
|
||||
|
||||
# Repository for random Projects that run through my mind
|
||||
|
||||
Fork do [repositório de Kaio Henrique](https://gitea.mange.ifrn.edu.br/20241144010013/20241144010013)
|
||||
@@ -0,0 +1,21 @@
|
||||
import pyautogui as auto
|
||||
|
||||
confirma = auto.confirm("Startar o programa", "Start-up", buttons=["Sim", "Não"])
|
||||
if confirma == "Sim":
|
||||
senha = auto.password(text='Qual sua Senha do SUAP', title='Senha', default='', mask='*')
|
||||
auto.PAUSE = 1.5
|
||||
auto.press("win")
|
||||
auto.write("chrome")
|
||||
auto.press("enter")
|
||||
auto.write("https://suap.ifrn.edu.br/accounts/login/")
|
||||
auto.press("enter")
|
||||
auto.write("20241144010013")
|
||||
auto.press("tab")
|
||||
auto.write(senha)
|
||||
auto.press("enter")
|
||||
auto.hotkey("ctrl","t")
|
||||
auto.press("win")
|
||||
auto.write("code")
|
||||
auto.press("enter")
|
||||
|
||||
|
||||
-119
@@ -1,119 +0,0 @@
|
||||
#setup
|
||||
import turtle as tl
|
||||
import random, sys
|
||||
|
||||
args = sys.argv
|
||||
# name, -arguments
|
||||
def has_argument(args, arg):
|
||||
if len(args) > 1:
|
||||
if args[1].startswith("-"):
|
||||
for chr in args[1]:
|
||||
if chr == arg:
|
||||
return True
|
||||
return False
|
||||
|
||||
def num2char(num) -> chr:
|
||||
return chr(num + 65)
|
||||
def char2num(char) -> int:
|
||||
return ord(char) - 65
|
||||
|
||||
posx = [0, 1, 2, 3, 4]
|
||||
posy = [0, 1, 2, 3, 4]
|
||||
postiro = []
|
||||
for i in range(len(posx)):
|
||||
for j in range(len(posy)):
|
||||
postiro.append(f"{i-2} {j-2}")
|
||||
|
||||
|
||||
tl.setup(650,650,None,None)
|
||||
tl.title("Naval Battle 1943 Loading...")
|
||||
tl.speed(0)
|
||||
|
||||
|
||||
#funções
|
||||
def linhax(x,y):
|
||||
tl.up(); tl.goto(x,y)
|
||||
tl.down(); tl.goto(x+600,y)
|
||||
pass
|
||||
|
||||
def linhay(x,y):
|
||||
tl.up(); tl.goto(x,y)
|
||||
tl.down(); tl.goto(x,y+600)
|
||||
pass
|
||||
|
||||
|
||||
#radar screen
|
||||
tl.bgcolor("lime green")
|
||||
#moldura
|
||||
linhax(-300,-300)
|
||||
linhay(-300,-300)
|
||||
linhay(300,-300)
|
||||
linhax(-300,300)
|
||||
|
||||
#linhas X
|
||||
for i in range(5):
|
||||
linhax(-300, (i-2)*100)
|
||||
tl.write(num2char(i), False, align="right")
|
||||
|
||||
#linhas Y
|
||||
for i in range(5):
|
||||
linhay((i-2)*100, -300)
|
||||
tl.write(str(i), False, align="right")
|
||||
|
||||
#Tabuleiro pronto
|
||||
tl.title("Naval Battle 1943")
|
||||
tl.hideturtle()
|
||||
boat = tl.Turtle()
|
||||
boat.shapesize(3, 3)
|
||||
boat.up(); boat.goto(0,0); boat.left(90)
|
||||
|
||||
#Enemies
|
||||
AMOUNT_OF_ENEMIES = 3
|
||||
enemies = []
|
||||
|
||||
for i in range(AMOUNT_OF_ENEMIES):
|
||||
enemy = tl.Turtle()
|
||||
enemy.color("red")
|
||||
enemy.up()
|
||||
if not has_argument(args, "D"):
|
||||
enemy.hideturtle()
|
||||
else:
|
||||
enemy.shapesize(3, 3)
|
||||
pos = [random.choice(posy), random.choice(posy)]
|
||||
enemy.goto((pos[0] - 2) * 100, (pos[1] - 2) * 100)
|
||||
|
||||
enemies.append([enemy, pos])
|
||||
|
||||
#partidas
|
||||
win = False
|
||||
while win == False:
|
||||
tirox = tl.numinput("linha X do disparo","Em qual quadrante X devemos disparar a artilharia")
|
||||
tiroy = tl.textinput("linha Y do disparo","Em qual quadrante Y devemos disparar a artilharia")
|
||||
tiroy = char2num(tiroy.upper())
|
||||
|
||||
if tirox == None or tiroy == None:
|
||||
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!")
|
||||
boat.write("U-boat Afundado\n Capitão!",False,align="center")
|
||||
hit_enemy[0].hideturtle()
|
||||
enemies.remove(hit_enemy)
|
||||
else:
|
||||
print("errou!")
|
||||
boat.write("Erramos o alvo\n Capitão!",False,align="center")
|
||||
acerto = False
|
||||
|
||||
if len(enemies) <= 0: # tamanho negativo???
|
||||
win = True
|
||||
|
||||
print("Você ganhou!!")
|
||||
tl.exitonclick()
|
||||
@@ -1,130 +0,0 @@
|
||||
import socket, threading
|
||||
|
||||
class Networking:
|
||||
"""
|
||||
A class that contains common networking functions for both server and client.
|
||||
"""
|
||||
@staticmethod
|
||||
def recv_any_size(sock):
|
||||
"""
|
||||
Receives data from the socket without knowing the size of the data.
|
||||
|
||||
The sender must send the size of the data before sending the data.
|
||||
"""
|
||||
data_size = sock.recv(1024).decode()
|
||||
sock.send("OK".encode())
|
||||
data = sock.recv(int(data_size)).decode()
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def send_any_size(sock, data):
|
||||
"""
|
||||
Sends data to the socket without knowing the size of the data.
|
||||
|
||||
Sends the size of the data before sending the data.
|
||||
"""
|
||||
sock.send(str(len(data)).encode())
|
||||
response = sock.recv(1024).decode()
|
||||
sock.send(data.encode())
|
||||
def recv_any_size(self, client):
|
||||
"""
|
||||
Receives data from the client without knowing the size of the data.
|
||||
|
||||
Client must send the size of the data before sending the data.
|
||||
"""
|
||||
data_size = client.recv(1024).decode()
|
||||
data = client.recv(int(data_size)).decode()
|
||||
return data
|
||||
|
||||
class Server:
|
||||
"""
|
||||
A basic server class that can be inherited to create a custom server.
|
||||
|
||||
Contains some basic networking functions.
|
||||
"""
|
||||
def __init__(self, host = "127.0.0.1", port = 8080):
|
||||
"""
|
||||
Hosts a basic server on the specified host and port
|
||||
"""
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.server.bind((self.host, self.port))
|
||||
|
||||
def start(self, max_connections = 5):
|
||||
"""
|
||||
Starts the server and listens for *max_connections* connections, defaulted to 5
|
||||
"""
|
||||
self.server.listen(max_connections)
|
||||
while True:
|
||||
client, addr = self.server.accept()
|
||||
print(f"Connection from {addr}")
|
||||
|
||||
# Start a new thread for the client
|
||||
threading.Thread(target=self.handle_client, args=(client,)).start()
|
||||
|
||||
def handle_client(self, client):
|
||||
"""
|
||||
Checks if the client sent "exit" and closes the connection if it did, else send the data back.
|
||||
|
||||
Overwrite with your own implementation.
|
||||
"""
|
||||
while True:
|
||||
data = self.recv(client)
|
||||
if data == "exit":
|
||||
break
|
||||
self.send(client, data)
|
||||
pass
|
||||
|
||||
def send(self, client, data):
|
||||
"""
|
||||
Sends data to the client
|
||||
"""
|
||||
Networking.send_any_size(client, data)
|
||||
|
||||
def recv(self, client):
|
||||
"""
|
||||
Receives data from the client
|
||||
"""
|
||||
return Networking.recv_any_size(client)
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops the server
|
||||
"""
|
||||
self.server.close()
|
||||
|
||||
|
||||
class Client:
|
||||
"""
|
||||
A basic client class that can be inherited to create a custom client.
|
||||
|
||||
Contains some basic networking functions.
|
||||
"""
|
||||
def __init__(self, host = "127.0.0.1", port = 8080):
|
||||
"""
|
||||
Connects to a server on the specified host and port
|
||||
"""
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.sock.connect((self.host, self.port))
|
||||
|
||||
def send(self, data):
|
||||
"""
|
||||
Sends data to the server
|
||||
"""
|
||||
Networking.send_any_size(self.sock, data)
|
||||
|
||||
def recv(self):
|
||||
"""
|
||||
Receives data from the server
|
||||
"""
|
||||
return Networking.recv_any_size(self.sock)
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Closes the connection
|
||||
"""
|
||||
Networking.send_any_size(self.sock, "exit")
|
||||
self.sock.close()
|
||||
@@ -1,24 +0,0 @@
|
||||
from networking import net_module
|
||||
import socket, threading
|
||||
|
||||
class Test_server(net_module.Server):
|
||||
def handle_client(self, client: socket.socket):
|
||||
print(self.recv(client))
|
||||
self.send(client, "Hello World")
|
||||
|
||||
print(self.recv(client))
|
||||
client.close()
|
||||
class Test_client(net_module.Client):
|
||||
def main(self):
|
||||
|
||||
self.send("Hello World")
|
||||
|
||||
print(self.recv())
|
||||
|
||||
self.close()
|
||||
|
||||
server = Test_server()
|
||||
threading.Thread(target=server.start, args=(1,)).start()
|
||||
client = Test_client()
|
||||
|
||||
client.main()
|
||||
Reference in New Issue
Block a user