Skip to content
Snippets Groups Projects
Commit 4a9be8cd authored by diegval's avatar diegval
Browse files

Feature: ticket ruleta en una camioneta

parent 197c85c5
No related branches found
No related tags found
3 merge requests!65Feature:,!51Tienda to guapa,!46Feature:
......@@ -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
......@@ -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()
}
......
......@@ -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()
}
......
......@@ -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>
......
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