Dice to Static + Items

This commit is contained in:
KuMiShi
2026-01-25 16:01:34 +01:00
parent 65c9d206dd
commit b5806605ff
2 changed files with 13 additions and 4 deletions

View File

@@ -2,13 +2,14 @@ import random as rd
from . import serializable from . import serializable
class Dice(serializable.Serializable): class Dice(serializable.Serializable):
def __init__(self, seed=42): def __init__(self):
self.seed = seed raise TypeError("Un dé ne peut pas être instanciée!")
rd.seed(self.seed)
@staticmethod
def roll(self, num_faces=20): def roll(self, num_faces=20):
return rd.randrange(start=1, stop=num_faces+1, step=1) return rd.randrange(start=1, stop=num_faces+1, step=1)
@staticmethod
def head_or_tails(): def head_or_tails():
result = rd.randint(0,1) result = rd.randint(0,1)
if result: # true if result: # true

View File

@@ -9,3 +9,11 @@ class Item(Serializable):
def __str__(self): def __str__(self):
return self.name + '(' + self.weight + ' kg)' + ': ' + self.description return self.name + '(' + self.weight + ' kg)' + ': ' + self.description
class Equippable(Item):
def __init__(self, name, description, weight = 10):
super().__init__(name, description, weight)
class Consummable(Item):
def __init__(self, name, description, weight = 10):
super().__init__(name, description, weight)