finished the documentation
This commit is contained in:
parent
9f832afbe5
commit
87a3d7d493
17 changed files with 94 additions and 23 deletions
1
NOTE.md
1
NOTE.md
|
@ -1,5 +1,4 @@
|
|||
1. Principal :
|
||||
- Documenter (Docstring, ...)
|
||||
- mode d'emploi (video + pdf) expliquant le fonctionnement
|
||||
|
||||
2. Bonus :
|
||||
|
|
|
@ -20,6 +20,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class Game(BaseGame):
|
||||
"""
|
||||
Scène sur laquelle deux joueurs s'affrontent en réseau
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window",
|
||||
thread: StoppableThread,
|
||||
connection: socket.socket,
|
||||
|
@ -112,9 +116,9 @@ class Game(BaseGame):
|
|||
font_size=20
|
||||
)
|
||||
|
||||
self._my_turn = my_turn # is it the player turn ?
|
||||
self._boat_ready_ally: bool = False # does the player finished placing his boat ?
|
||||
self._boat_ready_enemy: bool = False # does the opponent finished placing his boat ?
|
||||
self._my_turn = my_turn # est-ce au tour de ce joueur ?
|
||||
self._boat_ready_ally: bool = False # le joueur à t'il fini de placer ses bateaux ?
|
||||
self._boat_ready_enemy: bool = False # l'opposant à t'il fini de placer ses bateaux ?
|
||||
|
||||
if len(self.boats_length) == 0: # s'il n'y a pas de bateau à placé
|
||||
self._boat_ready_ally = True # défini l'état de notre planche comme prête
|
||||
|
@ -175,7 +179,7 @@ class Game(BaseGame):
|
|||
self._boat_ready_enemy = boat_ready_enemy
|
||||
self._refresh_turn_text()
|
||||
|
||||
# function
|
||||
# fonction
|
||||
|
||||
def to_json(self) -> dict:
|
||||
return {
|
||||
|
@ -220,6 +224,7 @@ class Game(BaseGame):
|
|||
|
||||
@property
|
||||
def save_path(self) -> Path:
|
||||
# renvoie le chemin du fichier de sauvegarde
|
||||
ip_address, port = self.connection.getpeername()
|
||||
|
||||
return path_save / (
|
||||
|
@ -230,6 +235,7 @@ class Game(BaseGame):
|
|||
|
||||
@property
|
||||
def history_path(self):
|
||||
# renvoie le chemin du fichier d'historique
|
||||
return path_history / (
|
||||
datetime.now().strftime("%Y-%m-%d %H-%M-%S") +
|
||||
self.get_save_suffix() +
|
||||
|
@ -237,10 +243,12 @@ class Game(BaseGame):
|
|||
)
|
||||
|
||||
def save_to_path(self, path: Path):
|
||||
# enregistre la partie dans un fichier
|
||||
with open(path, "w", encoding="utf-8") as file:
|
||||
json.dump(self.to_json(), file, ensure_ascii=False)
|
||||
|
||||
def save(self, value: bool):
|
||||
# fonction de callback lorsque l'adversaire accepte ou refuse la demande de sauvegarde
|
||||
self.chat_new_message(
|
||||
"System",
|
||||
"Sauvegarde de la partie..." if value else "Sauvegarde de la partie refusé.",
|
||||
|
@ -266,6 +274,7 @@ class Game(BaseGame):
|
|||
self.thread.stop()
|
||||
|
||||
def chat_new_message(self, author: str, content: str, system: bool = False):
|
||||
# envoie un message dans le chat
|
||||
deco_left, deco_right = "<>" if system else "[]"
|
||||
message: str = f"{deco_left}{author}{deco_right} - {content}"
|
||||
self.chat_log.text += "\n" + message
|
||||
|
@ -275,9 +284,11 @@ class Game(BaseGame):
|
|||
# network
|
||||
|
||||
def network_on_chat(self, packet: PacketChat):
|
||||
# lorsque l'adversaire envoie un message
|
||||
self.chat_new_message(self.name_enemy, packet.message)
|
||||
|
||||
def network_on_boat_placed(self, packet: PacketBoatPlaced):
|
||||
# lorsque l'adversaire indique avoir placé tous ses bateaux
|
||||
self.boat_ready_enemy = True
|
||||
|
||||
def network_on_bomb_placed(self, packet: PacketBombPlaced):
|
||||
|
@ -315,6 +326,7 @@ class Game(BaseGame):
|
|||
self.game_end(won=False)
|
||||
|
||||
def network_on_bomb_state(self, packet: PacketBombState):
|
||||
# lorsque l'adversaire indique si la bombe à touché ou non
|
||||
if packet.bomb_state is BombState.ERROR:
|
||||
# si une erreur est survenue, on rejoue
|
||||
self.my_turn = True
|
||||
|
@ -343,12 +355,14 @@ class Game(BaseGame):
|
|||
self.game_end(won=True)
|
||||
|
||||
def network_on_quit(self, packet: PacketQuit):
|
||||
# lorsque l'adversaire souhaite quitter
|
||||
self.thread.stop() # coupe la connexion
|
||||
|
||||
from source.gui.scene import GameError
|
||||
self.window.set_scene(GameError, text="L'adversaire a quitté la partie.")
|
||||
|
||||
def network_on_ask_save(self, packet: PacketAskSave):
|
||||
# lorsque l'opposant souhaite sauvegarder
|
||||
now = datetime.now()
|
||||
|
||||
if self.save_cooldown is not None: # si un cooldown est défini
|
||||
|
|
|
@ -10,6 +10,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class GameError(Scene):
|
||||
"""
|
||||
Cette scène affiche une erreur
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", text: str, **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class GameLoad(Scene):
|
||||
"""
|
||||
Cette scène affiche une proposition de chargement d'une ancienne sauvegarde
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", path: Path, thread_host: Host, **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class GameQuit(Popup):
|
||||
"""
|
||||
Cette scène affiche une confirmation pour quitter la partie
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", game_scene: "Game", **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from typing import TYPE_CHECKING
|
|||
|
||||
import pyglet.clock
|
||||
|
||||
from source.gui import texture, widget, media
|
||||
from source.gui import texture, widget
|
||||
from source.gui.position import vw_full, vh_full
|
||||
from source.gui.scene.abc.Popup import Popup
|
||||
|
||||
|
@ -12,6 +12,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class GameResult(Popup):
|
||||
"""
|
||||
Cette scène affiche une animation de victoire ou de défaite
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", game_scene: "Game", won: bool, **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class GameSave(Popup):
|
||||
"""
|
||||
Cette scène affiche une proposition de sauvegarde de la partie
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", game_scene: "Game", **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class GameWaitLoad(Scene):
|
||||
"""
|
||||
Cette scène sert de salle d'attente pour le client qui attend de charger ou non sa sauvegarde
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", path: Path, **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class HistoryGame(BaseGame):
|
||||
"""
|
||||
Cette scène sert à afficher une ancienne partie
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", history_path: Path, **kwargs):
|
||||
|
||||
with open(history_path, "r", encoding="utf8") as file:
|
||||
|
@ -94,8 +98,9 @@ class HistoryGame(BaseGame):
|
|||
|
||||
self._refresh_move_text()
|
||||
|
||||
# event
|
||||
# événement
|
||||
|
||||
def on_mouse_scroll(self, x: int, y: int, scroll_x: float, scroll_y: float):
|
||||
# lorsque la molette est utilisée, affiche le mouvement précédent ou le mouvement suivant
|
||||
for _ in range(abs(int(scroll_y))):
|
||||
self.next_move() if scroll_y < 0 else self.previous_move()
|
||||
|
|
|
@ -14,6 +14,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class HistoryMenu(Scene):
|
||||
"""
|
||||
Cette scène affiche toutes les anciennes parties et permet de les revisionner
|
||||
"""
|
||||
|
||||
PAGE_SIZE: int = 8
|
||||
|
||||
def __init__(self, window: "Window", page: int = 0, **kwargs):
|
||||
|
|
|
@ -9,6 +9,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class MainMenu(Scene):
|
||||
"""
|
||||
Cette scène représente le menu principal
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class RoomCreate(Scene):
|
||||
"""
|
||||
Cette scène sert à paramétrer la partie avant de la lancer
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
@ -59,7 +63,7 @@ class RoomCreate(Scene):
|
|||
label_text="52321"
|
||||
)
|
||||
|
||||
# Username
|
||||
# Pseudo
|
||||
|
||||
self.add_widget(
|
||||
widget.Text,
|
||||
|
@ -84,7 +88,7 @@ class RoomCreate(Scene):
|
|||
label_text="Host"
|
||||
)
|
||||
|
||||
# Grid configuration
|
||||
# configuration de la grille
|
||||
|
||||
self.add_widget(
|
||||
widget.Text,
|
||||
|
|
|
@ -14,6 +14,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class RoomHost(Scene):
|
||||
"""
|
||||
Cette scène sert à attendre un second joueur pour l'hôte après avoir configuré la partie
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", port: int, username: str, settings: "PacketSettings", **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
|
|
@ -10,6 +10,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class RoomJoin(Scene):
|
||||
"""
|
||||
Cette scène sert à se connecter à un hôte pour lancer une partie
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from math import inf
|
|||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from source.gui import widget, texture, media
|
||||
from source.gui import widget, texture
|
||||
from source.gui.position import vw_full, vh_full, vw, vh
|
||||
from source.gui.scene.abc.Popup import Popup
|
||||
|
||||
|
@ -11,6 +11,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class Settings(Popup):
|
||||
"""
|
||||
Cette scène sert à changer les paramètres graphique et audio de la partie
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class BaseGame(Scene, ABC):
|
||||
"""
|
||||
La classe de base pour les scènes représentant le jeu principal (une grille alliée, une grille ennemie)
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window",
|
||||
boats_length: list,
|
||||
name_ally: str,
|
||||
|
@ -129,5 +133,6 @@ class BaseGame(Scene, ABC):
|
|||
)
|
||||
|
||||
def _refresh_score_text(self):
|
||||
# rafraichi le score allié et ennemie
|
||||
self.score_ally.text = str(self.grid_enemy.board.get_score())
|
||||
self.score_enemy.text = str(self.grid_ally.board.get_score())
|
||||
|
|
|
@ -13,10 +13,10 @@ if TYPE_CHECKING:
|
|||
|
||||
class Scene(ABC, EventPropagationMixin):
|
||||
"""
|
||||
A scene that can be attached to a window.
|
||||
It allows to switch the whole comportment of the window in a simpler way.
|
||||
Une scène pouvant être attaché à une fenêtre.
|
||||
Permet de changer le comportement entier et les widgets de la fenêtre plus simplement.
|
||||
|
||||
It can react to any "on_" event from the window.
|
||||
Il peut réagir à n'importe quel événement de pyglet d'une fenêtre.
|
||||
"""
|
||||
|
||||
def __init__(self, window: "Window", **kwargs):
|
||||
|
@ -35,11 +35,11 @@ class Scene(ABC, EventPropagationMixin):
|
|||
|
||||
def add_widget(self, widget_class: Type["Widget"], priority: int = 0, **widget_kwargs):
|
||||
"""
|
||||
Add a widget to the scene.
|
||||
:param widget_class: the class of the widget to add.
|
||||
:param priority: the priority of the widget.
|
||||
:param widget_kwargs: kwargs for the creation of the widget object.
|
||||
:return: the new created widget.
|
||||
Ajoute un widget à la scène
|
||||
:param widget_class: La classe du widget à ajouter
|
||||
:param priority: la priorité du widget (force un widget à apparaître au-dessus des autres)
|
||||
:param widget_kwargs: les arguments clé de la création du widget
|
||||
:return: le widget créé
|
||||
"""
|
||||
|
||||
widget: "Widget" = widget_class(self, **widget_kwargs)
|
||||
|
@ -48,15 +48,15 @@ class Scene(ABC, EventPropagationMixin):
|
|||
|
||||
def remove_widget(self, widget: "Widget") -> None:
|
||||
"""
|
||||
Remove a widget from the scene.
|
||||
:param widget: the widget to remove.
|
||||
Retire un widget de la scène
|
||||
:param widget: le widget à retirer
|
||||
"""
|
||||
|
||||
self._widgets.remove(widget)
|
||||
|
||||
def clear_widget(self) -> None:
|
||||
"""
|
||||
Clear the scene from all the widgets.
|
||||
Supprime de la scène tous les widgets
|
||||
"""
|
||||
|
||||
self._widgets.clear()
|
||||
|
@ -66,7 +66,7 @@ class Scene(ABC, EventPropagationMixin):
|
|||
@property
|
||||
def valid(self) -> bool:
|
||||
"""
|
||||
Indique si la scène à tout ses éléments de formulaire valides
|
||||
Indique si la scène à tous ses éléments de formulaire valides
|
||||
:return: True si tous les éléments (Input, ...) sont correctement rempli.
|
||||
"""
|
||||
|
||||
|
@ -79,7 +79,7 @@ class Scene(ABC, EventPropagationMixin):
|
|||
|
||||
def on_draw(self) -> None:
|
||||
"""
|
||||
Draw all the objects in the scene.
|
||||
Dessines tous les objets de la scène
|
||||
"""
|
||||
|
||||
self.batch.draw()
|
||||
|
|
Loading…
Reference in a new issue