本文整理汇总了Python中dice.Dice.get_total_number方法的典型用法代码示例。如果您正苦于以下问题:Python Dice.get_total_number方法的具体用法?Python Dice.get_total_number怎么用?Python Dice.get_total_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dice.Dice
的用法示例。
在下文中一共展示了Dice.get_total_number方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DiceGame
# 需要导入模块: from dice import Dice [as 别名]
# 或者: from dice.Dice import get_total_number [as 别名]
class DiceGame(object):
def __init__(self, player1, player2):
# Private variables (Start "__")
self.__players = []
self.__players.append(player1)
self.__players.append(player2)
self.__the_dices = Dice()
self.__random_value = self.__the_dices.get_total_number()
class_name = self.__class__.__name__
print("""
************************
{class_name}, created
************************
""".format(class_name=class_name))
def info_game(self):
return """
*******************************
Game Started
{player} began to edge game.
Players
1. Player = {player1}
2. Player = {player2}
Random Value
{random_value}
*******************************
""".format(player=self.__players[0], player1=self.__players[0],
player2=self.__players[1], random_value=self.__random_value)
def get_players(self):
return self.__players
def select_player(self):
random_player = []
random_player.append(random.choice(self.__players))
list_difference = list(set(self.__players) - set(random_player))
random_player += list_difference
return random_player
def start_game(self):
self.__players = self.select_player()
self.info_game()
def get_winner_player(self):
player1_diff = abs(self.__random_value - self.__players[0].get_sum_of_dices())
player2_diff = abs(self.__random_value - self.__players[1].get_sum_of_dices())
if player1_diff == player2_diff:
return None
return self.__players[0] if player1_diff < player2_diff else self.__players[1]
def game_report(self):
self.__winner_player = self.get_winner_player()
print("""
*****************************
Winner
{winner_player}
Random Value
{random_value}
Player's Value
{player1} = {player1_value}
{player2} = {player2_value}
*****************************
""".format(winner_player=self.__winner_player if self.__winner_player else "Draw",
random_value=self.__random_value,
player1=self.__players[0].__str__(), player2=self.__players[1].__str__(),
player1_value=self.__players[0].get_sum_of_dices(),
player2_value=self.__players[1].get_sum_of_dices()))
@staticmethod
def __str__():
return "Dice Game"
def __del__(self):
class_name = self.__class__.__name__
print("""
************************
{class_name}, deleted
************************
""".format(class_name=class_name))
示例2: throw_dices
# 需要导入模块: from dice import Dice [as 别名]
# 或者: from dice.Dice import get_total_number [as 别名]
def throw_dices(self):
self.__sum_of_dices = Dice.get_total_number()
return self.__sum_of_dices