-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.py
124 lines (97 loc) · 4.12 KB
/
classes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import sqlite3
conn = sqlite3.connect('penalty_db.sqlite')
c = conn.cursor()
class Team:
def __init__(self, name, city, id=None):
self.name = name
self.city = city
self.id = id
self.partial = 0
self.final = 0
def add_keeper(self,team_id):
#method to add goalkeepers to teams
query = 'SELECT id FROM players WHERE player_type=0 and team_id=? ORDER BY overall DESC'
with conn:
c.execute(query, (team_id,))
all_gks = c.fetchall()
self.gk1 = all_gks[0][0]
self.gk2 = all_gks[1][0]
def add_shooter(self, team_id, player_id):
#method to add players to teams
if player not in shooter:
self.players.append(player)
def remove_players(self, player):
#method to remove players from teams
if player in players:
self.players.remove(player)
def __repr__(self):
return "('{}', '{}')".format(self.name, self.city)
def __str__(self):
return '{}'.format(self.team_name())
class Player:
#creator for players instances
def __init__(self, first, last, age, id=None,):
self.first = first
self.last = last
self.age = age
self.id = id
def fullname(self):
print(f'{self.first} {self.last} ({self.team})')
def __repr__(self):
return f"{self.first} {self.last}"
def __str__(self):
return f"{self.first}, {self.last}"
class Goalkeeper(Player):
#creator for goalkeepers instances
def __init__(self, first, last, age, id, player_type, diving, positioning, instinct, concentration, power, precision, coolness, overall, team=None):
super().__init__(first, last, age, id)
self.player_type = player_type
self.diving = diving
self.positioning = positioning
self.instinct = instinct
self.concentration = concentration
self.power = power
self.precision = precision
self.coolness = coolness
self.overall = overall
self.team = team
def state_gk(self):
print(f'{self.first} {self.last} {self.age} Diving: {self.diving} Positioning: {self.positioning}')
class Shooter(Player):
#creator for penalty shooters instances
def __init__(self, first, last, age, id, player_type, diving, positioning, instinct, concentration, power, precision, coolness, overall, team=None):
super().__init__(first, last, age, id)
self.player_type = player_type
self.diving = diving
self.positioning = positioning
self.instinct = instinct
self.concentration = concentration
self.power = power
self.precision = precision
self.coolness = coolness
self.overall = overall
self.team = team
# def initiate_gk(player_id):
# #takes a player id and initializes it
# query = '''SELECT first, last, age, id, player_type, diving, positioning,
# instinct, concentration, power, precision, coolness, overall, teams.name FROM players INNER JOIN teams ON players.team_id = teams.id WHERE id=?'''
# with conn:
# c.execute(query, (player_id,))
# gk = c.fetchone()
# return Goalkeeper(gk[0], gk[1], gk[2], gk[3], gk[4], gk[5], gk[6], gk[7], gk[8], gk[9], gk[10], gk[11], gk[12], gk[13])
select_all_gks = 'SELECT first, last, age, id, player_type, diving, positioning, instinct, concentration, power, precision, coolness, overall FROM players WHERE player_type = 0'
def initiate_gk_index(query, index):
#takes a query and index number and initiates the player
with conn:
c.execute(query)
gk = c.fetchall()[index]
return Goalkeeper(gk[0], gk[1], gk[2], gk[3], gk[4], gk[5], gk[6], gk[7], gk[8], gk[9], gk[10], gk[11], gk[12])
def get_gk_by_id(id):
#takes the ID of a players and returns the player
c.execute("SELECT * FROM players WHERE player_type = 0 AND id=:id", {'id':id})
return c.fetchall()
def initiate_teams(team_id):
with conn:
c.execute('SELECT id,name,city FROM teams WHERE id=:id', {'id': team_id})
team = c.fetchall()[0]
return Team({team[1]},{team[2]},{team[0]})