-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMario.kt
58 lines (51 loc) · 1.39 KB
/
Mario.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
50
51
52
53
54
55
56
57
58
package clases
import java.util.*
import kotlin.concurrent.schedule
class Mario(var vidas: Int = 3) {
init {
println("It's me! Mario!")
}
private var state = "small" // Mario es pequeño al iniciar el juego
set(value) {
val before = field
field = value
println("Tu estado ahora es $field")
if (value == "Star") {
Timer("SettingUp", false).schedule(10000) {
field = before
println("Tu estado ahora es $field")
}
}
}
private var lives = 3 // Uno comienza el juego con tres vidas
set(value){
if(field == 1){
field = 0
gameOver()
}
else if (field == 0){
println("Necesitas volver a jugar")
}
else{
field = value
}
}
val isAlive: Boolean
get() {
return lives >= 1
}
fun collision(collisionObj: String) {
when (collisionObj) {
"Goomba" -> lives--
"Super Mushroom" -> state = "Super Mario"
"Fire flower" -> state = "Fire Mario"
"Star" -> state = "Star"
}
}
fun getLives(): String {
return "$lives vidas"
}
}
private fun gameOver(){
println("JUEGO TERMINADO")
}