-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Artic42/11-creatingDiceClass
#11 dice and auxiliar classes created
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import random | ||
|
||
class dice: | ||
def __init__(self, size=6): | ||
self.size = size | ||
|
||
def setSize(self, size): | ||
self.size = size | ||
|
||
def roll(self): | ||
return random.randint(1, self.size) | ||
|
||
class customDice(dice): | ||
def __init__(self, faces): | ||
self.faces = faces | ||
self.size = len(faces) | ||
|
||
def roll(self): | ||
return random.choice(self.faces) | ||
|
||
class dicePool: | ||
def __init__(self, diceList): | ||
self.diceList = diceList | ||
|
||
def roll(self): | ||
return [d.roll() for d in self.diceList] | ||
|
||
def rollSum(self): | ||
return sum(self.roll()) | ||
|
||
def rollSuccesses(self, target): | ||
return sum([1 for roll in self.roll() if roll >= target]) |