zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    python-单链表的实现
    python-树形结构和遍历
    python四种简单排序
    python数据类型
    python安装和配置
    Js 中的false,零值,null,undefined和空字符串对象
    console和chrom-tool
    js中声明Number的五种方式
    vue下拉搜索
    canvas猜数游戏
  • 原文地址:https://www.cnblogs.com/yescarf/p/12907010.html
Copyright © 2011-2022 走看看