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()

 

posted @ 2020-05-17 21:30  yescarf  阅读(142)  评论(0编辑  收藏  举报