Skip to content
Snippets Groups Projects
Commit acdbd5cb authored by phenixceleste's avatar phenixceleste
Browse files

attack mechanism implemented ; calculs of pokemons stats added

parent c8eb440f
No related branches found
No related tags found
1 merge request!7Resolve "Implement attack use"
Pipeline #9710 passed with stage
in 2 minutes and 7 seconds
@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)
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)
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()
......@@ -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"
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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment