-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stats.py
62 lines (49 loc) · 1.6 KB
/
Stats.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
import time
class PlayerStats(object):
def __init__(self, startLives, countDown = 5):
self.isDead = False
self.timeAlive= 0
self.foodEaten= 0
self.deaths = 0
self.snakesKilled = 0
self.lives = startLives
self.startLives = startLives
self.startTimeAlive = time.time()
self.countDownResurrectStart = 0
self.countDown = countDown
def eatFood(self):
self.foodEaten +=1
def die(self):
self.countDownResurrectStart = time.time()
self.deaths +=1
self.isDead = True
def resurrect(self):
self.isDead = False
self.restartFood()
self.restartTimer()
def killedSnake(self):
self.snakesKilled +=1
def restartTimer(self):
self.timeAlive = 0
self.startTimeAlive = time.time()
def restartFood(self):
self.foodEaten = 0
def restartSnakesKilled(self):
self.snakesKilled = 0
def restartAll(self):
self.deaths = 0
self.lives = self.startLives
self.isDead = False
self.restartFood()
self.restartSnakesKilled()
self.restartTimer()
def getTimeAlive(self):
if(not self.isDead):
self.timeAlive = time.time() - self.startTimeAlive
return round (self.timeAlive,1)
def getCountDown(self):
if (self.lives > 0 and self.isDead):
elapsedTimeSinceDeath = time.time() - self.countDownResurrectStart
rounded = round(self.countDown - elapsedTimeSinceDeath,1)
return rounded if rounded > 0 else 0
return self.countDown