修改后如何使int返回其原始值?

时间:2018-11-26 11:33:59

标签: ios swift

我正在为学校目的制作RPG游戏,我想知道修改后如何取回整数的原始值。

在我的代码中,我有一个战斗机可以进行致命一击,这会使他的攻击力翻一番,而问题是他会在接下来的比赛中保持攻击力……有人有主意吗?

 func warriorAbility(_ attacker: Character, _ target: Character){

    attacker.weapon.damages *= 2

    print("\(attacker.name) the \(attacker.classe) use 'Battlecry !' and do a critical strike of \(attacker.weapon.damages) damages point. He double his atk !")
}
class Sword: Weapon{
init(){
    super.init(damages: 10, name: "Sword")
}
} class Fighter : Character{
init(name: String, classe: Classe){
    super.init(name: name, healthpoint: 100, maxHealthpoint: 100, weapon: Sword(), classe: classe)
}

}

编辑:添加了我的战斗机类和剑类

1 个答案:

答案 0 :(得分:1)

我建议您不要在游戏中改变武器的属性,而必须先对其进行还原。

类似的东西:

struct Weapon {
   let damage: Int
   let criticalMultiplier: Int
   let name: String
}

let sword = Weapon(damage: 10, criticalMultiplier:2, name:"sword")

struct Move {
   let attacker: Character
   let target: Character
   let isCritical: Bool

   func damage() -> Int {
      return attacker.weapon.damage * isCritical ? attacker.weapon.criticalMultiplier : 1
   }
}