CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

Programation d'une bataille navale sur Python avec turtle

barthelemye
barthelemye
Niveau 1
15 novembre 2018 à 21:10:01

Salut à tous, je suis débutant en programmation et j'ai rencontré un problème avec le programme suivant (certaines tabulation ne sont pas prise ne compte mais apparemment l'erreur ne vient pas de là donc pas de problème)

from random import randint
import turtle as tl

def échiquier ():#Cette fonction dessine un échiquier

N1=tl.Turtle()#création de 8 tortues
N2=tl.Turtle()
N3=tl.Turtle()
N4=tl.Turtle()
N5=tl.Turtle()
N6=tl.Turtle()
N7=tl.Turtle()
N8=tl.Turtle()

N1.up()#Positionement des tortues
N1.goto(-200,200)
N1.speed('fastest')
N1.down()

N2.up()
N2.goto(-200,150)
N2.speed('fastest')
N2.down()

N3.up()
N3.goto(-200,100)
N3.speed('fastest')
N3.down()

N4.up()
N4.goto(-200,50)
N4.speed('fastest')
N4.down()

N5.up()
N5.goto(-200,0)
N5.speed('fastest')
N5.down()

N6.up()
N6.goto(-200,-50)
N6.speed('fastest')
N6.down()

N7.up()
N7.goto(-200,-100)
N7.speed('fastest')
N7.down()

N8.up()
N8.goto(-200,-150)
N8.speed('fastest')
N8.down()

for i in range (0,4):#Chaque tortue effectue à son tour deux carrés de couleurs dépendant de leur ligne 4 fois
N1.fillcolor("white")
N1.begin_fill()
N1.width(2)
for i in range(0,4):
N1.forward(50)
N1.right(90)
N1.end_fill()
N1.forward(50)
N1.fillcolor("black")
N1.begin_fill()
N1.width(2)
for i in range(0,4):
N1.forward(50)
N1.right(90)
N1.end_fill()
N1.forward(50)

for i in range (0,4):
N2.fillcolor("black")
N2.begin_fill()
N2.width(2)
for i in range(0,4):
N2.forward(50)
N2.right(90)
N2.end_fill()
N2.forward(50)
N2.fillcolor("white")
N2.begin_fill()
N2.width(2)
for i in range(0,4):
N2.forward(50)
N2.right(90)
N2.end_fill()
N2.forward(50)

for i in range (0,4):
N3.fillcolor("white")
N3.begin_fill()
N3.width(2)
for i in range(0,4):
N3.forward(50)
N3.right(90)
N3.end_fill()
N3.forward(50)
N3.fillcolor("black")
N3.begin_fill()
N3.width(2)
for i in range(0,4):
N3.forward(50)
N3.right(90)
N3.end_fill()
N3.forward(50)

for i in range (0,4):
N4.fillcolor("black")
N4.begin_fill()
N4.width(2)
for i in range(0,4):
N4.forward(50)
N4.right(90)
N4.end_fill()
N4.forward(50)
N4.fillcolor("white")
N4.begin_fill()
N4.width(2)
for i in range(0,4):
N4.forward(50)
N4.right(90)
N4.end_fill()
N4.forward(50)

for i in range (0,4):
N5.fillcolor("white")
N5.begin_fill()
N5.width(2)
for i in range(0,4):
N5.forward(50)
N5.right(90)
N5.end_fill()
N5.forward(50)
N5.fillcolor("black")
N5.begin_fill()
N5.width(2)
for i in range(0,4):
N5.forward(50)
N5.right(90)
N5.end_fill()
N5.forward(50)

for i in range (0,4):
N6.fillcolor("black")
N6.begin_fill()
N6.width(2)
for i in range(0,4):
N6.forward(50)
N6.right(90)
N6.end_fill()
N6.forward(50)
N6.fillcolor("white")
N6.begin_fill()
N6.width(2)
for i in range(0,4):
N6.forward(50)
N6.right(90)
N6.end_fill()
N6.forward(50)

for i in range (0,4):
N7.fillcolor("white")
N7.begin_fill()
N7.width(2)
for i in range(0,4):
N7.forward(50)
N7.right(90)
N7.end_fill()
N7.forward(50)
N7.fillcolor("black")
N7.begin_fill()
N7.width(2)
for i in range(0,4):
N7.forward(50)
N7.right(90)
N7.end_fill()
N7.forward(50)

for i in range (0,4):
N8.fillcolor("black")
N8.begin_fill()
N8.width(2)
for i in range(0,4):
N8.forward(50)
N8.right(90)
N8.end_fill()
N8.forward(50)
N8.fillcolor("white")
N8.begin_fill()
N8.width(2)
for i in range(0,4):
N8.forward(50)
N8.right(90)
N8.end_fill()
N8.forward(50)

abcisse = 0#Définition des variables
ordonné = 0
compteurBoucleN1 = 0
positionementX = 0
positionementY = 0

échiquier()#Affichage de l'échiquier
tl.mainloop()

abcisse = randint (1,11)#L'ordinateur génère une position au bateau
ordonné = randint (1,11)
print("A vous de jouez")
while compteurBoucleN1 < 10 :#La boucle se joue dix fois à moins que le bateau soit coulé

x = int(input())#L'utilisateur choisist une position pour son tir
y = int(input())
if x<5:#Le programme calcul la cellule sur laquel l'utilisateur à tiré
positionementX = x*50-250
else :
positionementX = x*50
if y<5:
positionementY = y*50-250
else :
positionementY = y*50

tl.up()#Le programme place la tortue à la cellule chosit
tl.goto(positionementX,positionementY)
tl.down()
if x == abcisse and y == ordonné:#Cas où l'utilisateur coule le bateau
tl.circle(10)
tl.mainloop()
compteurBoucleN1 = 11 #Si l'utilisateur gagne le programme n'affichera pas la position du bateau
elif (x == abcisse-1 or x == abcisse or x == abcisse+1) and (y == ordonné-1 or y == ordonné or y == ordonné+1) :#Cas où l'utilisateur touche une cellule adjacente au bateau
tl.circle(20)
tl.mainloop()
elif x == abcisse or y == ordonné:#Cas où l'utilisateur touche une cellule dans la même ligne que le bateau
tl.circle(30)
tl.mainloop()
else :
tl.circle(40)#Cas où la cellule chosit n'a aucune spécificité
tl.mainloop()
compteurBoucleN1 = compteurBoucleN1+1 #Le compteur avance

fin de boucle
if compteurBoucleN1 == 10:#L'ordianteur affiche la position du bateau en cas de défaite
print ("La position du bateau était " + str(abcisse)+","+str(ordonné))

Je peut lancer le programme, l'échiquier se dessine et je peut saisir la première position sur laquelle je souhaite tiré mais à ce moment le programme se stop.
Le message d'erreur est le suivant

Traceback (most recent call last):
File "<string>", line 420, in run_nodebug
File "D:\Programmation\Apprentissage\Python\Programes ISN\BATNAV V2.py", line 225, in <module>
tl.up()#Le programme place la tortue à la cellule chosit
File "<string>", line 5, in up
turtle.Terminator

Merci beaucoup pour l'aide ;)

Exacompta
Exacompta
Niveau 10
17 novembre 2018 à 03:55:23

C'est illisible mis comme ça, tu nous donnes du python mais y a pas d’indentation en plus d'être un énorme pavé.

Sous forums
  • Aide à l'achat Mac
  • Internet
  • Macintosh
  • Création de sites web
  • Création de Jeux
  • Linux
  • Programmation
  • Steam Deck
  • Hardware
La vidéo du moment