Niveau Intermédiaire [Rendre Les Objets Intelligents Grâce à Python]
Maybe your like
le jeu de bataille navale - Niveau intermédiaire
Dans cette simulation de jeu de bataille navale, nous utiliserons deux cartes. La première sera l'ordinateur et contiendra deux bateaux placés aléatoirement et la seconde sera pour le joueur qui essayera de couler les bateaux. La partie se termine quand les bateaux sont coulés.
La liaison radio est mise à contribution pour la communication du début de la partie, de la fin de partie, les tirs et les résultats des tirs.
Ce projet commence à être ambitieux pour une réalisation dans le cadre de SNT.
Méthode : Version ordinateur
Le bouton A permet de décider un autre placement
Le bouton B permet de démarrer la partie
Des bruitages sont joués lorsqu'un haut-parleur est connecté sur pin0.
1# Olivier Lecluse2# 8 mars 20193# version ordi45from random import randint6from microbit import *7import radio,music89radio.config(group=1)10radio.on()1112boats = []13gameOn = False1415def placer():16 global boats17 boats=[]18 h=randint(0,1)19 if h==0: # bateau de 3 horizontal20 x3=randint(0,2)21 y3=randint(0,4)22 boats.append((x3,y3))23 boats.append((x3+1,y3))24 boats.append((x3+2,y3))25 else: # bateau de 3 vertical26 x3=randint(0,4)27 y3=randint(0,2)28 boats.append((x3,y3))29 boats.append((x3,y3+1))30 boats.append((x3,y3+2))3132 cont = True33 while cont :34 if h==0: # bateau de 2 verrtical35 x2=randint(0,4)36 y2=randint(0,3)37 if (x2,y2) not in boats and (x2, y2+1) not in boats:38 boats.append((x2,y2))39 boats.append((x2,y2+1))40 cont=False41 else: # bateau de 2 horizontal42 x2=randint(0,3)43 y2=randint(0,4)44 if (x2,y2) not in boats and (x2+1, y2) not in boats:45 boats.append((x2,y2))46 boats.append((x2+1,y2))47 cont=False4849def afficher():50 display.clear()51 for b in boats:52 display.set_pixel(b[0],b[1],9)5354placer()55afficher()56while True:57 if button_a.was_pressed() and not gameOn:58 placer()59 afficher()60 if button_b.was_pressed() and not gameOn:61 gameOn = True62 radio.send("GO")63 music.play(music.POWER_UP)64 if gameOn:65 # la partie est en cours6667 # Gestion de l'arrivee d'un coup68 incoming = radio.receive()69 if incoming:70 try:71 hx,hy = incoming.split(',')72 hit=(int(hx),int(hy))73 except:74 continue75 if (hit) in boats:76 boats.remove(hit)77 radio.send("HIT")78 music.pitch(1000, 500)79 color=080 else:81 radio.send("MISS")82 music.pitch(200, 500)83 color=284 display.set_pixel(hit[0], hit[1], color)8586 # Fin de la partie87 if len(boats)==0:88 radio.send("GAME OVER")89 music.play(music.FUNERAL)90 gameOn=False91# Olivier Lecluse # 8 mars 2019 # version ordi from random import randint from microbit import * import radio,music radio.config(group=1) radio.on() boats = [] gameOn = False def placer(): global boats boats=[] h=randint(0,1) if h==0: # bateau de 3 horizontal x3=randint(0,2) y3=randint(0,4) boats.append((x3,y3)) boats.append((x3+1,y3)) boats.append((x3+2,y3)) else: # bateau de 3 vertical x3=randint(0,4) y3=randint(0,2) boats.append((x3,y3)) boats.append((x3,y3+1)) boats.append((x3,y3+2)) cont = True while cont : if h==0: # bateau de 2 verrtical x2=randint(0,4) y2=randint(0,3) if (x2,y2) not in boats and (x2, y2+1) not in boats: boats.append((x2,y2)) boats.append((x2,y2+1)) cont=False else: # bateau de 2 horizontal x2=randint(0,3) y2=randint(0,4) if (x2,y2) not in boats and (x2+1, y2) not in boats: boats.append((x2,y2)) boats.append((x2+1,y2)) cont=False def afficher(): display.clear() for b in boats: display.set_pixel(b[0],b[1],9) placer() afficher() while True: if button_a.was_pressed() and not gameOn: placer() afficher() if button_b.was_pressed() and not gameOn: gameOn = True radio.send("GO") music.play(music.POWER_UP) if gameOn: # la partie est en cours # Gestion de l'arrivee d'un coup incoming = radio.receive() if incoming: try: hx,hy = incoming.split(',') hit=(int(hx),int(hy)) except: continue if (hit) in boats: boats.remove(hit) radio.send("HIT") music.pitch(1000, 500) color=0 else: radio.send("MISS") music.pitch(200, 500) color=2 display.set_pixel(hit[0], hit[1], color) # Fin de la partie if len(boats)==0: radio.send("GAME OVER") music.play(music.FUNERAL) gameOn=FalseMéthode : Version Joueur
Le bouton A déplace la cible verticalement
Le bouton B déplace la cible horizontalement
Une secousse déclenche le tir
- Précédent
- Suivant
- Introduction
- Adafruit ? CircuitPython ?
- Découverte de CircuitPython avec edublocks
- de l'Arduino vers CircuitPython
- projets CPX
- Projets divers autour de CircuitPython
- Graphisme sous CircuitPython - utilisation de displayio
- Fabriquer sa console de jeu - Niveau avancé
- Objets connectés (IoT) - MicroPython sur ESP8266 et ESP32
- Micropython sur la carte BBC micro::bit
- Introduction
- Utiliser l'éditeur Mu
- kit de survie de la carte microbit sous MicroPython
- Activités de prise en main de la micro:bit
- Mini-projets sur Microbit
- Réaliser un compteur - niveau facile
- Jeu de Pierre Feuille Ciseaux
- Robot Maqueen eviteur d'obstacles - Niveau débutant
- rob_hot : le robot guidé à la chaleur - niveau intermédiaire
- Robot Maqueen télécommandé - Niveau intermédiaire
- Alerte canicule ! - niveau facile
- Simulation d'un feu de chantier pour la circulation automobile
- Mesurer la vitesse du son
- Lire un GPS avec la carte micro:bit - Niveau intermédiaire
- le jeu de bataille navale - Niveau intermédiaire
- Jeu de tir : scudFighter - Niveau intermédiaire
- La roue codeuse - Niveau intermédiaire
- Effet stroboscopique - Niveau intermédiaire
- Accueil
- Module
Tag » Code Bataille Navale Python
-
Une Bataille Navale Codée En Python Sur NumWorks - Nsi.xyz
-
TP3 Bataille Navale
-
Bataille Navale Entierement Sur Python - OpenClassrooms
-
Bataille Navale Python
-
[PDF] Jeu De Bataille Navale [sr07] - Examen - Unisciel
-
[PDF] Travaux Pratiques Initiation à La Programmation Avec Python Feuille ...
-
Bataille Navale Python - YouTube
-
Live Coding Spécial 1k. On Code Une Bataille Navale ! - YouTube
-
Une Bataille Navale Réalisée En Python Avec La Librairie Pygame.
-
[PDF] Séance 10: Bataille Navale - IRIF
-
Nclv/Battleship: Bataille Navale PVP / PVE - GitHub
-
Tutoriel Sur La Programmation Python Bataille Navale - Cours-Gratuit
-
Python : Bataille Navale En Local Ou En Reseau :d - CodeS SourceS
-
[PDF] Bataille Navale