Compare commits
21 Commits
7c50729643
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| c1a0a79531 | |||
| aea638d660 | |||
| c9cf13c209 | |||
| 9b881839ba | |||
| 5d4aa8127f | |||
| d09e781ded | |||
| 2397e6dbe4 | |||
| a1c7b5ab2c | |||
| 52ae8b774d | |||
| fee2df07b1 | |||
| fd87fabaf1 | |||
| cebb11380c | |||
| 653e3ef0f6 | |||
| 89bda57fe5 | |||
| 89aa9b2192 | |||
| 98c723afc5 | |||
| 6043354279 | |||
| 29a56eceaa | |||
| d115126afb | |||
| bc8f73beaf | |||
| 31c2b39fa4 |
@@ -27,6 +27,7 @@ source env/bin/activate
|
||||
cloner le dépôt, aller dans le bon dossier
|
||||
```
|
||||
git clone https://mcstn.fr/gitea/Yann/Projet4.git
|
||||
cd Projet4
|
||||
```
|
||||
|
||||
## Exécution
|
||||
@@ -45,6 +46,9 @@ Si vous souhaitez spécifier une liste de joueurs au format JSON, il vous faut l
|
||||
dans le répertoire `data`
|
||||
Sinon, vous pouvez créer des joueurs via le menu
|
||||
|
||||
Le répertoire, nom des fichiers joueurs et tournois sont des constantes de models.py
|
||||
Ils sont placés dans le dossier `data`
|
||||
|
||||
## Auteur
|
||||
|
||||
Yann <yann@needsome.coffee>
|
||||
@@ -53,4 +57,4 @@ Yann <yann@needsome.coffee>
|
||||
|
||||
## License
|
||||
|
||||
N/A
|
||||
N/A
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from ChessTournament.models.models import (Player, Round, Match,
|
||||
MatchHistory)
|
||||
from ChessTournament.models.models import DATAPATH, PLAYERFILE, TOURNAMENTFILE
|
||||
|
||||
from models.models import (Player, Round, Match, MatchHistory)
|
||||
from models.models import DATAPATH, PLAYERFILE, TOURNAMENTFILE
|
||||
|
||||
from random import shuffle
|
||||
import os
|
||||
@@ -9,8 +7,8 @@ import json
|
||||
|
||||
|
||||
class Save:
|
||||
def __init__(self):
|
||||
pass
|
||||
def __init__(self, view):
|
||||
self.view = view
|
||||
|
||||
def load_file(self, file):
|
||||
try:
|
||||
@@ -24,7 +22,7 @@ class Save:
|
||||
return data_tmp
|
||||
|
||||
except json.decoder.JSONDecodeError:
|
||||
print("Erreur de format sur le fichier")
|
||||
self.view.display_format_error()
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
|
||||
@@ -39,7 +37,7 @@ class Save:
|
||||
data_tmp = (self.load_file(PLAYERFILE))
|
||||
data_tmp.append(player)
|
||||
self.write_file(data_tmp, PLAYERFILE)
|
||||
print("Joueur créé !")
|
||||
self.view.ok_player()
|
||||
return True
|
||||
|
||||
def player_load(self) -> list:
|
||||
@@ -57,14 +55,12 @@ class Save:
|
||||
|
||||
return data_list
|
||||
else:
|
||||
print("\n**** Pas de fichier joueur trouvé :/\n")
|
||||
self.view.display_file_error("joueur")
|
||||
|
||||
def tournament_write(self, tournament):
|
||||
data = {
|
||||
tournament.name: tournament.data()
|
||||
}
|
||||
print(data)
|
||||
|
||||
if self.load_file(TOURNAMENTFILE):
|
||||
data_tmp = self.load_file(TOURNAMENTFILE)
|
||||
data_tmp[tournament.name] = tournament.data()
|
||||
@@ -78,7 +74,7 @@ class Save:
|
||||
data_tmp = self.load_file(TOURNAMENTFILE)
|
||||
return data_tmp
|
||||
else:
|
||||
print("\n**** Pas de fichier tournoi trouvé :/ \n")
|
||||
self.view.display_file_error("tournoi")
|
||||
|
||||
|
||||
class Application:
|
||||
@@ -93,11 +89,8 @@ class Application:
|
||||
def sort_by_score(self):
|
||||
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):
|
||||
print("Nouveau tournoi ! \n")
|
||||
"""update existing tournament with data from view"""
|
||||
tournament_details = self.view.prompt_for_tournament()
|
||||
self.tournament.name = tournament_details['name']
|
||||
self.tournament.location = tournament_details['location']
|
||||
@@ -105,17 +98,19 @@ class Application:
|
||||
self.tournament.date_end = tournament_details['date_end']
|
||||
self.tournament.description = tournament_details['description']
|
||||
self.tournament.total_round = tournament_details['total_round']
|
||||
self.tournament.round_list = []
|
||||
if self.save.player_load():
|
||||
self.tournament.players_list = self.save.player_load()
|
||||
self.save.tournament_write(self.tournament)
|
||||
else:
|
||||
print("Placez un fichier joueur dans le répertoire data"
|
||||
"ou créez des nouveaux joueurs depuis le menu")
|
||||
print()
|
||||
self.view.display_player_instructions()
|
||||
self.menu_manager()
|
||||
|
||||
def run_tournament(self):
|
||||
"""creates all round iteration
|
||||
"""
|
||||
shuffle(self.tournament.players_list)
|
||||
self.view.display_players(self.tournament.players_list)
|
||||
for each_round in range(1, self.tournament.total_round + 1):
|
||||
self.tournament.current_round += 1
|
||||
self.round = Round()
|
||||
@@ -125,6 +120,7 @@ class Application:
|
||||
self.round.start_time = self.round.get_time()
|
||||
# create matches TODO : check from history
|
||||
self.round.match_list = self.create_match()
|
||||
self.match_history.add(self.round.match_list)
|
||||
# display matches
|
||||
self.view.display_matches(self.round.match_list)
|
||||
self.view.prompt_for_scores()
|
||||
@@ -132,20 +128,16 @@ class Application:
|
||||
self.scores(self.round.match_list)
|
||||
self.sort_by_score()
|
||||
self.tournament.round_list.append(self.round.save())
|
||||
print("après maj", self.tournament.round_list)
|
||||
self.save.tournament_write(self.tournament)
|
||||
self.view.display_round_info(self.round)
|
||||
self.view.display_scores(self.tournament.players_list)
|
||||
|
||||
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
|
||||
self.view.ok_done(self.tournament.name)
|
||||
|
||||
def check_match(self, match, match_history):
|
||||
"""check if match is in list
|
||||
For future usage
|
||||
"""
|
||||
for item in match_history:
|
||||
if match in item:
|
||||
return True
|
||||
@@ -163,9 +155,15 @@ class Application:
|
||||
for i in range(0, len(self.tournament.players_list), 2):
|
||||
j += 1
|
||||
match = Match()
|
||||
match.player1 = self.tournament.players_list[i]
|
||||
match.player2 = self.tournament.players_list[i+1]
|
||||
match_list.append(match)
|
||||
try:
|
||||
match.player1 = self.tournament.players_list[i]
|
||||
match.player2 = self.tournament.players_list[i+1]
|
||||
if self.match_history.check(match):
|
||||
# match.player2 = self.tournament.players_list[i+2]
|
||||
self.view.display_error_already()
|
||||
match_list.append(match)
|
||||
except IndexError:
|
||||
pass
|
||||
return match_list
|
||||
|
||||
def scores(self, match_list) -> list:
|
||||
@@ -196,8 +194,8 @@ class Application:
|
||||
while True:
|
||||
# Quit
|
||||
if menu_choice == "4":
|
||||
print("Bye")
|
||||
|
||||
self.view.display_quit()
|
||||
quit()
|
||||
# Rapports
|
||||
elif menu_choice == "3":
|
||||
rapport_choice = self.menu.items(2)
|
||||
@@ -210,14 +208,14 @@ class Application:
|
||||
elif rapport_choice == "1":
|
||||
if self.save.player_load():
|
||||
self.view.display_players(self.save.player_load())
|
||||
input("?")
|
||||
self.view.prompt_next()
|
||||
|
||||
# Display list of tournaments
|
||||
elif rapport_choice == "2":
|
||||
if self.save.tournament_load():
|
||||
self.view.display_tournaments(
|
||||
self.save.tournament_load())
|
||||
input("?")
|
||||
self.view.prompt_next()
|
||||
|
||||
# display tournament's details
|
||||
elif rapport_choice == "3":
|
||||
@@ -235,31 +233,12 @@ class Application:
|
||||
elif menu_choice == "2":
|
||||
joueur = self.view.prompt_for_new_player()
|
||||
self.save.player_write(joueur)
|
||||
input("Retour ?")
|
||||
self.view.prompt_next()
|
||||
self.menu_manager()
|
||||
|
||||
# create new tournament
|
||||
elif menu_choice == "1":
|
||||
print("c'est parti")
|
||||
self.view.ok_go()
|
||||
self.create_tournament()
|
||||
self.run_tournament()
|
||||
self.view.display_winner(self.tournament.players_list)
|
||||
self.view.display_scores(self.tournament.players_list)
|
||||
self.menu_manager()
|
||||
|
||||
|
||||
class CheckMatch:
|
||||
pass
|
||||
|
||||
|
||||
class MenuManager:
|
||||
pass
|
||||
|
||||
|
||||
class TournamentManager:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class UserManager:
|
||||
pass
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<div id="masthead" class="sev-4"></div>
|
||||
<div id="page">
|
||||
<h1>flake8 violations</h1>
|
||||
<p id="versions">Generated on 2025-02-13 11:38
|
||||
<p id="versions">Generated on 2025-02-14 11:49
|
||||
with Installed plugins: flake8-html: 0.4.3, mccabe: 0.7.0, pycodestyle: 2.12.1, pyflakes: 3.2.0
|
||||
</p>
|
||||
<ul id="index">
|
||||
|
||||
10
main.py
10
main.py
@@ -1,13 +1,13 @@
|
||||
from ChessTournament.models.models import Tournament
|
||||
from ChessTournament.controllers.base import Application, Save
|
||||
from ChessTournament.views.base import View
|
||||
from ChessTournament.views.menu import Menu
|
||||
from models.models import Tournament
|
||||
from controllers.base import Application, Save
|
||||
from views.base import View
|
||||
from views.menu import Menu
|
||||
|
||||
|
||||
def main():
|
||||
tournament = Tournament()
|
||||
save = Save()
|
||||
view = View()
|
||||
save = Save(view)
|
||||
menu = Menu()
|
||||
application = Application(tournament=tournament,
|
||||
save=save,
|
||||
|
||||
@@ -22,6 +22,7 @@ class Tournament:
|
||||
self.round_list = []
|
||||
self.current_round = 0
|
||||
self.players_list = players_list
|
||||
self.scores = []
|
||||
self.description = "Pas de description"
|
||||
|
||||
def __str__(self):
|
||||
@@ -67,7 +68,8 @@ class Player:
|
||||
'prénom': self.name,
|
||||
'nom': self.lastname,
|
||||
'date de naissance': self.birthdate,
|
||||
'ine': self.ine
|
||||
'ine': self.ine,
|
||||
'score': self.score
|
||||
}
|
||||
return player_dict
|
||||
|
||||
|
||||
109
views/base.py
109
views/base.py
@@ -29,28 +29,16 @@ class View:
|
||||
input("Saisir les scores ? (y)")
|
||||
return True
|
||||
|
||||
def prompt_next(self):
|
||||
print()
|
||||
input("?")
|
||||
return True
|
||||
|
||||
def prompt_for_round(self, round):
|
||||
print()
|
||||
input(f"Prêt à lancer le {round.name} ? (y)")
|
||||
return True
|
||||
|
||||
def display_matches(self, match_list):
|
||||
print("Liste des matchs : ")
|
||||
for match in match_list:
|
||||
print(match.player1.name, match.player1.lastname.upper(),
|
||||
"contre", match.player2.name, match.player2.lastname.upper(),
|
||||
"(", match, ")"
|
||||
)
|
||||
|
||||
def display_round_info(self, round):
|
||||
print("\n -> ", round)
|
||||
|
||||
def display_scores(self, players_list):
|
||||
print("\nLes scores sont :")
|
||||
print("-----------------")
|
||||
for i in players_list:
|
||||
print(i.ine, i.name, i.lastname, ":", i.score)
|
||||
|
||||
def prompt_for_new_player(self) -> dict:
|
||||
print("Enregistrez un nouveau joueur :\n")
|
||||
lastname = input("Nom de famille ? : ")
|
||||
@@ -77,6 +65,16 @@ class View:
|
||||
tournament_details['total_round'] = int(total_round)
|
||||
return tournament_details
|
||||
|
||||
def prompt_tournament_to_display(self, tournament_list_to_display):
|
||||
i = 0
|
||||
temp_list = []
|
||||
for tournament in tournament_list_to_display:
|
||||
i += 1
|
||||
print(i, ".", tournament)
|
||||
temp_list.append(tournament)
|
||||
num = int(input("Numéro du tournoi à afficher ? "))
|
||||
return temp_list[num - 1]
|
||||
|
||||
def input_scores(self, match, count):
|
||||
print("Scores pour le match", count, " :")
|
||||
while True:
|
||||
@@ -91,43 +89,46 @@ class View:
|
||||
except ValueError:
|
||||
print("Veuillez entrer un chiffre")
|
||||
|
||||
def display_winner(self, player_list):
|
||||
winner = max(player_list, key=lambda t: t.score)
|
||||
print("Le gagnant est :",
|
||||
winner.name,
|
||||
winner.lastname,
|
||||
"avec un score de :",
|
||||
winner.score)
|
||||
def display_matches(self, match_list):
|
||||
print("Liste des matchs : ")
|
||||
for match in match_list:
|
||||
print(match.player1.name, match.player1.lastname.upper(),
|
||||
"contre", match.player2.name, match.player2.lastname.upper(),
|
||||
"(", match, ")"
|
||||
)
|
||||
|
||||
def display_round_info(self, round):
|
||||
print("\n -> ", round)
|
||||
|
||||
def display_scores(self, players_list):
|
||||
print("\nLes scores sont :")
|
||||
print("-----------------")
|
||||
for i in players_list:
|
||||
print(i.ine, ':', i.name, i.lastname, i.score)
|
||||
|
||||
def display_players(self, player_list_to_display):
|
||||
print("Liste des joueurs :")
|
||||
print("\nListe des joueurs :")
|
||||
for player in player_list_to_display:
|
||||
print(player.data())
|
||||
print(f"{player.name} {str.upper(player.lastname)} ({player.ine})")
|
||||
|
||||
def display_tournaments(self, tournament_list_to_display):
|
||||
print("Liste des tournois : ")
|
||||
print("\nListe des tournois : ")
|
||||
for tournament in tournament_list_to_display:
|
||||
print("-", tournament,
|
||||
"le",
|
||||
tournament_list_to_display[tournament]['start'])
|
||||
|
||||
def prompt_tournament_to_display(self, tournament_list_to_display):
|
||||
i = 0
|
||||
temp_list = []
|
||||
for tournament in tournament_list_to_display:
|
||||
i += 1
|
||||
print(i, ".", tournament)
|
||||
temp_list.append(tournament)
|
||||
num = int(input("Numéro du tournoi à afficher ? "))
|
||||
return temp_list[num - 1]
|
||||
|
||||
def display_tournament_detail(self, tournament_to_display):
|
||||
i = tournament_to_display
|
||||
print("Nom du tournoi : ", i['name'])
|
||||
print("\n***************************************************")
|
||||
print("\nNom du tournoi : ", i['name'])
|
||||
print("Lieu : ", i['location'])
|
||||
print("Description : ", i['description'])
|
||||
print("Le tournoi a débuté le : ", i['start'])
|
||||
print("Et s'est terminé le : ", i['end'])
|
||||
print("Les participants étaient : \n", i['players'])
|
||||
print("\nLes participants étaient : ")
|
||||
for j in i['players']:
|
||||
print(j['ine'], "-", j['prénom'], str.upper(j['nom']))
|
||||
print("\nLes matches et leurs résultats étaient :")
|
||||
for j in i['rounds']:
|
||||
print(j['Nom'])
|
||||
@@ -137,6 +138,36 @@ class View:
|
||||
for k in j['Matches']:
|
||||
print(k)
|
||||
print()
|
||||
print("Les scores finaux :")
|
||||
for j in i['players']:
|
||||
print(j['prénom'], str.upper(j['nom']), ":", j['score'])
|
||||
print("\n***************************************************")
|
||||
|
||||
def display_error(self):
|
||||
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):
|
||||
print("Placez un fichier joueur dans le répertoire data "
|
||||
"ou créez des nouveaux joueurs depuis le menu")
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user