Skip to content

Commit 9686ad2

Browse files
authored
Merge pull request #9 from Tracks12/dev
2.3
2 parents d4ce664 + 7670c72 commit 9686ad2

File tree

15 files changed

+367
-172
lines changed

15 files changed

+367
-172
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
.venv/
12
__pycache__/
23
*.pyc
4+
5+
saves/*.map

README.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22

33
Le jeu de la vie de John Horton Conway
44

5-
Pour en connaître un peu plus, vous pouvez visiter la page **[Wikipedia](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)** du jeu de la vie.
5+
> [!Note]
6+
> Pour en connaître un peu plus, vous pouvez visiter la page **[Wikipedia](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)** du jeu de la vie.
67
78
## Sommaire
89

9-
1. [Consignes](#consignes)
10-
2. [Pré-requis](#pré-requis)
11-
- [Dépendances](#dépendances)
12-
3. [Utilisations](#utilisations)
13-
4. [Sauvegarde](#sauvegarde)
14-
- [Les entités](#les-entités)
15-
5. [Exemples d'utilisations](#exemples-dutilisations)
16-
- [Aperçu](#aperçu)
17-
- [Remarque](#remarque)
18-
6. [Licence](#licence)
10+
- [**conwayGameOfLife**](#conwaygameoflife)
11+
- [Sommaire](#sommaire)
12+
- [Consignes](#consignes)
13+
- [Pré-requis](#pré-requis)
14+
- [Dépendances](#dépendances)
15+
- [Utilisations](#utilisations)
16+
- [Sauvegarde](#sauvegarde)
17+
- [Les entités](#les-entités)
18+
- [Exemples d'utilisations](#exemples-dutilisations)
19+
- [Aperçu](#aperçu)
20+
- [Remarque](#remarque)
21+
- [Licence](#licence)
1922

2023
## Consignes
2124

@@ -27,17 +30,23 @@ La liste des consignes du sujet est disponible dans le [todo.md](todo.md)
2730

2831
L'installation de **[Python 3](https://www.python.org/downloads/)** est recommandé pour l'éxécution du script
2932

33+
> [!Note]
34+
> Une fois l'installation de **[Python 3](https://www.python.org/downloads/)** terminée, tapez `$ pip install -r requirements.txt` dans un terminal à la racine du projets pour installer toutes les dépendances du projet
35+
3036
[Sommaire](#sommaire)
3137

3238
### Dépendances
3339

34-
- [base64.b64decode](https://docs.python.org/3/library/base64.html#base64.b64decode), [base64.b64encode](https://docs.python.org/3/library/base64.html#base64.b64encode)
35-
- [json.dumps](https://docs.python.org/3/library/json.html#json.dumps), [json.loads](https://docs.python.org/3/library/json.html#json.loads)
36-
- [os.system](https://docs.python.org/3/library/os.html#os.system)
37-
- [sys.argv](https://docs.python.org/3/library/sys.html#sys.argv), [sys.version_info](https://docs.python.org/3/library/sys.html#sys.version_info)
38-
- [platform.system](https://docs.python.org/3/library/platform.html#platform.system)
39-
- [time.sleep](https://docs.python.org/3/library/time.html#time.sleep)
40-
- [zlib.compress](https://docs.python.org/3/library/zlib.html#zlib.compress), [zlib.decompress](https://docs.python.org/3/library/zlib.html#zlib.decompress)
40+
- [base64](https://docs.python.org/3/library/base64.html)
41+
- [json](https://docs.python.org/3/library/json.html)
42+
- [keyboard](https://pypi.org/project/keyboard/) (For Windows system)
43+
- [os](https://docs.python.org/3/library/os.html)
44+
- [sys](https://docs.python.org/3/library/sys.html)
45+
- [platform](https://docs.python.org/3/library/platform.html)
46+
- [termios](https://docs.python.org/3/library/termios.html) (For Linux system)
47+
- [tty](https://docs.python.org/3/library/tty.html) (For Linux system)
48+
- [time](https://docs.python.org/3/library/time.html)
49+
- [zlib](https://docs.python.org/3/library/zlib.html)
4150

4251
[Sommaire](#sommaire)
4352

@@ -46,31 +55,31 @@ L'installation de **[Python 3](https://www.python.org/downloads/)** est recomman
4655
| Fonctionnalités | Commandes |
4756
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------ |
4857
| Exécuter le script | `$ python main.py` |
49-
| Créer une nouvelle map | `$ python main.py -n <mapName> <x> <y>`<br />`$ python main.py --new <mapName> <x> <y>` |
5058
| Insérer une ou plusieurs cellule(s) | `$ python main.py -a <mapName> "[(x, y), ...]"`<br />`$ python main.py --add <mapName> "[(x, y), ...]"` |
5159
| Insérer une entité | `$ python main.py -A <mapName> <type> <x> <y>`<br />`$ python main.py --add-entity <mapName> <type> <x> <y>` |
5260
| Afficher une map enregistrée | `$ python main.py -d <mapName>`<br />`$ python main.py --display <mapName>` |
61+
| Lister les maps sauvegardés | `$ python main.py -l`<br />`$ python main.py --list` |
62+
| Créer une nouvelle map | `$ python main.py -n <mapName> <x> <y>`<br />`$ python main.py --new <mapName> <x> <y>` |
5363
| Réinitialiser une map | `$ python main.py -r <mapName>`<br />`$ python main.py --reset <mapName>` |
5464
| Jouer une map | `$ python main.py -s <mapName>`<br />`$ python main.py --start <mapName>` |
5565

5666
[Sommaire](#sommaire)
5767

5868
## Sauvegarde
5969

60-
Les maps générées sont sauvegardées de manière automatique après chaque mise à jour de celle-ci dans un fichier **.map** portant le nom de la map dans le répertoire **[saves/](saves/)** (_exemple: **[world.map](saves/world.map)**_)
70+
Les maps générées sont sauvegardées de manière automatique après chaque mise à jour de celle-ci dans un fichier **.map** portant le nom de la map dans le répertoire **[saves](saves/)** (_exemple: **[world.map](saves/world.map)**_)
6171

6272
[Sommaire](#sommaire)
6373

6474
### Les entités
6575

66-
De même que pour la map, les entités sont stockées dans le fichier **[entity.json](entity.json)**
76+
De même que pour la map, les entités sont stockées dans le dossier **[entities](entities/)**
6777

68-
Si vous voulez ajouter des entités dans le fichier, vous pouvez le faire en suivant le formatage de positionnement relatif avec les coordonnées **x** et **y** comme dans l'exemple ci dessous:
78+
Si vous voulez ajouter des entités dans le fichier, vous pouvez le faire en suivant le formatage de positionnement relatif avec les coordonnées **x** et **y** comme dans l'exemple ci dessous pour l'entité "block":
6979

7080
```json
7181
{
72-
"nom de l'entité": "[(x, y), (x, y+1), (x+1, y), (x+1, y+1)]",
73-
...
82+
"block": "[(x, y), (x, y+1), (x+1, y), (x+1, y+1)]"
7483
}
7584
```
7685

@@ -99,11 +108,12 @@ Et on lance le jeu avec `$ python main.py` en entrant le nom de la map que l'on
99108
### Remarque
100109

101110
- Vous pouvez checker votre configuration avec `$ python main.py -d world` pour afficher la map avec vos cellules actives
102-
- Depuis la version 2.0, vous pouvez maintenant enregistrer une entité complète dans **[entity.json](entity.json)** et l'ajouter sur la map comme ceci:
111+
- Depuis la version 2.0, vous pouvez maintenant enregistrer une entité complète dans le dossier **[entities](entities)** et l'ajouter sur la map comme ceci:
103112
- **Départ de floraison**: `$ python main.py -A world flowering 25 25`
104113
- **Le clown**: `$ python main.py -A world clown 25 25`
105114

106-
Si vous voulez entièrement la réinitialiser, `$ python main.py -r world` remet toutes les cellules d'une map à 0
115+
> [!Tip]
116+
> Si vous voulez entièrement la réinitialiser, `$ python main.py -r world` remet toutes les cellules d'une map à 0
107117
108118
[Sommaire](#sommaire)
109119

core/__init__.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@
44
from base64 import b64decode, b64encode
55
from platform import system
66

7-
CMD_CLEAR = "clear" if(system() == "Linux") else "cls" # Commande de nettoyage de la console
7+
class SystemEnum:
8+
LINUX = "Linux"
9+
WINDOWS = "Windows"
810

9-
class Colors: # Module de coloration pour les système Linux/Unix
10-
if(system() == "Linux"):
11-
bold = "\033[1m"
12-
italic = "\033[3m"
11+
SYSTEM = system()
12+
_isLinux = bool(SYSTEM == SystemEnum.LINUX)
13+
14+
CMD_CLEAR = "clear" if(_isLinux) else "cls" # Commande de nettoyage de la console
1315

14-
red = "\033[31m"
15-
green = "\033[32m"
16-
yellow = "\033[33m"
17-
blue = "\033[34m"
18-
purple = "\033[35m"
19-
cyan = "\033[36m"
20-
white = "\033[37m"
16+
class Colors: # Module de coloration pour les système Linux/Unix
17+
bold = "\033[1m" if(_isLinux) else ""
18+
italic = "\033[3m" if(_isLinux) else ""
2119

22-
end = "\033[0m"
20+
red = "\033[31m" if(_isLinux) else ""
21+
green = "\033[32m" if(_isLinux) else ""
22+
yellow = "\033[33m" if(_isLinux) else ""
23+
blue = "\033[34m" if(_isLinux) else ""
24+
purple = "\033[35m" if(_isLinux) else ""
25+
cyan = "\033[36m" if(_isLinux) else ""
26+
white = "\033[37m" if(_isLinux) else ""
2327

24-
else:
25-
bold = italic = end = ""
26-
red = green = yellow = blue = purple = cyan = white = ""
28+
end = "\033[0m" if(_isLinux) else ""
2729

2830
class Icons: # Module d'icône ascii
2931
# Icônes fixes
@@ -33,11 +35,11 @@ class Icons: # Module d'icône ascii
3335

3436
# Icônes de chargement
3537
succ = f" [{Colors.bold}{Colors.green}*{Colors.end}] "
36-
fail = f" [{Colors.bold}{Colors.red}*{Colors.end}] "
38+
fail = f" [{Colors.bold}{Colors.red}x{Colors.end}] "
3739

3840
class B64: # Encode/Decode ascii string in base64
39-
def encode(str = ""):
41+
def encode(str: str = "") -> bytes:
4042
return(b64encode(str.encode("ascii")))
4143

42-
def decode(str = ""):
44+
def decode(str: bytes = "") -> str:
4345
return(b64decode(str).decode("ascii"))

core/entity.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,32 @@
44
# Module de l'objet Entity
55
# ce module contient les fonctionnalités de chargement des entités
66

7+
from os import listdir
78
from os.path import abspath, dirname
89

910
from core.loader import Loader
1011

1112
class Entity:
1213
def __init__(self):
13-
self.__path = str(f"{dirname(abspath(__file__))}/../entity.json")
14-
self.__entities = dict({})
14+
self.__path = str(f"{abspath(dirname(__file__))}/../entities")
15+
self.__entities = dict[str, str]({})
1516
self.loaded = bool(self.__loadJSON())
1617

17-
def __loadJSON(self): # Chargement des entités depuis un fichier
18+
def __loadJSON(self) -> bool: # Chargement des entités depuis le dossier "entities"
1819
try:
19-
with open(self.__path, 'r') as outFile:
20-
self.__entities = dict(Loader.json(outFile, ["Loading entities ...", "Entities loaded ! ", "Entities loading Failed !"]))
20+
print("Loading entities ...")
21+
for entity in [ e.split(".")[0] for e in listdir(self.__path) ]:
22+
with open(f"{self.__path}/{entity}.json", 'r') as outFile:
23+
self.__entities[entity] = Loader.json(outFile, [f"Loading {entity} ...", f"{entity} loaded ! ", f"{entity} loading Failed !"])[entity]
2124

25+
print("Entities loaded !")
2226
return(True)
2327

2428
except(Exception):
2529
return(False)
2630

27-
def __build(self, coord): # Build with relative position
28-
entities = dict(self.__entities)
31+
def __build(self, coord: tuple[int]) -> dict[str, str]: # Build with relative position
32+
entities = dict[str, str](self.__entities)
2933

3034
for name in entities:
3135
entities[name] = str(entities[name].replace("x", str(coord[0])))
@@ -34,13 +38,8 @@ def __build(self, coord): # Build with relative position
3438

3539
return(entities)
3640

37-
def getEntitiesName(self):
38-
names = []
41+
def getEntitiesName(self) -> list[str]:
42+
return([ str(e) for e in self.__entities ])
3943

40-
for name in self.__entities:
41-
names.append(str(name))
42-
43-
return(names)
44-
45-
def get(self, name, coord = (5, 5)): # Récupération d'une
44+
def get(self, name: str, coord: tuple[int] = (5, 5)) -> str: # Récupération d'une entité
4645
return(self.__build(coord)[name])

core/loader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
from core import B64, Colors, Icons
99

1010
class Loader: # Module de chargements
11-
def anim(msg):
11+
def anim(msg: str):
1212
arr = ['\\', '|', '/', '-']
1313

14-
for i in range(0, 10):
14+
for i in range(10):
1515
print(f" [{Colors.bold}{Colors.yellow}{arr[i % len(arr)]}{Colors.end}] {msg}", end = "\r")
16-
sleep(.05)
16+
sleep(.005)
1717

1818
def map(file, msg = ["", "", ""]): # Méthode de chargement pour fichier MAP
1919
Loader.anim(msg[0])

0 commit comments

Comments
 (0)