Code de base fourni dans l'ennonce du TP|TP_3.9|ADD roboc/

This commit is contained in:
Fred Z 2018-02-06 11:01:44 +01:00
parent a6438f4e6f
commit 6ef6604901
5 changed files with 87 additions and 0 deletions

14
roboc/carte-base.py Normal file
View File

@ -0,0 +1,14 @@
# -*-coding:Utf-8 -*
"""Ce module contient la classe Carte."""
class Carte:
"""Objet de transition entre un fichier et un labyrinthe."""
def __init__(self, nom, chaine):
self.nom = nom
self.labyrinthe = creer_labyrinthe_depuis_chaine(chaine)
def __repr__(self):
return "<Carte {}>".format(self.nom)

11
roboc/cartes/facile.txt Normal file
View File

@ -0,0 +1,11 @@
OOOOOOOOOO
O O O O
O . OO O
O O O XO
O OOOO O.O
O O O U
O OOOOOO.O
O O O
O O OOOOOO
O . O O
OOOOOOOOOO

20
roboc/cartes/prison.txt Normal file
View File

@ -0,0 +1,20 @@
OOOOOOOOOOOOOOOOOOOO
OXO . O O . O
O.O O O O O O
O O O O O O O
O.O O . O O O
O O O OOOOOO O O
O O O O O
O O OOOOOOOOOO O
O.O . O O
O O O O O
O O O O O
O O.O O O
O.O . O O
O O O O O
O O O O O
O O O O O
O O O O O
O.O O O O
O O O U
OOOOOOOOOOOOOOOOOOOO

12
roboc/labyrinthe-base.py Normal file
View File

@ -0,0 +1,12 @@
# -*-coding:Utf-8 -*
"""Ce module contient la classe Labyrinthe."""
class Labyrinthe:
"""Classe représentant un labyrinthe."""
def __init__(self, robot, obstacles):
self.robot = robot
self.grille = {}
# ...

30
roboc/roboc-base.py Normal file
View File

@ -0,0 +1,30 @@
# -*-coding:Utf-8 -*
"""Ce fichier contient le code principal du jeu.
Exécutez-le avec Python pour lancer le jeu.
"""
import os
from carte import Carte
# On charge les cartes existantes
cartes = []
for nom_fichier in os.listdir("cartes"):
if nom_fichier.endswith(".txt"):
chemin = os.path.join("cartes", nom_fichier)
nom_carte = nom_fichier[:-3].lower()
with open(chemin, "r") as fichier:
contenu = fichier.read()
# Création d'une carte, à compléter
# On affiche les cartes existantes
print("Labyrinthes existants :")
for i, carte in enumerate(cartes):
print(" {} - {}".format(i + 1, carte.nom))
# Si il y a une partie sauvegardée, on l'affiche, à compléter
# ... Complétez le programme ...