-
Notifications
You must be signed in to change notification settings - Fork 1
/
Players.py
68 lines (56 loc) · 1.68 KB
/
Players.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
import json
class Player:
def __init__(self, name, gamesWon=0):
self.name = name
self.gamesWon = gamesWon
self.gamesLost = 0
self.IsKingOfHill = False
self.currStreak=0
self.WP = 100
self.add()
def loaddata(self):
with open('data.json') as json_file:
data = json.load(json_file)
return data
def writedata(self, data):
writing = open("data.json", "w")
json.dump(data, writing)
writing.close()
def add(self):
data = self.loaddata()
data['people'].append({
"name": self.name,
"isKingOfHill": False,
"gamesWon": 0,
"gamesLost": 0,
"currentStreak": 0,
"WP": 100
})
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
def addWin(self):
people = self.loaddata()["people"]
index = self.getPlayerIndex
people[index]["gamesWon"] += 1
people[index]["currentStreak"] += 1
self.gamesWon += 1
self.currStreak=self.gamesWon
self.calcWP()
def addLoss(self):
self.gamesLost += 1
self.currStreak = 0
self.calcWP()
def makeKingOfHill(self):
self.IsKingOfHill = True
def dethrone(self):
self.IsKingOfHill = False
self.addLoss()
def calcWP(self):
self.WP = (self.gamesWon / (self.gamesLost + self.gamesLost)) * 100
def setWin(self, num):
self.gamesWon = num
def getPlayerIndex(self, name):
data = self.loaddata()
people = data["people"]
playerIndex = people.index(name)
return playerIndex