push all to show in first session
This commit is contained in:
0
tournoi/__init_.py
Normal file
0
tournoi/__init_.py
Normal file
0
tournoi/match.py
Normal file
0
tournoi/match.py
Normal file
14
tournoi/menu.py
Normal file
14
tournoi/menu.py
Normal file
@@ -0,0 +1,14 @@
|
||||
class Menu:
|
||||
|
||||
def items(self):
|
||||
print("[1] Créer un nouveau tournoi", end='\n')
|
||||
print("[2] Enregistrer un nouveau joueur", end='\n')
|
||||
print("[3] Rapports", end='\n')
|
||||
print("[4] Quitter", end='\n')
|
||||
|
||||
|
||||
def rapports():
|
||||
print("[1] Afficher la liste des joueurs", end='\n')
|
||||
print("[2] Afficher l'historique des tournois", end='\n')
|
||||
print("[3] Afficher le détail d'un tournoi", end='\n')
|
||||
print("[4] Quitter", end='\n')
|
||||
19
tournoi/player.py
Normal file
19
tournoi/player.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import json
|
||||
|
||||
class Player:
|
||||
"""Define player, should store only data for now ? Don't see further"""
|
||||
|
||||
def get_new_player(self):
|
||||
get_player = {}
|
||||
print("Enregistrez un nouveau joueur :\n")
|
||||
get_player['lastname'] = input('Nom de famille :\n')
|
||||
get_player['name'] = input('Prénom :\n')
|
||||
get_player['birth_date'] = input('Date de naissance :\n')
|
||||
|
||||
#convert dict in json object and write it in players.json file (with "a" append to file)
|
||||
with open("players.json", "a") as output:
|
||||
output.write(json.dumps(get_player, indent=3))
|
||||
|
||||
|
||||
new = Player()
|
||||
new.get_new_player()
|
||||
10
tournoi/players.json
Normal file
10
tournoi/players.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"lastname": "Prout",
|
||||
"name": "Joe",
|
||||
"birth_date": "23/02/2003"
|
||||
}
|
||||
{
|
||||
"lastname": "Dupont",
|
||||
"name": "Pierre",
|
||||
"birth_date": "20/01/2002"
|
||||
}
|
||||
0
tournoi/tournament.py
Normal file
0
tournoi/tournament.py
Normal file
74
tournoi/turn.py
Normal file
74
tournoi/turn.py
Normal file
@@ -0,0 +1,74 @@
|
||||
from random import choice
|
||||
|
||||
|
||||
class Turn():
|
||||
def __init__(self, name, matchs):
|
||||
self.name = name
|
||||
self.matchs = matchs
|
||||
self.match_history = []
|
||||
|
||||
def rambling(self, player_list):
|
||||
"""jumble (random order) players in list and return list"""
|
||||
self.tmp_list = []
|
||||
self.picked_player = []
|
||||
for i in range(2^len(player_list)):
|
||||
self.picked_player = choice(player_list)
|
||||
self.tmp_list.append(self.picked_player)
|
||||
return self.tmp_list
|
||||
|
||||
|
||||
def sorting(self, player_list):
|
||||
"""order players on score : use second index (for every item in the list) as key (given by function score)"""
|
||||
def score(couple):
|
||||
return couple[1]
|
||||
return sorted(player_list, key=score)
|
||||
|
||||
|
||||
def associate(self, player_list):
|
||||
"""create a match list"""
|
||||
self.match_list = []
|
||||
self.couple = ()
|
||||
for i in range(len(player_list)):
|
||||
if i % 2 == 0 :
|
||||
self.couple = (player_list[i][0], player_list[i+1][0])
|
||||
if self.couple in self.match_history:
|
||||
self.couple = (player_list[i][0], player_list[i + 2][0])
|
||||
self.match_list.append(self.couple)
|
||||
else:
|
||||
self.match_list.append(self.couple)
|
||||
|
||||
self.match_history.append(self.name)
|
||||
self.match_history.append(self.match_list)
|
||||
return self.match_list
|
||||
|
||||
|
||||
def matchmarking(self, player_list):
|
||||
pass
|
||||
|
||||
list = [['Player1', 8],
|
||||
['Player2', 2],
|
||||
['Player3', 0],
|
||||
['Player4', 5],
|
||||
['Player5', 8],
|
||||
['Player6', 3],
|
||||
['Player7', 1],
|
||||
['Player8', 6],
|
||||
['Player9', 3],
|
||||
['Player10', 4],
|
||||
['Player11', 3],
|
||||
['Player12', 2],
|
||||
['Player13', 8],
|
||||
['Player14', 4],
|
||||
['Player15', 2],
|
||||
['Player16', 7]]
|
||||
|
||||
tour = Turn("tour1", 1)
|
||||
|
||||
print(tour.sorting(list))
|
||||
print(tour.rambling(list))
|
||||
|
||||
print(tour.associate(tour.sorting(list)))
|
||||
|
||||
print(f"Voici l'historique des matchs : {tour.match_history}")
|
||||
|
||||
tour2 = Turn()
|
||||
Reference in New Issue
Block a user