-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.kt
49 lines (41 loc) · 1.16 KB
/
Enemy.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package clases
open class Enemy(val name: String, val strength: Int) {
protected var direction: String = "LEFT"
init {
println("Iniciando superclase de $name")
}
protected fun changeDirection() {
direction = if (direction == "RIGHT") "LEFT" else "RIGHT"
println("$name va en dirección $direction")
}
protected fun die() {
println("$name ha muerto")
}
open fun collision(collider: String) {
when (collider) {
"Weapon" -> die()
"Enemy" -> changeDirection()
}
}
}
class Goomba : Enemy("Goomba", 1) {
//(name: String, strength: int):
//Enemy(name,strength){
init {
println("Iniciando subclase de $name")
}
}
class Koopa : Enemy("Koopa", 2) {
override fun collision(collider: String) {
//super.collision(collider)
println("Usando la colision de la clase Enemy")
when (collider) {
"Weapon" -> {
var state = "Shell"
println("El estado ahora es: $state")
}
"Enemy" -> changeDirection()
}
//println("Usando la colision de la clase Enemy")
}
}