commit
6043354279
@ -1,7 +1,5 @@
|
|||||||
from ChessTournament.models.models import (Player, Round, Match,
|
from models.models import (Player, Round, Match, MatchHistory)
|
||||||
MatchHistory)
|
from models.models import DATAPATH, PLAYERFILE, TOURNAMENTFILE
|
||||||
from ChessTournament.models.models import DATAPATH, PLAYERFILE, TOURNAMENTFILE
|
|
||||||
|
|
||||||
|
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
import os
|
import os
|
||||||
@ -63,8 +61,6 @@ class Save:
|
|||||||
data = {
|
data = {
|
||||||
tournament.name: tournament.data()
|
tournament.name: tournament.data()
|
||||||
}
|
}
|
||||||
print(data)
|
|
||||||
|
|
||||||
if self.load_file(TOURNAMENTFILE):
|
if self.load_file(TOURNAMENTFILE):
|
||||||
data_tmp = self.load_file(TOURNAMENTFILE)
|
data_tmp = self.load_file(TOURNAMENTFILE)
|
||||||
data_tmp[tournament.name] = tournament.data()
|
data_tmp[tournament.name] = tournament.data()
|
||||||
@ -109,13 +105,12 @@ class Application:
|
|||||||
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)
|
||||||
else:
|
else:
|
||||||
print("Placez un fichier joueur dans le répertoire data"
|
self.view.display_player_instructions()
|
||||||
"ou créez des nouveaux joueurs depuis le menu")
|
|
||||||
print()
|
|
||||||
self.menu_manager()
|
self.menu_manager()
|
||||||
|
|
||||||
def run_tournament(self):
|
def run_tournament(self):
|
||||||
shuffle(self.tournament.players_list)
|
shuffle(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):
|
||||||
self.tournament.current_round += 1
|
self.tournament.current_round += 1
|
||||||
self.round = Round()
|
self.round = Round()
|
||||||
@ -125,6 +120,7 @@ class Application:
|
|||||||
self.round.start_time = self.round.get_time()
|
self.round.start_time = self.round.get_time()
|
||||||
# create matches TODO : check from history
|
# create matches TODO : check from history
|
||||||
self.round.match_list = self.create_match()
|
self.round.match_list = self.create_match()
|
||||||
|
self.match_history.add(self.round.match_list)
|
||||||
# display matches
|
# display matches
|
||||||
self.view.display_matches(self.round.match_list)
|
self.view.display_matches(self.round.match_list)
|
||||||
self.view.prompt_for_scores()
|
self.view.prompt_for_scores()
|
||||||
@ -132,7 +128,6 @@ class Application:
|
|||||||
self.scores(self.round.match_list)
|
self.scores(self.round.match_list)
|
||||||
self.sort_by_score()
|
self.sort_by_score()
|
||||||
self.tournament.round_list.append(self.round.save())
|
self.tournament.round_list.append(self.round.save())
|
||||||
print("après maj", self.tournament.round_list)
|
|
||||||
self.save.tournament_write(self.tournament)
|
self.save.tournament_write(self.tournament)
|
||||||
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)
|
||||||
@ -163,9 +158,15 @@ class Application:
|
|||||||
for i in range(0, len(self.tournament.players_list), 2):
|
for i in range(0, len(self.tournament.players_list), 2):
|
||||||
j += 1
|
j += 1
|
||||||
match = Match()
|
match = Match()
|
||||||
match.player1 = self.tournament.players_list[i]
|
try:
|
||||||
match.player2 = self.tournament.players_list[i+1]
|
match.player1 = self.tournament.players_list[i]
|
||||||
match_list.append(match)
|
match.player2 = self.tournament.players_list[i+1]
|
||||||
|
if self.match_history.check(match):
|
||||||
|
# match.player2 = self.tournament.players_list[i+2]
|
||||||
|
print("deja joue")
|
||||||
|
match_list.append(match)
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
return match_list
|
return match_list
|
||||||
|
|
||||||
def scores(self, match_list) -> list:
|
def scores(self, match_list) -> list:
|
||||||
@ -197,7 +198,7 @@ class Application:
|
|||||||
# Quit
|
# Quit
|
||||||
if menu_choice == "4":
|
if menu_choice == "4":
|
||||||
print("Bye")
|
print("Bye")
|
||||||
|
break
|
||||||
# Rapports
|
# Rapports
|
||||||
elif menu_choice == "3":
|
elif menu_choice == "3":
|
||||||
rapport_choice = self.menu.items(2)
|
rapport_choice = self.menu.items(2)
|
||||||
@ -243,23 +244,4 @@ class Application:
|
|||||||
print("c'est parti")
|
print("c'est parti")
|
||||||
self.create_tournament()
|
self.create_tournament()
|
||||||
self.run_tournament()
|
self.run_tournament()
|
||||||
self.view.display_winner(self.tournament.players_list)
|
|
||||||
self.view.display_scores(self.tournament.players_list)
|
|
||||||
self.menu_manager()
|
self.menu_manager()
|
||||||
|
|
||||||
|
|
||||||
class CheckMatch:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class MenuManager:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TournamentManager:
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class UserManager:
|
|
||||||
pass
|
|
||||||
|
@ -22,6 +22,7 @@ class Tournament:
|
|||||||
self.round_list = []
|
self.round_list = []
|
||||||
self.current_round = 0
|
self.current_round = 0
|
||||||
self.players_list = players_list
|
self.players_list = players_list
|
||||||
|
self.scores = []
|
||||||
self.description = "Pas de description"
|
self.description = "Pas de description"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@ -67,7 +68,8 @@ class Player:
|
|||||||
'prénom': self.name,
|
'prénom': self.name,
|
||||||
'nom': self.lastname,
|
'nom': self.lastname,
|
||||||
'date de naissance': self.birthdate,
|
'date de naissance': self.birthdate,
|
||||||
'ine': self.ine
|
'ine': self.ine,
|
||||||
|
'score': self.score
|
||||||
}
|
}
|
||||||
return player_dict
|
return player_dict
|
||||||
|
|
||||||
|
@ -34,23 +34,6 @@ class View:
|
|||||||
input(f"Prêt à lancer le {round.name} ? (y)")
|
input(f"Prêt à lancer le {round.name} ? (y)")
|
||||||
return True
|
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:
|
def prompt_for_new_player(self) -> dict:
|
||||||
print("Enregistrez un nouveau joueur :\n")
|
print("Enregistrez un nouveau joueur :\n")
|
||||||
lastname = input("Nom de famille ? : ")
|
lastname = input("Nom de famille ? : ")
|
||||||
@ -77,6 +60,16 @@ class View:
|
|||||||
tournament_details['total_round'] = int(total_round)
|
tournament_details['total_round'] = int(total_round)
|
||||||
return tournament_details
|
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):
|
def input_scores(self, match, count):
|
||||||
print("Scores pour le match", count, " :")
|
print("Scores pour le match", count, " :")
|
||||||
while True:
|
while True:
|
||||||
@ -91,13 +84,22 @@ class View:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
print("Veuillez entrer un chiffre")
|
print("Veuillez entrer un chiffre")
|
||||||
|
|
||||||
def display_winner(self, player_list):
|
def display_matches(self, match_list):
|
||||||
winner = max(player_list, key=lambda t: t.score)
|
print("Liste des matchs : ")
|
||||||
print("Le gagnant est :",
|
for match in match_list:
|
||||||
winner.name,
|
print(match.player1.name, match.player1.lastname.upper(),
|
||||||
winner.lastname,
|
"contre", match.player2.name, match.player2.lastname.upper(),
|
||||||
"avec un score de :",
|
"(", match, ")"
|
||||||
winner.score)
|
)
|
||||||
|
|
||||||
|
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):
|
def display_players(self, player_list_to_display):
|
||||||
print("Liste des joueurs :")
|
print("Liste des joueurs :")
|
||||||
@ -111,23 +113,16 @@ class View:
|
|||||||
"le",
|
"le",
|
||||||
tournament_list_to_display[tournament]['start'])
|
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):
|
def display_tournament_detail(self, tournament_to_display):
|
||||||
i = tournament_to_display
|
i = tournament_to_display
|
||||||
print("Nom du tournoi : ", i['name'])
|
print("Nom du tournoi : ", i['name'])
|
||||||
print("Lieu : ", i['location'])
|
print("Lieu : ", i['location'])
|
||||||
|
print("Description : ", i['description'])
|
||||||
print("Le tournoi a débuté le : ", i['start'])
|
print("Le tournoi a débuté le : ", i['start'])
|
||||||
print("Et s'est terminé le : ", i['end'])
|
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 :")
|
print("\nLes matches et leurs résultats étaient :")
|
||||||
for j in i['rounds']:
|
for j in i['rounds']:
|
||||||
print(j['Nom'])
|
print(j['Nom'])
|
||||||
@ -137,6 +132,14 @@ class View:
|
|||||||
for k in j['Matches']:
|
for k in j['Matches']:
|
||||||
print(k)
|
print(k)
|
||||||
print()
|
print()
|
||||||
|
print("Les scores finaux :")
|
||||||
|
for j in i['players']:
|
||||||
|
print(j['prénom'], str.upper(j['nom']), ":", j['score'])
|
||||||
|
|
||||||
def display_error(self):
|
def display_error(self):
|
||||||
print("Erreur de saisie, recommencez;")
|
print("Erreur de saisie, recommencez;")
|
||||||
|
|
||||||
|
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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user