Module dice
[hide private]
[frames] | no frames]

Source Code for Module dice

 1  #!/usr/bin/python3 
 2  """ 
 3  This module provides the Dice class (formula based random numbers) 
 4  """ 
 5  import sys 
 6  from random import randint 
 7   
 8   
9 -class Dice(object):
10 """ 11 This class supports formula based dice rolls. 12 The formulae can be described in a few (fairly standard) formats: 13 - DnD style ... D100, 3D6, 3D6+4 14 - ranges ... 4-12 15 - simple numbers ... 50 16 17 @ivar num_dice: (int) number of dice to be rolled, None if a range 18 @ivar dice_type: (int) number of faces on each die, None if a range 19 @ivar plus: (int) number to be added to the roll 20 @ivar min_value: (int) lowest legal value in range, None if a formula 21 @ivar max_value: (int) highest legal value range, None if a formula 22 """ 23
24 - def __init__(self, formula):
25 """ 26 instantiate a roller for a specified formula 27 28 @param formula: (string) description of roll 29 @raise ValueError: illegal formula expression 30 """
31 # formula must be a string (or integer) 32 # if it is just a number, this is simple 33 # figure out what kind of expression this is 34 # see if it has known form and 2 values 35 # process the values 36 # there might be a plus after the dice type 37
38 - def str(self):
39 """ 40 return string representation of these dice" 41 """
42
43 - def roll(self):
44 """ 45 roll this set of dice and return result 46 @return: (int) resulting value 47 """
48