Skip to content
Snippets Groups Projects
Commit 0a8ac89b authored by izajime's avatar izajime
Browse files

mejoras

parent fcfd72fd
No related branches found
No related tags found
3 merge requests!65Feature:,!7Minijuego 1,!6Minijuego 1
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
......
......@@ -18,14 +18,16 @@ class Minijuego1 : AppCompatActivity() {
private lateinit var puntajeTextView: TextView // TextView para mostrar el puntaje
private lateinit var tiempoTextView: TextView // TextView para mostrar el tiempo
private var puntaje = 0 // Variable para almacenar el puntaje
private val handler = Handler(Looper.getMainLooper()) // Crear Handler con el Looper del hilo principal
private val handler =
Handler(Looper.getMainLooper()) // Crear Handler con el Looper del hilo principal
private var tiempoRestante = 30 // Tiempo límite del juego (en segundos)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_minijuego1)
frameLayout = findViewById(R.id.frameLayout) // Referencia al FrameLayout
puntajeTextView = findViewById(R.id.puntajeTextView) // Referencia al TextView para el puntaje
puntajeTextView =
findViewById(R.id.puntajeTextView) // Referencia al TextView para el puntaje
tiempoTextView = findViewById(R.id.tiempoTextView) // Referencia al TextView para el tiempo
// Iniciar el juego
......@@ -45,7 +47,15 @@ class Minijuego1 : AppCompatActivity() {
private fun agregarBoton() {
val boton = Button(this) // Crear un nuevo botón
boton.setBackgroundResource(R.drawable.hueso) // Imagen del botón
// Determinar aleatoriamente si el botón será un "hueso" o una "bomba"
val esHueso = Random.nextFloat() > 0.3
if (esHueso) {
boton.setBackgroundResource(R.drawable.hueso) // Imagen del hueso
} else {
boton.setBackgroundResource(R.drawable.bomba) // Imagen de la bomba
}
// Posicionamos el botón aleatoriamente dentro del FrameLayout
val huesoAleatorio = Random.nextInt(100, 300)
......@@ -56,8 +66,7 @@ class Minijuego1 : AppCompatActivity() {
// Configurar la acción al pulsar el botón
boton.setOnClickListener {
puntaje++ // Incrementar el puntaje
actualizarPuntaje() // Actualizar el TextView con el puntaje
actualizarPuntaje(esHueso) // Actualizar el TextView con el puntaje
frameLayout.removeView(boton) // Remover el botón al ser pulsado
}
......@@ -73,8 +82,9 @@ class Minijuego1 : AppCompatActivity() {
override fun onTick(millisUntilFinished: Long) {
// Actualizamos el tiempo restante cada segundo
tiempoRestante = (millisUntilFinished / 1000).toInt()
tiempoTextView.text = "Tiempo: $tiempoRestante s" // Mostrar el tiempo restante en el TextView
if (tiempoRestante == 1){
tiempoTextView.text =
"Tiempo: $tiempoRestante s" // Mostrar el tiempo restante en el TextView
if (tiempoRestante == 1) {
handler.removeCallbacksAndMessages(null) // Detener el juego al acabar el tiempo
}
}
......@@ -90,12 +100,21 @@ class Minijuego1 : AppCompatActivity() {
}
// Función para actualizar el puntaje en el TextView
private fun actualizarPuntaje() {
puntajeTextView.text = "Puntaje: $puntaje" // Actualiza el texto del puntaje
private fun actualizarPuntaje(esHueso : Boolean) {
if(puntaje == 0 && !esHueso){
puntaje = 0
puntajeTextView.text = "Puntaje: 0" // Actualiza el texto del puntaje
} else if (esHueso) {
puntaje++ // Incrementar el puntaje si es un hueso
puntajeTextView.text = "Puntaje: $puntaje" // Actualiza el texto del puntaje
} else {
puntaje-- // Decrementar el puntaje si es una bomba
puntajeTextView.text = "Puntaje: $puntaje" // Actualiza el texto del puntaje
}
}
override fun onDestroy() {
super.onDestroy()
handler.removeCallbacksAndMessages(null) // Detener el juego al cerrar la actividad
}
}
\ No newline at end of file
}
app/src/main/res/drawable/bomba.png

18.9 KiB

app/src/main/res/drawable/hueso.png

14.4 KiB | W: | H:

app/src/main/res/drawable/hueso.png

90.7 KiB | W: | H:

app/src/main/res/drawable/hueso.png
app/src/main/res/drawable/hueso.png
app/src/main/res/drawable/hueso.png
app/src/main/res/drawable/hueso.png
  • 2-up
  • Swipe
  • Onion skin
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