首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Python模拟MOBA手游~铭文篇

Python模拟MOBA手游~铭文篇

作者头像
小Bob来啦
发布2021-04-29 12:04:10
发布2021-04-29 12:04:10
1.1K00
代码可运行
举报
运行总次数:0
代码可运行

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

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

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

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

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

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

这一节分为了三个部分:

  1. 铭文初长成
  2. 铭文加持
  3. 铭文涅槃

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

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

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

一.铭文初长成

源代码:

代码语言:javascript
代码运行次数:0
运行
复制
# 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)

运行结果:

二.铭文加持

源代码:

代码语言:javascript
代码运行次数:0
运行
复制
# 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()

运行结果:

三.铭文涅槃

源代码:

代码语言:javascript
代码运行次数:0
运行
复制
# 初始化颜色等级限制的字典
# 白色-3,绿色-5,蓝色-7,橙色-9,红色-12。
dictLevel = {'白色': 3, '绿色': 5, '蓝色': 7, '橙色': 9, '红色': 12}


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

运行结果:

未完待续...

为你,千千万万遍.

往期推荐:

Python模拟MOBA手游~英雄篇

2021-04-16

华为云高校联盟活动~Python模拟MOBA手游(三)

2021-04-11

三月碎碎念 || Q1总结

2021-04-03

一键三连,就差你了

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-04-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 程序员Bob 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档