2.23骰子游戏
Posted yescarf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2.23骰子游戏相关的知识,希望对你有一定的参考价值。
#写一个骰子游戏 import random class Game: def __init__(self,player1,player2): self.player1 = player1 self.player2 = player2 def star_game(self): self.player1.cast() self.player2.cast() print(self.player1,self.player2) class Player: def __init__(self,name,sex,*dice): self.name = name self.sex = sex self.dices = dice #玩家抛骰子 def cast(self): for dice in self.dices: dice.move() def guess_game(self): return (4,2) def __str__(self): player_dice_list = [self.dices[0].count,self.dices[1].count,self.dices[2].count] return "姓名%s,投掷的骰子点数信息为%s"%(self.name,str(player_dice_list)) class Dice: def __init__(self): self.count = 0 def move(self): self.count = random.randint(1,7) #游戏开始之前准备六颗骰子 d1 = Dice() d2 = Dice() d3 = Dice() d4 = Dice() d5 = Dice() d6 = Dice() p1 = Player(‘player1‘,‘男‘,d1,d2,d3) p2 = Player(‘player2‘,‘女‘,d4,d5,d6) for i in range(0,5): print(‘第%d次游戏的情况........‘ % (i + 1)) game = Game(p1,p2) game.star_game()
以上是关于2.23骰子游戏的主要内容,如果未能解决你的问题,请参考以下文章