Dice to Static + Items
This commit is contained in:
7
dice.py
7
dice.py
@@ -2,13 +2,14 @@ import random as rd
|
||||
from . import serializable
|
||||
|
||||
class Dice(serializable.Serializable):
|
||||
def __init__(self, seed=42):
|
||||
self.seed = seed
|
||||
rd.seed(self.seed)
|
||||
def __init__(self):
|
||||
raise TypeError("Un dé ne peut pas être instanciée!")
|
||||
|
||||
@staticmethod
|
||||
def roll(self, num_faces=20):
|
||||
return rd.randrange(start=1, stop=num_faces+1, step=1)
|
||||
|
||||
@staticmethod
|
||||
def head_or_tails():
|
||||
result = rd.randint(0,1)
|
||||
if result: # true
|
||||
|
||||
10
item.py
10
item.py
@@ -8,4 +8,12 @@ class Item(Serializable):
|
||||
self.weight = weight
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user