当前位置: 首页>>代码示例>>Python>>正文


Python Move.getPower方法代码示例

本文整理汇总了Python中Move.Move.getPower方法的典型用法代码示例。如果您正苦于以下问题:Python Move.getPower方法的具体用法?Python Move.getPower怎么用?Python Move.getPower使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Move.Move的用法示例。


在下文中一共展示了Move.getPower方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: attack

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import getPower [as 别名]
def attack(move, pokemon1, pokemon2):
    # Creating an empty string to store the results of the attack function
    tempMsg = ""

    # Reading "Type Advantages.csv" file to determine type advantages and the damage modifier
    # Stores the line number in the csv as the key and a list giving information about type advantage for the value
    fin = open("Type Advantages.csv", "r")
    typeDic = {}
    for line in fin:
        line = line.strip()
        typeList = line.split(",")
        typeDic[typeList[0]] = typeList
        # This list contains a number in the first position, the attack type in the second, the defending type in the third,
        # and the appropriate damage multiplier in the fourth
    fin.close()

    # Making the input string into an actual move object
    move = Move(move)

    # This modifier is used in damage calculations; it takes into account type advantage and STAB bonus
    modifier = 1

    # Calculating Type advantages using "Type Advantages.csv" file
    for key in typeDic:
        # If the attacking and defending types match up, multiply the modifier by the damage multiplier from the list
        if typeDic[key][1] == move.type and typeDic[key][2] == pokemon2.type1:
            modifier *= float(typeDic[key][3])

        # Didn't use elif; Just in case you get a 4x or 0.25x modifier based on double type
        if typeDic[key][1] == move.type and typeDic[key][2] == pokemon2.type2:
            modifier *= float(typeDic[key][3])

    # Calculating STAB (Same-type Attack Bonus)
    if move.type == pokemon1.type1:
        modifier *= Pokemon.STAB

    elif move.type == pokemon1.type2:
        modifier *= Pokemon.STAB

    # Damage formula also has a random element
    modifier *= random.uniform(0.85, 1.0)

    print()

    # Appending the useMove function to the output
    tempMsg += pokemon1.useMove(move)

    # ATK/DEF or SpATK/SpDEF or Status? Using the Pokemon damage formula
    # If the move is "Physical", the damage formula will take into account attack and defense
    if move.kind == "Physical":
        damage = int(
            (((2 * pokemon1.getLevel()) + 10) / 250 * (pokemon1.battleATK / pokemon2.battleDEF) * move.getPower() + 2)
            * modifier
        )
        tempMsg += "\n" + pokemon2.loseHP(damage)
    # If the move is "Special", the damage formula will take into account special attack and special defense
    elif move.kind == "Special":
        damage = int(
            (
                ((2 * pokemon1.getLevel()) + 10) / 250 * (pokemon1.battleSpATK / pokemon2.battleSpDEF) * move.getPower()
                + 2
            )
            * modifier
        )
        tempMsg += "\n" + pokemon2.loseHP(damage)

    # Stat Changing moves
    else:
        # If the move is stat-changing, it does 0 damage and the modifier is set to 1 (so it doesn't return super effective or not very effective)
        damage = 0
        modifier = 1

        # Going through each kind of different stat change based on the move type
        if move.kind == "a-":
            pokemon2.atkStage -= 1
            pokemon2.battleATK = pokemon2.originalATK * statMod(pokemon2.atkStage)
            tempMsg += "\n" + pokemon2.name + "'s attack fell! "

        elif move.kind == "a+":
            pokemon1.atkStage += 1
            pokemon1.battleATK = pokemon1.originalATK * statMod(pokemon1.atkStage)
            tempMsg += "\n" + pokemon1.name + "'s attack rose! "

        elif move.kind == "d+":
            pokemon1.defStage += 1
            pokemon1.battleDEF = pokemon1.originalDEF * statMod(pokemon1.defStage)
            print(pokemon1.name + "'s defense rose! ")
            tempMsg += "\n" + pokemon1.name + "'s defense rose! "

        elif move.kind == "sa+":
            pokemon1.spAtkStage += 1
            pokemon1.battleSpATK = pokemon1.originalSpATK * statMod(pokemon1.spAtkStage)
            print(pokemon1.name + "'s special attack rose! ")
            tempMsg += "\n" + pokemon1.name + "'s special attack rose! "

        elif move.kind == "sd+":
            pokemon1.spDefStage += 1
            pokemon1.battleSpDef = pokemon1.originalSpDEF * statMod(pokemon1.spDefStage)
            tempMsg += "\n" + pokemon1.name + "'s special defense rose! "

#.........这里部分代码省略.........
开发者ID:christophercao1,项目名称:Pokemon-Simulator-in-Python,代码行数:103,代码来源:Attack.py


注:本文中的Move.Move.getPower方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。