added 4 methods to Statistics class

This commit is contained in:
jonspacz 2020-04-01 14:46:49 +02:00
parent 1c28b3a644
commit ff29e52a8d

View File

@ -1,6 +1,46 @@
class Statistics: class Statistics:
def __init__(self): def __init__(self):
self.hp self.hp = 100
self.hunger self.hunger = 100
self.thirst self.thirst = 100
self.stamina self.stamina = 100
# methods that don't let the values pass below 0 and over 100 during change
def set_hp(self, hp_diff):
if 0 <= self.hp + hp_diff <= 100:
self.hp = self.hp + hp_diff
else:
if self.hp + hp_diff <= 0:
self.hp = 0
else:
self.hp = 100
def set_hunger(self, hunger_diff):
if 0 <= self.hp + hunger_diff <= 100:
self.hp = self.hp + hunger_diff
else:
if self.hp + hunger_diff <= 0:
self.hp = 0
else:
self.hp = 100
def set_thirst(self, thirst_diff):
if 0 <= self.hp + thirst_diff <= 100:
self.hp = self.hp + thirst_diff
else:
if self.hp + thirst_diff <= 0:
self.hp = 0
else:
self.hp = 100
def set_stamina(self, stamina_diff):
if 0 <= self.hp + stamina_diff <= 100:
self.hp = self.hp + stamina_diff
else:
if self.hp + stamina_diff <= 0:
self.hp = 0
else:
self.hp = 100