diff --git a/src/main/scala/backend/Main.scala b/src/main/scala/backend/Main.scala index 1c393e279525f1f23c38c523a8e95fe8991216ae..7561898e20a00665527e3af187a05d9f17ec0b77 100644 --- a/src/main/scala/backend/Main.scala +++ b/src/main/scala/backend/Main.scala @@ -1,11 +1,15 @@ @main def main() = val pkmn = PokemonFactory("Bulbasaur") val pkmn2 = PokemonFactory("Charmander") + val pkmn3 = PokemonFactory("Squirtle") println(pkmn) println(pkmn2) + println(pkmn3) - pkmn.attack(CapacityFactory("Vine Whip"), pkmn2) + pkmn.useCapacity(CapacityFactory("Vine Whip"), pkmn2) + pkmn.useCapacity(CapacityFactory("Vine Whip"), pkmn3) println(pkmn) println(pkmn2) + println(pkmn3) diff --git a/src/main/scala/backend/Pokemon/Capacity.scala b/src/main/scala/backend/Pokemon/Capacity.scala index 0a0bdf43c015e4f0d9b9af3ca78b9ddf16c9ac7c..730eeefed9e9b9ca7cdf44e503898e9af6e94687 100644 --- a/src/main/scala/backend/Pokemon/Capacity.scala +++ b/src/main/scala/backend/Pokemon/Capacity.scala @@ -1 +1 @@ -class Capacity(val name: String, val ctype: Type, val maxUses: Int) +class Capacity(val name: String, val ctype: Type, val maxUses: Int, val power: Int) diff --git a/src/main/scala/backend/Pokemon/CapacityFactory.scala b/src/main/scala/backend/Pokemon/CapacityFactory.scala index ef2f4961c666861f1cc60ed305a434d266f852db..1c47d63c9c2349885d96d3583be34ff14e8b1793 100644 --- a/src/main/scala/backend/Pokemon/CapacityFactory.scala +++ b/src/main/scala/backend/Pokemon/CapacityFactory.scala @@ -1,6 +1,6 @@ object CapacityFactory: - private case class VineWhip() extends Capacity("Vine Whip", Grass, 15) + private case class VineWhip() extends Capacity("Vine Whip", Grass, 10, 35) def apply(name: String): Capacity = name match case "Vine Whip" => VineWhip() diff --git a/src/main/scala/backend/Pokemon/Pokemon.scala b/src/main/scala/backend/Pokemon/Pokemon.scala index 7ef4fd7e3ad4124fb7dcba22abe4fada1193d8f5..8f2c2350a1140b57109164180424203202b5935e 100644 --- a/src/main/scala/backend/Pokemon/Pokemon.scala +++ b/src/main/scala/backend/Pokemon/Pokemon.scala @@ -2,25 +2,39 @@ trait Pokemon( // TODO: must add later max_life... private var _name: String, private var _life: Int, val ptype: List[Type], - _pcapacity: List[Capacity], - _attack: Int, - _defense: Int, - _speed: Int + pcapacity: List[Capacity], + baseAttack: Int, + baseDefense: Int, + baseSpeed: Int, + baseLife: Int, + level: Int ): + // getter def name: String = this._name + def life: Int = this._life + // setter def name_=(name: String) = this._name = name + def life_=(life: Int) = this._life = life - def attack(capacity: Capacity, other: Pokemon) = - val multiplier = other.ptype.foldLeft(1.0)(_ * capacity.ctype.typeEfficiency(_).factor) + def attack: Int = 5 + scala.math.floor(2.0 * this.baseAttack * this.level / 100.0).toInt + def defense: Int = 5 + scala.math.floor(2.0 * this.baseDefense * this.level / 100.0).toInt + def speed: Int = 5 + scala.math.floor(2.0 * this.baseSpeed * this.level / 100.0).toInt + def maxLife: Int = scala.math.floor(2.0 * this.baseSpeed * this.level / 100.0).toInt + 10 + this.level - other.decreaseLife(Math.round(multiplier.toFloat)) + def useCapacity(capacity: Capacity, other: Pokemon) = + val multiplier = other.ptype.foldLeft(1.0)(_ * capacity.ctype.typeEfficiency(_).factor) - def life: Int = this._life + val damage = + (((2.0 * (this.level) / 5.0) * (capacity.power) * (this.attack) + / (other.defense)) / 50.0 + 2.0) + * (scala.util.Random.between(0.85, 1.0)) * multiplier + * (if this.ptype.foldLeft(false)(_ || _ == capacity.ctype) then 1.5 else 1.0) - def life_=(life: Int) = this._life = life + other.decreaseLife(Math.round(damage.toFloat)) def decreaseLife(x: Int) = this._life = this._life - x - override def toString(): String = s"[${this.name}] Life: ${this.life}" + override def toString(): String = + s"[${this.name}] Life: ${this.life}\nMaxLife: ${this.maxLife}\nAttack: ${this.attack}\nDefense: ${this.defense}\nSpeed: ${this.speed}\n" diff --git a/src/main/scala/backend/Pokemon/PokemonFactory.scala b/src/main/scala/backend/Pokemon/PokemonFactory.scala index 8bcb85db54162348278c71af357b9689d052866f..23f8126bb02b72a4fc617ddfcfc7bd709cc2afb3 100644 --- a/src/main/scala/backend/Pokemon/PokemonFactory.scala +++ b/src/main/scala/backend/Pokemon/PokemonFactory.scala @@ -1,8 +1,8 @@ object PokemonFactory: - private case class Bulbasaur() extends Pokemon("Bulbasaur", 45, List(Grass, Poison), List(), 49, 49, 45) - private case class Charmander() extends Pokemon("Charmander", 39, List(Fire), List(), 52, 43, 65) - private case class Squirtle() extends Pokemon("Squirtle", 44, List(Water), List(), 48, 65, 43) + private case class Bulbasaur() extends Pokemon("Bulbasaur", 11, List(Grass, Poison), List(), 49, 49, 45, 45, 1) + private case class Charmander() extends Pokemon("Charmander", 12, List(Fire), List(), 52, 43, 65, 39, 1) + private case class Squirtle() extends Pokemon("Squirtle", 11, List(Water), List(), 48, 65, 43, 44, 1) def apply(name: String): Pokemon = name match case "Bulbasaur" => Bulbasaur()