华为云高校联盟活动~Python模拟MOBA手游~铭文篇

举报
小Bob来啦 发表于 2021/04/22 23:24:59 2021/04/22
【摘要】 每日一句:当你真正为自己、为好朋友或家人做一些事时,你就不会轻易放弃。但如果你不热爱这件事,那么你就不会多走一步,也不情愿在周末加班,只会安于现状。上回说到MOBA手游中最重要的是英雄,那么其次于英雄的便属于英雄加成,在MOBA中表现为铭文装配,这两者在游戏中对于游戏体验的作用是巨大的。在MOBA手游中,虽然属性的加成不只是铭文,还有购买的装备,但开局前对铭文的装配,可以给英雄带来不少的提升...

每日一句:当你真正为自己、为好朋友或家人做一些事时,你就不会轻易放弃。但如果你不热爱这件事,那么你就不会多走一步,也不情愿在周末加班,只会安于现状。

上回说到MOBA手游中最重要的是英雄,那么其次于英雄的便属于英雄加成,在MOBA中表现为铭文装配,这两者在游戏中对于游戏体验的作用是巨大的。

在MOBA手游中,虽然属性的加成不只是铭文,还有购买的装备,但开局前对铭文的装配,可以给英雄带来不少的提升,也有利于英雄前期的发育。

在MOBA手游中,不同的铭文会给英雄带来不同属性的增幅,每个英雄也有各自最适合的铭文搭配。

那么铭文属性的改变在代码中要如何处理呢,比如铭文升级、铭文属性的改变,铭文属性在每个等级之间的改变并不是固定的,一般来说是等级越高,属性的提升也越高。

由于铭文升级和装配都是在英雄开局前就设定好了的,所以在代码中只需考虑关于铭文的升级,一般表现形式是几个低级铭文可以合成一个等级更高的铭文,其中属性的提升是按照百分比提升的。

这一节分为了三个部分:

  1. 铭文初长成

  2. 铭文加持

  3. 铭文涅槃


第一部分挺简单的,是对铭文属性的初始化

第二部分为铭文升级,需要注意的是升级后铭文属性的改变,以及原有铭文的数量。

第三部分作为特列,演示了当我们铭文升级到最高等级时,不可再升级,也就是说在升级时需要加上判断。


一.铭文初长成


源代码:

    # Todo:补全Rune类
    class RUne:
    # Todo:初始化属性name, color, attribute, attributeValue, level
        def __init__(self, name, color, attribute, attributeValue, level):
            self.name=name
            self.color=color
            self.attribute=attribute
            self.attributeValue=attributeValue
            self.level=level
    # Todo:在Rune类中打印输出属性的值
            print("Rune:{},{},{},{},{}".format(self.name,self.color,self.attribute,self.attributeValue,self.level))
    
    # Todo: 输入五行字符,按照顺序依次为Rune类对象的名称(name)、颜色(color)、属性名称(attribute)、属性值(attributeValue)、等级(level)初始化
    name=input()
    color=input()
    attribute=input()
    attributeValue=input()
    level=input()
    
    # Todo:实例化Rune对象,打印输出结果 name,color,attribute,attributeValue,level
    
    rune=RUne(name,color,attribute,attributeValue,level)

    运行结果:


    二.铭文加持


    源代码:
      # Todo:补全Rune类
      class Rune:
      # Todo:初始化属性name, color, attribute, attributeValue, level
          def __init__(self, name, color, attribute, attributeValue, level):
              self.name = name
              self.color = color
              self.attribute = attribute
              self.attributeValue = attributeValue
              self.level = level
      
      # Todo:  传入参数为:铭文数量,没有返回值。
      #       最初级的铭文为1级,5个1级铭文可以合成1个2级铭文,5个2级铭文可以合成3级铭文,以此类推.......
      #       铭文每提升一个等级,属性值增加20%。
          def levelUp(self, number):
              count=0
              while (number>=5):
                  number=number//5
                  count+=1
                  self.attributeValue+=self.attributeValue*0.2
              self.level+=count
      # 打印输出对象信息
          def printObj(self):
              self.attributeValue = round(self.attributeValue)
              print('Rune:{0},{1},{2},{3},{4}'.format(self.name, self.color, self.attribute, self.attributeValue, self.level))
      
      # Todo: 输入五行字符,按照顺序依次为Rune类对象的名称(name)、颜色(color)、属性名称(attribute)、属性值(attributeValue)、等级(level)初始化
      name=input()
      color=input()
      attribute=input()
      attributeValue=int(input())
      level=int(input())
      number=int(input())
      # Todo:实例化Rune对象
      rune=Rune(name,color,attribute,attributeValue,level)
      
      # Todo:调用levelUp方法,实现铭文提升等级的功能
      rune.levelUp(number)
      
      # Todo:调用printObj方法,打印输出对象信息
      rune.printObj()
      运行结果:

      三.铭文涅槃


      源代码:

        # Todo:补全Rune类
        class Rune:
        # Todo:初始化属性name, color, attribute, attributeValue, level
            def __init__(self, name, color, attribute, attributeValue, level):
                self.name = name
                self.color = color
                self.attribute = attribute
                self.attributeValue = attributeValue
                self.level = level
        
        # Todo:  传入参数为:铭文数量,没有返回值。
        #       铭文每提升一个等级,属性值增加20%。
        #       铭文根据不同的颜色,提升等级的上限不同,白色-3,绿色-5,蓝色-7,橙色-9,红色-12。
        #       达到等级上限,铭文等级不可提升
            def levelUp(self, number):
                t0=number
                i=1
                while number>5:
                    if self.level<dictLevel[self.color]:
                        number=t0/(5**i)
                        self.level+=1
                        self.attributeValue*=1.2
                        i+=1
                    else:
                        print("已经达到铭文等级上限,不可再升级")
                        break
                    pass
        
        # 打印输出对象信息
            def printObj(self):
                self.attributeValue = round(self.attributeValue)
                print('Rune:{0},{1},{2},{3},{4}'.format(self.name, self.color, self.attribute, self.attributeValue, self.level))
        
        # Todo: 输入五行字符,按照顺序依次为Rune类对象的名称(name)、颜色(color)、属性名称(attribute)、属性值(attributeValue)、等级(level)初始化
        name=input()
        color=input()
        attribute=input()
        attributeValue=int(input())
        level=int(input())
        number=int(input())
        
        rune=Rune(name,color,attribute,attributeValue,level)
        
        # Todo:调用levelUp方法,实现铭文提升等级的功能
        rune.levelUp(number)
        
        # Todo:调用printObj方法,打印输出对象信息
        rune.printObj()

        运行结果:

        【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
        • 点赞
        • 收藏
        • 关注作者

        评论(0

        0/1000
        抱歉,系统识别当前为高风险访问,暂不支持该操作

        全部回复

        上滑加载中

        设置昵称

        在此一键设置昵称,即可参与社区互动!

        *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

        *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。