本文整理汇总了Python中die.Die类的典型用法代码示例。如果您正苦于以下问题:Python Die类的具体用法?Python Die怎么用?Python Die使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Die类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DieRollTest
class DieRollTest(unittest.TestCase):
"""Test the functionality of the Die class' roll function."""
def setUp(self):
self.possible_values = [1, 2, 3, "Dog", "Cat", "Hippo"]
self.new_die = Die(self.possible_values)
def tearDown(self):
del self.possible_values
del self.new_die
def test_roll_once(self):
"""Roll the die once and ensure the returned value is in possibleValues"""
self.assertIn(self.new_die.roll(), self.possible_values,
"Rolled value was not in possibleValues of Die")
def test_rolled_value_changes(self):
"""Roll the die a number of times and make sure it changes value"""
holding_value = self.new_die.roll()
for i in range(10):
if self.new_die.roll() != holding_value:
self.assertTrue(True)
return
self.assertTrue(False, "Die Value did not change from Holding Value "
"for 10 rolls")
def test_currentValue_is_updated_to_rolled_value(self):
"""Make sure that the Die's currentValue is updated to match what is rolled."""
self.new_die.currentValue = 5
self.assertEqual(self.new_die.roll(), self.new_die.currentValue,
"Current Value was not different from rolled")
示例2: test_roll_one_die
def test_roll_one_die(self):
"""Roll one die using the roll_the_dice function."""
angry_game = AngryDiceGame()
single_die = Die([1,2,3,"Dog"])
single_die.currentValue = 7
angry_game.roll_the_dice([single_die])
self.assertNotEqual(single_die.currentValue, 7, "Die was not rolled")
示例3: __init__
def __init__(self, conf={}):
conf = self.get_conf_values()
self.die = Die(no_of_faces=conf['no_of_faces_of_die'])
self.board = Board(no_of_rows=conf['no_of_rows'],
no_of_columns=conf['no_of_columns'],
snakes_conf=conf['snakes'],
ladders_conf=conf['ladders'],
die=self.die)
示例4: main
def main():
theDie = Die()
count = eval(input("How many times should I roll the die? "))
c1 = 0
c2 = 0
c3 = 0
c4 = 0
c5 = 0
c6 = 0
for i in range(count):
theDie.roll()
val = theDie.getFaceValue()
if val == 1:
c1 = c1 + 1
elif val == 2:
c2 = c2 + 1
elif val == 3:
c3 = c3 + 1
elif val == 4:
c4 = c4 + 1
elif val == 5:
c5 = c5 + 1
elif val == 6:
c6 = c6 + 1
else:
print ("Error - value of die was", val)
c1Percent = float(c1)/count * 100
c2Percent = float(c2)/count * 100
c3Percent = float(c3)/count * 100
c4Percent = float(c4)/count * 100
c5Percent = float(c5)/count * 100
c6Percent = float(c6)/count * 100
print ("Value 1 came up:", c1, "or a percentage of", c1Percent)
print ("Value 2 came up:", c2, "or a percentage of", c2Percent)
print ("Value 3 came up:", c3, "or a percentage of", c3Percent)
print ("Value 4 came up:", c4, "or a percentage of", c4Percent)
print ("Value 5 came up:", c5, "or a percentage of", c5Percent)
print ("Value 6 came up:", c6, "or a percentage of", c6Percent)
示例5: main
def main():
trisha = Die(-5)
## trisha.roll()
print("Trisha", trisha.getFaceValue())
print(trisha)
## sheldon = Die()
## for i in range(10):
## trisha.roll()
## sheldon.roll()
## tValue = trisha.getFaceValue()
## sValue = sheldon.getFaceValue()
## if sValue <= tValue:
## sheldon.setFaceValue(5.5)
## sValue = sheldon.getFaceValue()
## print("Trisha: " + str(tValue), end = " ")
## print("Sheldon: " + str(sValue))
## if tValue > sValue:
## print ("Trisha won!")
## elif tValue == sValue:
## print("Tie")
## else:
## print("Sheldon won!")
print ("Done!")
示例6: __init__
def __init__(self):
self.board = Board()
self.move_manager = MoveManager(self.board)
self.players = [PlayerMoveFirstPawn(p, self.board) for p in Players]
self.current = Players.black
self.die = Die()
self._retry_counter = 0
# save finishers
self.finishers = []
self.event_ready = threading.Event()
self.event_finished = threading.Event()
# Look to serialize canvas drawings
self.lock = threading.Lock()
# Thread for tk mainloop, this runs until the program gets exited
self.tk_thread = threading.Thread(target=self._tk_mainloop)
示例7: LuckyPython
class LuckyPython(object):
def __init__(self, conf={}):
conf = self.get_conf_values()
self.die = Die(no_of_faces=conf['no_of_faces_of_die'])
self.board = Board(no_of_rows=conf['no_of_rows'],
no_of_columns=conf['no_of_columns'],
snakes_conf=conf['snakes'],
ladders_conf=conf['ladders'],
die=self.die)
def get_board(self):
return self.board.get_board()
def get_changed_player(self):
return self.board.get_active_player()
def get_score(self):
score = self.die.get_score()
return score
def add_player(self, object):
return self.board.add_player(object)
def set_board_status(self, object):
if object['status'] == 'start':
self.board.msg = 'Starting the game'
self.board.status = 'P' #start play
def set_score(self, score_object):
return self.board.set_score(score_object)
def get_turn(self):
return self.board.get_turn()
def get_conf_values(self):
""" get from user """ #FIXME
conf_dict = {'no_of_columns': 10,
'no_of_rows': 10,
'snakes': ((20, 10), (40, 6), (66, 33), (98, 18)),
'ladders': ((5, 14), (32, 62), (46, 58), (60, 84)),
'no_of_faces_of_die': 6}
return conf_dict
示例8: load_sprites
def load_sprites(self):
self.player_group = CameraSpriteGroup()
self.player_bullet_group = CameraSpriteGroup()
self.player_max_hp = 20
self.player_healthbar = HealthBar(self.player_max_hp, self.player_max_hp, "res/player_healthbar.png", (128, 16))
self.player_healthbar.rect.x = -55
self.player_healthbar.rect.y = 10
self.player_hb_group = CameraSpriteGroup()
self.player_hb_group.add(self.player_healthbar)
self.enemy_group = CameraSpriteGroup()
self.enemy_bullet_group = CameraSpriteGroup()
self.health_bar_sprites = CameraSpriteGroup()
self.max_badguys = 0
self.guys_killed = 0
self.levels = [{"img":"res/levels/level1.png", "badguys":2, "goal":6}, {"img":"res/levels/level2.png", "badguys":5, "goal":10}]
self.cur_level = 0
self.load_level(0)
self.menu = Menu()
self.win = Win()
self.die = Die()
示例9: Die
import pygal
from die import Die
# Create a D6 and a D10.
die_1 = Die()
die_2 = Die(10)
# Make some rolls, and store results in a list.
results = []
for roll_num in range(50000):
result = die_1.roll() + die_2.roll()
results.append(result)
# Analyze the results.
frequencies = []
max_result = die_1.num_sides + die_2.num_sides
for value in range(2, max_result + 1):
frequency = results.count(value)
frequencies.append(frequency)
# print(frequencies)
# Visualize the results.
hist = pygal.Bar()
hist.title = "Results of rolling a D6 and a D10 50,000 times."
hist.x_labels = Die.x_labels(2, max_result)
开发者ID:crystalDf,项目名称:Python-Crash-Course-Chapter-15-Data-Visualization,代码行数:31,代码来源:different_dice_visual.py
示例10: Die
import pygal
from die import Die
die1 = Die()
die2 = Die(10)
results = []
for roll_num in range(5000):
result = die1.roll() + die2.roll()
results.append(result)
frequencies = []
max_result = die1.num_sides + die2.num_sides
for value in range(2, max_result+1):
frequency = results.count(value)
frequencies.append(frequency)
# create a histogram
hist = pygal.Bar()
# histogram details/styling
hist.title = "Results of rolling a D6 and a D10 50,000 times."
hist.x_labels = list(range(2, max_result+1))
hist.x_title = "Result"
hist.y_title = "Frequency of Result"
# add a series of values to the chart
hist.add('D6 + D10', frequencies)
# render the chart to a SVG file
hist.render_to_file('diff_die_visual.svg')
示例12: Die
from die import Die
import pygal
# Create a D6 and a D10.
die_1 = Die()
die_2 = Die(10)
# Make some rolls, and store results in a list.
results = []
for roll_num in range(50000):
result = die_1.roll() + die_2.roll()
results.append(result)
# Analyze the results.
frequencies = []
示例13: Die
#die_visual.py
import pygal
from die import Die
# Create a D6.
die = Die()
# Make some rolls, and store results in a list.
#results = []
#for roll_num in range(1000):
# result = die.roll()
# results.append(result)
results=[ die.roll() for result in range(1000) ]
# Analyze the results.
#frequencies = []
#for value in range(1, die.num_sides+1):
# frequency = results.count(value)
# frequencies.append(frequency)
frequencies = [ results.count(value) for value in range(1, die.num_sides+1) ]
#print(results)
print(frequencies)
# Visualize the results.
# A histogram is a bar chart showing how often certain results occur.
hist = pygal.Bar()
hist.title = "Results of rolling one D6 1000 times."
#hist.x_labels = ['1', '2', '3', '4', '5', '6']
hist.x_labels = [ num for num in range(1, 7) ]
hist.x_title = "Result"
hist.y_title = "Frequency of Result"
示例14: Die
#die_visual.py
import pygal
from die import Die
# Create two D6 dice.
die_1 = Die()
die_2 = Die()
# Make some rolls, and store results in a list.
#results = []
#for roll_num in range(1000):
# result = die_1.roll() + die_2.roll()
# results.append(result)
results = [ die_1.roll() + die_2.roll() for roll_num in range(1000) ]
# Analyze the results.
#frequencies = []
max_results = die_1.num_sides + die_2.num_sides
#for value in range(2, max_results+1):
# frequency = results.count(value)
# frequencies.append(frequency)
frequencies = [ results.count(value) for value in range(2, max_results+1) ]
#print(results)
print(frequencies)
# Visualize the results.
# A histogram is a bar chart showing how often certain results occur.
hist = pygal.Bar()
hist.title = "Results of rolling two D6 1000 times."
#hist.x_labels = ['2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
示例15: Die
import pygal
from die import Die
# Create a D6
die = Die()
# Make some rolls, and store results in a list.
results = []
for roll_num in range(1000):
result = die.roll()
results.append(result)
# Analyze the results.
frequencies = []
for value in range(1, die.num_sides + 1):
frequency = results.count(value)
frequencies.append(frequency)
# print(frequencies)
# Visualize the results.
hist = pygal.Bar()
hist.title = "Results of rolling one D6 1000 times."
hist.x_labels = Die.x_labels(1, 6)
hist.x_title = "Result"
hist.y_title = "Frequency of Result"
hist.add('D6', frequencies)