Compare commits
No commits in common. "dev" and "simple" have entirely different histories.
@ -27,7 +27,6 @@ source env/bin/activate
|
|||||||
cloner le dépôt, aller dans le bon dossier
|
cloner le dépôt, aller dans le bon dossier
|
||||||
```
|
```
|
||||||
git clone https://mcstn.fr/gitea/Yann/Projet4.git
|
git clone https://mcstn.fr/gitea/Yann/Projet4.git
|
||||||
cd Projet4
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Exécution
|
## Exécution
|
||||||
|
@ -7,8 +7,8 @@ import json
|
|||||||
|
|
||||||
|
|
||||||
class Save:
|
class Save:
|
||||||
def __init__(self, view):
|
def __init__(self):
|
||||||
self.view = view
|
pass
|
||||||
|
|
||||||
def load_file(self, file):
|
def load_file(self, file):
|
||||||
try:
|
try:
|
||||||
@ -22,7 +22,7 @@ class Save:
|
|||||||
return data_tmp
|
return data_tmp
|
||||||
|
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
self.view.display_format_error()
|
print("Erreur de format sur le fichier")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ class Save:
|
|||||||
data_tmp = (self.load_file(PLAYERFILE))
|
data_tmp = (self.load_file(PLAYERFILE))
|
||||||
data_tmp.append(player)
|
data_tmp.append(player)
|
||||||
self.write_file(data_tmp, PLAYERFILE)
|
self.write_file(data_tmp, PLAYERFILE)
|
||||||
self.view.ok_player()
|
print("Joueur créé !")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def player_load(self) -> list:
|
def player_load(self) -> list:
|
||||||
@ -55,7 +55,7 @@ class Save:
|
|||||||
|
|
||||||
return data_list
|
return data_list
|
||||||
else:
|
else:
|
||||||
self.view.display_file_error("joueur")
|
print("\n**** Pas de fichier joueur trouvé :/\n")
|
||||||
|
|
||||||
def tournament_write(self, tournament):
|
def tournament_write(self, tournament):
|
||||||
data = {
|
data = {
|
||||||
@ -74,7 +74,7 @@ class Save:
|
|||||||
data_tmp = self.load_file(TOURNAMENTFILE)
|
data_tmp = self.load_file(TOURNAMENTFILE)
|
||||||
return data_tmp
|
return data_tmp
|
||||||
else:
|
else:
|
||||||
self.view.display_file_error("tournoi")
|
print("\n**** Pas de fichier tournoi trouvé :/ \n")
|
||||||
|
|
||||||
|
|
||||||
class Application:
|
class Application:
|
||||||
@ -89,8 +89,11 @@ class Application:
|
|||||||
def sort_by_score(self):
|
def sort_by_score(self):
|
||||||
self.tournament.players_list.sort(key=lambda t: t.score, reverse=True)
|
self.tournament.players_list.sort(key=lambda t: t.score, reverse=True)
|
||||||
|
|
||||||
|
def shuffle_players(self):
|
||||||
|
return shuffle(self.tournament.players_list)
|
||||||
|
|
||||||
def create_tournament(self):
|
def create_tournament(self):
|
||||||
"""update existing tournament with data from view"""
|
print("Nouveau tournoi ! \n")
|
||||||
tournament_details = self.view.prompt_for_tournament()
|
tournament_details = self.view.prompt_for_tournament()
|
||||||
self.tournament.name = tournament_details['name']
|
self.tournament.name = tournament_details['name']
|
||||||
self.tournament.location = tournament_details['location']
|
self.tournament.location = tournament_details['location']
|
||||||
@ -98,7 +101,6 @@ class Application:
|
|||||||
self.tournament.date_end = tournament_details['date_end']
|
self.tournament.date_end = tournament_details['date_end']
|
||||||
self.tournament.description = tournament_details['description']
|
self.tournament.description = tournament_details['description']
|
||||||
self.tournament.total_round = tournament_details['total_round']
|
self.tournament.total_round = tournament_details['total_round']
|
||||||
self.tournament.round_list = []
|
|
||||||
if self.save.player_load():
|
if self.save.player_load():
|
||||||
self.tournament.players_list = self.save.player_load()
|
self.tournament.players_list = self.save.player_load()
|
||||||
self.save.tournament_write(self.tournament)
|
self.save.tournament_write(self.tournament)
|
||||||
@ -107,8 +109,6 @@ class Application:
|
|||||||
self.menu_manager()
|
self.menu_manager()
|
||||||
|
|
||||||
def run_tournament(self):
|
def run_tournament(self):
|
||||||
"""creates all round iteration
|
|
||||||
"""
|
|
||||||
shuffle(self.tournament.players_list)
|
shuffle(self.tournament.players_list)
|
||||||
self.view.display_players(self.tournament.players_list)
|
self.view.display_players(self.tournament.players_list)
|
||||||
for each_round in range(1, self.tournament.total_round + 1):
|
for each_round in range(1, self.tournament.total_round + 1):
|
||||||
@ -132,12 +132,15 @@ class Application:
|
|||||||
self.view.display_round_info(self.round)
|
self.view.display_round_info(self.round)
|
||||||
self.view.display_scores(self.tournament.players_list)
|
self.view.display_scores(self.tournament.players_list)
|
||||||
|
|
||||||
self.view.ok_done(self.tournament.name)
|
print("\nLe tournoi", self.tournament.name, "est terminé !\n")
|
||||||
|
|
||||||
|
def get_match_info(self, match_list):
|
||||||
|
matches = []
|
||||||
|
for i in match_list:
|
||||||
|
matches.append(i.get_data())
|
||||||
|
return matches
|
||||||
|
|
||||||
def check_match(self, match, match_history):
|
def check_match(self, match, match_history):
|
||||||
"""check if match is in list
|
|
||||||
For future usage
|
|
||||||
"""
|
|
||||||
for item in match_history:
|
for item in match_history:
|
||||||
if match in item:
|
if match in item:
|
||||||
return True
|
return True
|
||||||
@ -160,7 +163,7 @@ class Application:
|
|||||||
match.player2 = self.tournament.players_list[i+1]
|
match.player2 = self.tournament.players_list[i+1]
|
||||||
if self.match_history.check(match):
|
if self.match_history.check(match):
|
||||||
# match.player2 = self.tournament.players_list[i+2]
|
# match.player2 = self.tournament.players_list[i+2]
|
||||||
self.view.display_error_already()
|
print("deja joue")
|
||||||
match_list.append(match)
|
match_list.append(match)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
@ -194,8 +197,8 @@ class Application:
|
|||||||
while True:
|
while True:
|
||||||
# Quit
|
# Quit
|
||||||
if menu_choice == "4":
|
if menu_choice == "4":
|
||||||
self.view.display_quit()
|
print("Bye")
|
||||||
quit()
|
break
|
||||||
# Rapports
|
# Rapports
|
||||||
elif menu_choice == "3":
|
elif menu_choice == "3":
|
||||||
rapport_choice = self.menu.items(2)
|
rapport_choice = self.menu.items(2)
|
||||||
@ -208,14 +211,14 @@ class Application:
|
|||||||
elif rapport_choice == "1":
|
elif rapport_choice == "1":
|
||||||
if self.save.player_load():
|
if self.save.player_load():
|
||||||
self.view.display_players(self.save.player_load())
|
self.view.display_players(self.save.player_load())
|
||||||
self.view.prompt_next()
|
input("?")
|
||||||
|
|
||||||
# Display list of tournaments
|
# Display list of tournaments
|
||||||
elif rapport_choice == "2":
|
elif rapport_choice == "2":
|
||||||
if self.save.tournament_load():
|
if self.save.tournament_load():
|
||||||
self.view.display_tournaments(
|
self.view.display_tournaments(
|
||||||
self.save.tournament_load())
|
self.save.tournament_load())
|
||||||
self.view.prompt_next()
|
input("?")
|
||||||
|
|
||||||
# display tournament's details
|
# display tournament's details
|
||||||
elif rapport_choice == "3":
|
elif rapport_choice == "3":
|
||||||
@ -233,12 +236,12 @@ class Application:
|
|||||||
elif menu_choice == "2":
|
elif menu_choice == "2":
|
||||||
joueur = self.view.prompt_for_new_player()
|
joueur = self.view.prompt_for_new_player()
|
||||||
self.save.player_write(joueur)
|
self.save.player_write(joueur)
|
||||||
self.view.prompt_next()
|
input("Retour ?")
|
||||||
self.menu_manager()
|
self.menu_manager()
|
||||||
|
|
||||||
# create new tournament
|
# create new tournament
|
||||||
elif menu_choice == "1":
|
elif menu_choice == "1":
|
||||||
self.view.ok_go()
|
print("c'est parti")
|
||||||
self.create_tournament()
|
self.create_tournament()
|
||||||
self.run_tournament()
|
self.run_tournament()
|
||||||
self.menu_manager()
|
self.menu_manager()
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<div id="masthead" class="sev-4"></div>
|
<div id="masthead" class="sev-4"></div>
|
||||||
<div id="page">
|
<div id="page">
|
||||||
<h1>flake8 violations</h1>
|
<h1>flake8 violations</h1>
|
||||||
<p id="versions">Generated on 2025-02-14 11:49
|
<p id="versions">Generated on 2025-02-13 15:45
|
||||||
with Installed plugins: flake8-html: 0.4.3, mccabe: 0.7.0, pycodestyle: 2.12.1, pyflakes: 3.2.0
|
with Installed plugins: flake8-html: 0.4.3, mccabe: 0.7.0, pycodestyle: 2.12.1, pyflakes: 3.2.0
|
||||||
</p>
|
</p>
|
||||||
<ul id="index">
|
<ul id="index">
|
||||||
|
10
main.py
10
main.py
@ -1,13 +1,13 @@
|
|||||||
from models.models import Tournament
|
from ChessTournament.models.models import Tournament
|
||||||
from controllers.base import Application, Save
|
from ChessTournament.controllers.base import Application, Save
|
||||||
from views.base import View
|
from ChessTournament.views.base import View
|
||||||
from views.menu import Menu
|
from ChessTournament.views.menu import Menu
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
tournament = Tournament()
|
tournament = Tournament()
|
||||||
|
save = Save()
|
||||||
view = View()
|
view = View()
|
||||||
save = Save(view)
|
|
||||||
menu = Menu()
|
menu = Menu()
|
||||||
application = Application(tournament=tournament,
|
application = Application(tournament=tournament,
|
||||||
save=save,
|
save=save,
|
||||||
|
@ -29,11 +29,6 @@ class View:
|
|||||||
input("Saisir les scores ? (y)")
|
input("Saisir les scores ? (y)")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def prompt_next(self):
|
|
||||||
print()
|
|
||||||
input("?")
|
|
||||||
return True
|
|
||||||
|
|
||||||
def prompt_for_round(self, round):
|
def prompt_for_round(self, round):
|
||||||
print()
|
print()
|
||||||
input(f"Prêt à lancer le {round.name} ? (y)")
|
input(f"Prêt à lancer le {round.name} ? (y)")
|
||||||
@ -107,12 +102,12 @@ class View:
|
|||||||
print(i.ine, ':', i.name, i.lastname, i.score)
|
print(i.ine, ':', i.name, i.lastname, i.score)
|
||||||
|
|
||||||
def display_players(self, player_list_to_display):
|
def display_players(self, player_list_to_display):
|
||||||
print("\nListe des joueurs :")
|
print("Liste des joueurs :")
|
||||||
for player in player_list_to_display:
|
for player in player_list_to_display:
|
||||||
print(f"{player.name} {str.upper(player.lastname)} ({player.ine})")
|
print(player.data())
|
||||||
|
|
||||||
def display_tournaments(self, tournament_list_to_display):
|
def display_tournaments(self, tournament_list_to_display):
|
||||||
print("\nListe des tournois : ")
|
print("Liste des tournois : ")
|
||||||
for tournament in tournament_list_to_display:
|
for tournament in tournament_list_to_display:
|
||||||
print("-", tournament,
|
print("-", tournament,
|
||||||
"le",
|
"le",
|
||||||
@ -120,8 +115,7 @@ class View:
|
|||||||
|
|
||||||
def display_tournament_detail(self, tournament_to_display):
|
def display_tournament_detail(self, tournament_to_display):
|
||||||
i = tournament_to_display
|
i = tournament_to_display
|
||||||
print("\n***************************************************")
|
print("Nom du tournoi : ", i['name'])
|
||||||
print("\nNom du tournoi : ", i['name'])
|
|
||||||
print("Lieu : ", i['location'])
|
print("Lieu : ", i['location'])
|
||||||
print("Description : ", i['description'])
|
print("Description : ", i['description'])
|
||||||
print("Le tournoi a débuté le : ", i['start'])
|
print("Le tournoi a débuté le : ", i['start'])
|
||||||
@ -141,33 +135,11 @@ class View:
|
|||||||
print("Les scores finaux :")
|
print("Les scores finaux :")
|
||||||
for j in i['players']:
|
for j in i['players']:
|
||||||
print(j['prénom'], str.upper(j['nom']), ":", j['score'])
|
print(j['prénom'], str.upper(j['nom']), ":", j['score'])
|
||||||
print("\n***************************************************")
|
|
||||||
|
|
||||||
def display_error(self):
|
def display_error(self):
|
||||||
print("Erreur de saisie, recommencez;")
|
print("Erreur de saisie, recommencez;")
|
||||||
|
|
||||||
def display_format_error(self):
|
|
||||||
print("\n**** Erreur de format de fichier")
|
|
||||||
|
|
||||||
def display_file_error(self, file):
|
|
||||||
print(f"\n**** Pas de fichier {file} trouvé :/")
|
|
||||||
|
|
||||||
def display_player_instructions(self):
|
def display_player_instructions(self):
|
||||||
print("Placez un fichier joueur dans le répertoire data "
|
print("Placez un fichier joueur dans le répertoire data "
|
||||||
"ou créez des nouveaux joueurs depuis le menu")
|
"ou créez des nouveaux joueurs depuis le menu")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
def display_quit(self):
|
|
||||||
print("Bye !")
|
|
||||||
|
|
||||||
def display_error_already(self):
|
|
||||||
print("Déjà joué")
|
|
||||||
|
|
||||||
def ok_player(self):
|
|
||||||
print("\nJoueur créé.")
|
|
||||||
|
|
||||||
def ok_go(self):
|
|
||||||
print("\n!!! C'est parti !!!\n")
|
|
||||||
|
|
||||||
def ok_done(self, name):
|
|
||||||
print(f"\nLe tournoi {name} est terminé !\n")
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user