예제 #1
0
 def test_createDict3(self):
     tab = Table("test1", {'roll': '2d2', '2': 'two', '3-4': 'threefour'})
     res1 = tab.use()
     self.assertEqual(res1, 'threefour')
     res2 = tab.roll()
     self.assertEqual(res2, 'threefour')
     values = tab.results()
     values.sort()
     self.assertEqual(values, ['threefour', 'two'])
예제 #2
0
 def test_createDict(self):
     tab = Table("test1", {'1': 'one', '2': 'two'})
     res1 = tab.use()
     self.assertEqual(res1, 'two')
     res2 = tab.roll()
     self.assertEqual(res2, 'two')
     values = tab.results()
     values.sort()
     self.assertEqual(values, ['one', 'two'])
예제 #3
0
# situation.

# This first example creates a table out of a list.  Each item in the list has the
# same chance of being selected.

tab1 = Table('PlanetaryOcean',
             ['On Surface', 'Under A Thin Crust', 'Deep Underground'])

# this second example creates a table out of a python dictionary.  The first element
# is the roll, the second is the result for each "line" in the table.

tab2 = Table('Race', {'1-3': 'Human', '4-5': "Elf", '6': 'Dwarf'})

# and you can use these tables in the obvious ways:
print('Using the PlanetaryOcean table: %s' % tab1.use())
print('Using the Race table: %s' % tab2.roll())

# Rule 2: many functions support a "debug=True" option.  If you pass that
# option in, it will print out debugging information designed to help you
# figure out what is going on, and why it is happening.

# You can also do several other interesting things with tables:

# Get a list of all possible results:
print('Possible results for the first table: %s' % tab1.results())

# Set the dice that will be used, and get that later:

tab3 = Table('Race', {
    'roll': '2d4',
    '2-5': 'Human',