diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/Resumen.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/Resumen.kt index fbb32fcd3dd2ed23c9247f5a75534eb476dde613..69233420502f012d1673c5044527a4f0b210a3b2 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/Resumen.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/Resumen.kt @@ -2,13 +2,18 @@ package com.example.ellegadodepintia.exploradoresDePintia import android.animation.AnimatorSet import android.animation.ObjectAnimator +import android.app.Activity import android.content.Intent import android.os.Bundle +import android.view.View +import android.view.ViewGroup import android.view.animation.AccelerateDecelerateInterpolator import android.widget.Button import android.widget.ImageView import android.widget.ProgressBar import android.widget.TextView +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -17,20 +22,42 @@ import com.example.ellegadodepintia.R import com.example.ellegadodepintia.exploradoresDePintia.model.Atributo import com.example.ellegadodepintia.exploradoresDePintia.model.GameState import com.example.ellegadodepintia.exploradoresDePintia.model.objeto.ObjetoDeValor +import com.example.ellegadodepintia.repositorios.RepositorioJugador +import com.example.ellegadodepintia.ruleta.Ruleta class Resumen : AppCompatActivity() { + private lateinit var startForResult: ActivityResultLauncher<Intent> + private var gananciaTotal = 0 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_resumen_partida) - if(GameState.jugador.atributos[Atributo.Vida]!! <= 0){ + + startForResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + val mensajeResultado = result.data?.getStringExtra("resultado")!!.toInt() + println(mensajeResultado) + val textoResumen = findViewById<TextView>(R.id.textoResumen) + "Ha susado el ticker para generar aun más monedas. Enhorabuena, has conseguido $mensajeResultado monedas.".also { + textoResumen.text = it + } + GameState.jugador.monedas+=mensajeResultado-gananciaTotal + GameState.jugador.monedas.toString() + .also { findViewById<TextView>(R.id.moneyText).text = it } + RepositorioJugador.setMonedas(GameState.jugador.monedas) + findViewById<Button>(R.id.botonRuleta).visibility = View.GONE + + } + } + + + if (GameState.jugador.atributos[Atributo.Vida]!! <= 0) { mostrarDerrota() } else { calcularGanancias() } GameState.jugador.monedas.toString() .also { findViewById<TextView>(R.id.moneyText).text = it } - val continuarButton = findViewById<Button>(R.id.botonContinuar) continuarButton.setOnClickListener { val intent = Intent(this, MapActivity::class.java) @@ -43,11 +70,13 @@ class Resumen : AppCompatActivity() { barraVida.progress = GameState.jugador.atributos[Atributo.Vida]!! } - private fun mostrarDerrota(){ + private fun mostrarDerrota() { val textoResumen = findViewById<TextView>(R.id.textoResumen) val imagenProtagonista = findViewById<ImageView>(R.id.imagenProtagonista) - "El investigador ha sido derrotado, ha perdido todos sus objetos del inventario".also { textoResumen?.text = it } + "El investigador ha sido derrotado, ha perdido todos sus objetos del inventario".also { + textoResumen?.text = it + } imagenProtagonista?.setImageResource(R.drawable.protagonista_die_06) } @@ -60,7 +89,8 @@ class Resumen : AppCompatActivity() { var nObjetosValor = 0 textoResumen?.text = "" - val movimientoLateral = ObjectAnimator.ofFloat(imagenProtagonista, "translationX", -100f, 100f) + val movimientoLateral = + ObjectAnimator.ofFloat(imagenProtagonista, "translationX", -100f, 100f) movimientoLateral.duration = 1500 movimientoLateral.repeatCount = ObjectAnimator.INFINITE movimientoLateral.repeatMode = ObjectAnimator.REVERSE @@ -79,6 +109,7 @@ class Resumen : AppCompatActivity() { for (objeto in GameState.jugador.inventario) { if (objeto is ObjetoDeValor) { nObjetosValor++ + gananciaTotal += objeto.coste objetosDeValor.add(objeto) objeto.usar() } @@ -88,12 +119,26 @@ class Resumen : AppCompatActivity() { if (nObjetosValor == 0) { - "El investigador no ha conseguido ningún objeto de valor".also { textoResumen?.text = it } + "El investigador no ha conseguido ningún objeto de valor".also { + textoResumen?.text = it + } } else { - "${textoResumen.text} Enhorabuena, has conseguido ${nObjetosValor*20} monedas.".also { + "${textoResumen.text} Enhorabuena, has conseguido $gananciaTotal monedas.".also { textoResumen.text = it } - + val botonRuleta = findViewById<Button>(R.id.botonRuleta) + val tieneTicket = GameState.jugador.inventario.any { it.nombre == "Ticket" } + println(tieneTicket) + if (!tieneTicket) { + (botonRuleta.parent as? ViewGroup)?.removeView(botonRuleta) + } else { + botonRuleta.visibility = View.VISIBLE + botonRuleta.setOnClickListener { + val intent = Intent(this, Ruleta::class.java) + intent.putExtra("PUNTUACION_ACTUAL", gananciaTotal) + startForResult.launch(intent) + } + } } } } \ No newline at end of file diff --git a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/Jugador.kt b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/Jugador.kt index 510704a719aebd5586501429faa35fe740822733..861ae25d2d00f12f18c912956bcc3d4167fbb8ac 100644 --- a/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/Jugador.kt +++ b/app/src/main/java/com/example/ellegadodepintia/exploradoresDePintia/model/Jugador.kt @@ -34,6 +34,14 @@ class Jugador { atributos[Atributo.Investigacion] = 1 atributos[Atributo.Energia] = 10 + inventario.add( + ObjetoUtilidad( + nombre = "Ticket", + descripcion = "Representa una invitación a un evento relacionado con la cultura vaccea, como una feria arqueológica o un festival cultural", + imagen = R.drawable.asi_objeto_ticket + ) + ) + inventario.add( ObjetoEquipable( nombre = "Espada de Hierro", @@ -95,8 +103,10 @@ class Jugador { fun actualizarAtributo(atributo: Atributo, valor: Int) { atributos[atributo] = atributos[atributo]!!.plus(valor) notifyObservers() - if (atributo == Atributo.Vida && atributos[atributo]!! <= 0){ - "¡Has sido derrotado!".also { context!!.findViewById<TextView>(R.id.textoResultado).text = it } + if (atributo == Atributo.Vida && atributos[atributo]!! <= 0) { + "¡Has sido derrotado!".also { + context!!.findViewById<TextView>(R.id.textoResultado).text = it + } cargarAnimacionesMuerteProtagonista() Handler(Looper.getMainLooper()).postDelayed({ val intent = Intent(context, Resumen::class.java) @@ -154,7 +164,7 @@ class Jugador { notifyObservers() } - fun actualizarMonedas(valor: Int){ + fun actualizarMonedas(valor: Int) { monedas = valor notifyObservers() } diff --git a/app/src/main/java/com/example/ellegadodepintia/ruleta/Ruleta.kt b/app/src/main/java/com/example/ellegadodepintia/ruleta/Ruleta.kt index 73b0004c50ccb651fe337c51b70530df1860f4d4..ee453e724aaa1e29101c68593bc1a72cf77409b6 100644 --- a/app/src/main/java/com/example/ellegadodepintia/ruleta/Ruleta.kt +++ b/app/src/main/java/com/example/ellegadodepintia/ruleta/Ruleta.kt @@ -2,6 +2,8 @@ package com.example.ellegadodepintia.ruleta import android.animation.ObjectAnimator import android.animation.ValueAnimator +import android.app.Activity +import android.content.Intent import android.os.Bundle import android.os.Handler import android.os.Looper @@ -14,6 +16,7 @@ import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.core.animation.doOnEnd import com.example.ellegadodepintia.R +import com.example.ellegadodepintia.exploradoresDePintia.model.GameState import kotlin.random.Random import com.example.ellegadodepintia.soundManager.SoundManager @@ -27,11 +30,13 @@ class Ruleta : AppCompatActivity() { private val segmentos = arrayOf("x4", "x1", "x2", "x1", "x2", "x1", "x2", "x1") private var ultimaRotacion = 0f - private var puntuacionActual = 33 + private var puntuacionActual = 1 // Configura las vistas iniciales de la actividad y establece acciones iniciales override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + + puntuacionActual = intent.getIntExtra("PUNTUACION_ACTUAL", 0) soundManager = SoundManager(this) soundManager.playSoundLoop(R.raw.sound_casino, 80) setContentView(R.layout.activity_ruleta) @@ -46,6 +51,7 @@ class Ruleta : AppCompatActivity() { ruletaImage = findViewById(R.id.ruletaImage) puntero = findViewById(R.id.ruletaPuntero) puntuacion = findViewById(R.id.puntuacion) + puntuacionActual.toString().also { puntuacion.text = it } titulo = findViewById(R.id.ruletaTitulo) } @@ -102,6 +108,13 @@ class Ruleta : AppCompatActivity() { soundManager.playSound(R.raw.sound_big_win,100) lluviaMonedas() } + + Handler(Looper.getMainLooper()).postDelayed({ + val resultIntent = Intent() + resultIntent.putExtra("resultado", "$puntuacionActual") + setResult(Activity.RESULT_OK, resultIntent) + finish() + },5000) } // Realiza una animación de conteo que muestra la puntuación cambiando de un valor inicial a un valor final @@ -110,7 +123,7 @@ class Ruleta : AppCompatActivity() { duration = 3000 addUpdateListener { animation -> val valorActual = animation.animatedValue as Int - puntuacion.text = "Puntuación: $valorActual" + valorActual.toString().also { puntuacion.text = it } } start() } diff --git a/app/src/main/res/layout/activity_resumen_partida.xml b/app/src/main/res/layout/activity_resumen_partida.xml index 105078ab0540ec9d7d848109caf16c4ee81a5744..e4d154018cd0044793c1fdb45fd6e27b15949cd6 100644 --- a/app/src/main/res/layout/activity_resumen_partida.xml +++ b/app/src/main/res/layout/activity_resumen_partida.xml @@ -148,6 +148,16 @@ android:layout_marginTop="10dp" android:text="Continuar" android:textColor="@color/pintiaButtonText" /> + + <Button + android:id="@+id/botonRuleta" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:backgroundTint="@color/pintiaButton" + android:layout_marginTop="10dp" + android:text="Utilizar Ticket" + android:textColor="@color/pintiaButtonText" + android:visibility="gone"/> </LinearLayout>