blender-edutech-ressources-.../Lycee/programmation_python/Ropy - SNT/Correction/rp_cmd-correction_mission_6...

102 lines
2.7 KiB
Python

from rp_lib import * # Bibliothèque Ropy
###############################################################################
# rp_cmd-correction_mission_6a.py
# @title: Commandes pour le Rover Ropy - Correction mission 6 en colimaçon
# @project: Ropy (Blender-EduTech)
###############################################################################
###############################################################################
# Initialisation du niveau :
# Niveau 1 : Les premiers pas de Ropy
# Niveau 2 : Ma première fonction
# Niveau 3 : Sécuriser Ropy
# Niveau 4 : Partir au bout du monde
# Niveau 5 : Faire face à l'inconnu
# Niveau 6 : Se rendre utile
###############################################################################
###############################################################################
# Fonctions
###############################################################################
# Avancer + marquer (mission 2) avec sécurisation (mission 3)
def mrp_avancer():
if rp_detect()==False:
rp_avancer()
rp_marquer()
# Avancer d'un nombre de pas (mission 4)
def mrp_avancer_nbpas(pas):
for i in range (pas):
mrp_avancer()
# Avancer jusqu'au mur (mission 5)
def mrp_avancer_mur():
while rp_detect()==False:
mrp_avancer()
# Aller à la case origine (mission 6)
def mrp_depart():
rp_gauche()
mrp_avancer_mur()
rp_droite()
mrp_avancer_mur()
rp_gauche()
mrp_avancer_mur()
rp_gauche()
# Faire un aller-retour (mission 6)
def mrp_aller_retour():
mrp_avancer_nbpas(9)
rp_gauche()
mrp_avancer()
rp_gauche()
mrp_avancer_nbpas(9)
rp_droite()
mrp_avancer()
rp_droite()
# Faire un carre (mission 6)
def mrp_carre(pas):
for i in range (4):
mrp_avancer_nbpas(pas)
rp_gauche()
# Avance d'une case en diagonale sud-ouest
def mrp_avancer_so():
rp_gauche()
mrp_avancer()
rp_droite()
mrp_avancer()
###############################################################################
# Commandes
###############################################################################
def commandes():
# Mission 6
mrp_depart()
# Objectif 6.2 (colimaçon)
nb_pas=9
for i in range (5):
mrp_carre(nb_pas)
mrp_avancer_so()
nb_pas=nb_pas-2
###############################################################################
# En: External call << DONT CHANGE THIS SECTION >>
# Fr: Appel externe << NE PAS MODIFIER CETTE SECTION >>
###############################################################################
def cycle():
commandes()
rp_fin()
if __name__=='start':
thread_cmd_start(cycle)
if __name__=='stop':
thread_cmd_stop()