-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nrainhart/dev-tadequest
Dev tadequest
- Loading branch information
Showing
15 changed files
with
541 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="src" path="test"/> | ||
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
.metadata | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.settings/ | ||
.loadpath | ||
.recommenders | ||
build | ||
.classpath | ||
.project | ||
.settings | ||
.cache-main | ||
.cache-tests | ||
.scala_dependencies | ||
.metadata | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.settings/ | ||
.loadpath | ||
.recommenders | ||
build | ||
.classpath | ||
.project | ||
.settings | ||
.cache-main | ||
.cache-tests | ||
.scala_dependencies | ||
.worksheet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>TAdeQuest</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.scala-ide.sdt.core.scalabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.scala-ide.sdt.core.scalanature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package model | ||
import scala.util.{Try, Success, Failure} | ||
|
||
case class Equipo(val nombre: String, val pozoComun: Int = 0, val heroes: List[Heroe] = List()) { | ||
|
||
def mejorHeroeSegun(criterio: Heroe => Int) = heroes.sortWith((heroe1, heroe2) => criterio.apply(heroe1) >= criterio.apply(heroe2)).headOption | ||
|
||
def lider() = mejorHeroeSegun { _.valorStatPrincipal() } | ||
|
||
def obtenerItem(item: Item) = { | ||
def incrementoStatPrincipal(heroe: Heroe, item: Item) = { | ||
heroe.equipar(item).map(_.valorStatPrincipal - heroe.valorStatPrincipal).getOrElse(Int.MinValue) | ||
//Si el incremento es menor a 0, no se le va a equipar el item | ||
} | ||
val heroeAEquiparItem = mejorHeroeSegun(heroe => incrementoStatPrincipal(heroe, item)) | ||
heroeAEquiparItem match { | ||
case Some(heroe) if (incrementoStatPrincipal(heroe: Heroe, item: Item) > 0) => reemplazarMiembro(heroe.equipar(item).get, heroe) | ||
case _ => copy(pozoComun = pozoComun + item.precio) | ||
} | ||
} | ||
|
||
def obtenerMiembro(nuevoMiembro: Heroe) = copy(heroes = heroes ++ List(nuevoMiembro)) | ||
|
||
def reemplazarMiembro(nuevoMiembro: Heroe, heroeAEliminar: Heroe) = copy(heroes = heroes.diff(List(heroeAEliminar)) ++ List(nuevoMiembro)) | ||
|
||
def cantidadMiembrosConTrabajo(unTrabajo: Trabajo) = heroes.count(_.tieneTrabajo(unTrabajo)) | ||
|
||
def elegirMision(misiones: TablonDeAnuncios, criterio: CriterioMision) = misiones.filter(_.serRealizadaPor(this).isSuccess) | ||
.sortWith((mision1, mision2) => criterio(mision1.serRealizadaPor(this).get, mision2.serRealizadaPor(this).get)) | ||
.headOption | ||
|
||
def entrenar(misiones: TablonDeAnuncios, criterio: CriterioMision): EstadoEquipo = { | ||
elegirMision(misiones, criterio).map { mejorMision => | ||
val equipoLuegoDeMision = mejorMision.serRealizadaPor(this) | ||
equipoLuegoDeMision.flatMap {_.entrenar(misiones.filter(!_.equals(mejorMision)), criterio)} | ||
}.getOrElse(SinFallos(this))//TANTO SI NO HAY MISIONES COMO SI QUEDAN PERO NINGUNA SE PUEDE REALIZAR, DEVUELVE EL EQUIPO ORIGINAL (!!!) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,70 @@ | ||
package model | ||
|
||
class Heroe { | ||
|
||
} | ||
package model | ||
import scala.util.{ Try, Success, Failure } | ||
|
||
sealed trait Stat | ||
|
||
case object HP extends Stat | ||
case object Velocidad extends Stat | ||
case object Fuerza extends Stat | ||
case object Inteligencia extends Stat | ||
|
||
|
||
sealed trait Slot | ||
|
||
case object Cabeza extends Slot | ||
case object Torso extends Slot | ||
case object ManoIzq extends Slot | ||
case object ManoDer extends Slot | ||
|
||
case class Heroe( | ||
stats: Map[Stat, Int] = Map[Stat, Int](HP -> 100, Fuerza -> 100, Velocidad -> 100, Inteligencia -> 100), | ||
inventario: List[Item] = List(), | ||
trabajo: Option[Trabajo] = None | ||
) { | ||
require(stats.keys.sameElements(List(HP,Fuerza,Velocidad,Inteligencia))) | ||
|
||
def slots: List[Slot] = List(Cabeza, Torso, ManoIzq, ManoDer) | ||
|
||
def trabajo(nuevoTrabajo: Trabajo) = copy(trabajo = Some(nuevoTrabajo)) | ||
|
||
def tieneTrabajo(unTrabajo: Trabajo) = trabajo.contains(unTrabajo) | ||
|
||
def getStat(nombreStat: Stat): Int = { | ||
val modificacionesAAplicar = inventario.flatMap(_.modificaciones) ++ trabajo.fold[List[ModificacionStat]](List())(_.modificaciones) | ||
1.max(aplicarModificaciones(modificacionesAAplicar).getStatBase(nombreStat)) | ||
} | ||
|
||
def getStatBase(nombreStat: Stat) = { | ||
stats(nombreStat) | ||
} | ||
|
||
def incrementarStatBase(nombreStat: Stat, valor: Int) = { | ||
setStatBase(nombreStat, getStatBase(nombreStat) + valor) | ||
} | ||
|
||
def setStatBase(nombreStat: Stat, valor: Int) = { | ||
val nuevosStats = stats + (nombreStat -> valor) | ||
copy(stats = nuevosStats) | ||
} | ||
|
||
def aplicarModificaciones(modificaciones: List[Modificacion]) = { | ||
modificaciones.sorted.foldLeft(this) {(heroe, modificacion) => modificacion(heroe)} | ||
} | ||
|
||
def valorStatPrincipal() = trabajo.map{t => getStat(t.statPrincipal)}.getOrElse(0)//ROMPE SI USO GUIÓN BAJO (???) | ||
|
||
def equipar(item: Item): Try[Heroe] = { | ||
if (item.puedeEquiparseEn(this)){ | ||
val itemsADesequipar = inventario.filter(unItem => unItem.slotsRequeridos.exists(slot => item.slotsRequeridos.contains(slot))) | ||
val nuevoInventario = inventario.diff(itemsADesequipar) ++ List(item) | ||
return Success(copy(inventario = nuevoInventario)) | ||
} else { | ||
return Failure(new NoSePuedeEquiparItemError(item, this)) | ||
} | ||
} | ||
|
||
def desequipar(item: Item) = copy(inventario = inventario.diff(List(item))) | ||
|
||
} | ||
|
||
class NoSePuedeEquiparItemError(val item: Item, val heroe: Heroe) extends RuntimeException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package model | ||
|
||
class Item (val slotsRequeridos: List[Slot], | ||
val restricciones: List[Restriccion], | ||
val modificaciones: List[ModificacionStat], | ||
val precio: Int){ | ||
|
||
def puedeEquiparseEn(heroe: Heroe) = restricciones.forall(_.apply(heroe)) | ||
|
||
} | ||
|
||
case object CascoVikingo extends Item(List(Cabeza), List(heroe => heroe.stats.get(Fuerza).get > 50), List(VariarStatEn(HP,10)), 150) | ||
case object PalitoMagico extends Item(List(ManoIzq), List(), List(VariarStatEn(Inteligencia,20)), 300) | ||
case object ArmaduraEleganteSport extends Item(List(Torso), List(), List(VariarStatEn(Velocidad,30), VariarStatEn(HP,-30)), 400) | ||
case object ArcoViejo extends Item(List(ManoIzq,ManoDer), List(), List(VariarStatEn(Fuerza,2)), 400) | ||
case object EscudoAntiRobo extends Item(List(ManoIzq), List(heroe => heroe.stats.get(Fuerza).get >= 20, heroe => heroe.trabajo != Ladron), List(VariarStatEn(HP,20)), 200) | ||
case object TalismanDeDedicacion extends Item(List(), List(), List(IncrementarStatsEnPorcentajeDePrincipal(10)), 350) | ||
case object TalismanDelMinimalismo extends Item(List(), List(), List(ModificarStatPorCantidadItems(HP,50),ModificarStatPorCantidadItems(HP,50)), 800) | ||
|
||
case object VinchaDelBufaloDeAgua extends Item(List(Cabeza), List(heroe => heroe.trabajo.isEmpty), List(), 650) //ver | ||
|
||
case object TalismanMaldito extends Item(List(), List(), List(ModificarTodosLosStats(1)), 1) | ||
case object EspadaDeLaVida extends Item(List(ManoIzq), List(), List(SetearStatSegun(Fuerza,HP)), 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package model | ||
import scala.util.{Try, Success, Failure} | ||
|
||
abstract class EstadoEquipo (equipo: Equipo){ | ||
def realizar(tarea: Tarea): EstadoEquipo | ||
def flatMap(f: Equipo => EstadoEquipo): EstadoEquipo = f(equipo)//PUEDE CAMBIAR LIBREMENTE DE ESTADO (!!!) | ||
def map(f: Equipo => Equipo): EstadoEquipo | ||
def get = equipo | ||
def isSuccess = true | ||
} | ||
|
||
case class SinFallos(equipo: Equipo) extends EstadoEquipo(equipo){ | ||
def realizar(tarea: Tarea) = tarea.realizarsePor(equipo).map{ e => SinFallos(e) }.getOrElse(ParcialmenteFallido(equipo, tarea)) | ||
def map(f: Equipo => Equipo) = copy(equipo = f(equipo)) | ||
} | ||
|
||
case class ParcialmenteFallido(equipo: Equipo, tareaFallada: Tarea) extends EstadoEquipo(equipo){ | ||
def realizar(tarea: Tarea): EstadoEquipo = tarea.realizarsePor(equipo).map{ e => ParcialmenteFallido(e,tareaFallada) } | ||
.getOrElse(Fallido(equipo, tarea)) | ||
def map(f: Equipo => Equipo) = copy(equipo = f(equipo)) | ||
} | ||
|
||
case class Fallido(equipo: Equipo, tareaFallada: Tarea) extends EstadoEquipo(equipo){ | ||
def realizar(tarea: Tarea) = this | ||
override def flatMap(f: Equipo => EstadoEquipo) = this | ||
def map(f: Equipo => Equipo) = this | ||
override def isSuccess = false | ||
} | ||
|
||
class Mision(val tareas: List[Tarea] = List(), val recompensa: Recompensa) { | ||
|
||
def serRealizadaPor(equipo: Equipo): EstadoEquipo = { | ||
val equipoLuegoDeMision = tareas.foldLeft(SinFallos(equipo): EstadoEquipo) {(equipo, tarea) => | ||
equipo.realizar(tarea) | ||
} | ||
equipoLuegoDeMision.map(equipo => cobrarRecompensa(equipo)) | ||
} | ||
|
||
def cobrarRecompensa(equipo: Equipo) = recompensa.apply(equipo) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package model | ||
|
||
object Modificacion{ | ||
implicit object ModificacionOrdering extends Ordering[Modificacion]{ | ||
def compare(a: Modificacion, b: Modificacion) = { | ||
val ordenModificaciones = List(AgregarItem,VariarStatEn,VariarStatEnSi,ModificarStatPorCantidadItems, | ||
IncrementarStatsEnPorcentajeDePrincipal,SetearStat,SetearStatSegun,ModificarTodosLosStats) | ||
ordenModificaciones.indexOf(a.getClass) - ordenModificaciones.indexOf(b.getClass) | ||
} | ||
} | ||
} | ||
|
||
sealed trait Modificacion{ | ||
def apply(heroe: Heroe): Heroe | ||
} | ||
|
||
case class AgregarItem(itemAAgregar: Item) extends Modificacion { | ||
def apply(heroe: Heroe) = heroe.equipar(itemAAgregar).getOrElse(heroe)//DEBERIA FALLAR SI NO SE PUEDE EQUIPAR, PERO ESO ROMPERIA LA FIRMA | ||
} | ||
|
||
sealed trait ModificacionStat extends Modificacion | ||
|
||
case class ModificarStatPorCantidadItems(stat: Stat, valor: Int) extends ModificacionStat { | ||
def apply(heroe: Heroe) = { | ||
val cantItems = heroe.inventario.size | ||
val valorAumentado = cantItems * valor | ||
heroe.incrementarStatBase(stat, valorAumentado) | ||
} | ||
} | ||
|
||
case class SetearStatSegun(statAModificar: Stat , stat: Stat) extends ModificacionStat { | ||
def apply(heroe: Heroe) = { | ||
heroe.setStatBase(stat, heroe.stats.get(stat).get) | ||
} | ||
} | ||
|
||
case class ModificarTodosLosStats(valor: Int) extends ModificacionStat { | ||
def apply(heroe: Heroe) = { | ||
heroe.stats.keys.foldLeft(heroe) {(heroe,stat) => heroe.setStatBase(stat, 1)} | ||
} | ||
} | ||
|
||
case class VariarStatEn(stat: Stat, valor: Int) extends ModificacionStat { | ||
def apply(heroe: Heroe) = heroe.incrementarStatBase(stat, valor) | ||
} | ||
|
||
case class SetearStat(stat: Stat, valor: Int) extends ModificacionStat { | ||
def apply(heroe: Heroe) = heroe.setStatBase(stat, valor) | ||
} | ||
|
||
case class IncrementarStatsEnPorcentajeDePrincipal(porcentaje: Float) extends ModificacionStat { | ||
def apply(heroe: Heroe) = { | ||
val incremento = (heroe.valorStatPrincipal * porcentaje).round | ||
heroe.stats.keys.foldLeft(heroe) {(heroe, stat) => heroe.incrementarStatBase(stat, incremento)} | ||
} | ||
} | ||
|
||
case class VariarStatEnSi(stat: Stat, valor: Int, condicion: Restriccion) extends ModificacionStat { | ||
def apply(heroe: Heroe)={ | ||
var aMod=0 | ||
if(condicion(heroe)){ | ||
aMod=valor | ||
} | ||
heroe.incrementarStatBase(stat, aMod) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package model | ||
import scala.util.{Try, Success, Failure} | ||
|
||
abstract class Tarea(modificaciones: List[Modificacion]) { | ||
|
||
def facilidad(heroe: Heroe, equipo: Equipo): Option[Int] | ||
|
||
def realizarsePor(equipo: Equipo): Try[Equipo] = { | ||
def heroeQueVaARealizarla(equipo: Equipo): Option[Heroe] = { | ||
equipo.mejorHeroeSegun { heroe => facilidad(heroe, equipo).getOrElse(Int.MinValue) } | ||
.flatMap { heroe => if (facilidad(heroe, equipo).isDefined) Some(heroe) else None }//En caso de que ninguno pueda realizarla | ||
} | ||
heroeQueVaARealizarla(equipo).fold[Try[Equipo]](Failure(new TareaFallidaError(this, equipo))) { heroePosta => | ||
val heroeModificado = heroePosta.aplicarModificaciones(modificaciones) | ||
val equipoActualizado = equipo.reemplazarMiembro(heroeModificado, heroePosta) | ||
Success(equipoActualizado) | ||
} | ||
} | ||
|
||
} | ||
|
||
class TareaFallidaError(val tarea: Tarea, val equipo: Equipo) extends RuntimeException | ||
|
||
object pelearContraMonstruo extends Tarea(List(VariarStatEnSi(HP, (-4), {_.getStat(Fuerza)<20}))) { | ||
|
||
def facilidad(heroe: Heroe, equipo: Equipo) = { | ||
equipo.lider().map(_.trabajo match { | ||
case Some(Guerrero) => 20 | ||
case _ => 10 | ||
}) | ||
} | ||
|
||
} | ||
|
||
object forzarPuerta extends Tarea(List(VariarStatEnSi(Fuerza, 1, {heroe => !heroe.tieneTrabajo(Ladron) && !heroe.tieneTrabajo(Mago)}), | ||
VariarStatEnSi(HP, (-5), {heroe => !heroe.tieneTrabajo(Ladron) && !heroe.tieneTrabajo(Mago)}))) {//NO ESTA BUENO REPETIR LA CONDICIÓN | ||
|
||
def facilidad(heroe: Heroe, equipo: Equipo) = { | ||
Some(heroe.getStat(Inteligencia) + equipo.cantidadMiembrosConTrabajo(Ladron) * 10) | ||
} | ||
|
||
} | ||
|
||
object robarTalisman extends Tarea(List(AgregarItem(TalismanDelMinimalismo))) { | ||
|
||
def facilidad(heroe: Heroe, equipo: Equipo) = { | ||
equipo.lider().flatMap(_.trabajo match { | ||
case Some(Ladron) => Some(heroe.getStat(Velocidad)) | ||
case _ => None | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package model | ||
|
||
class Trabajo (val statPrincipal: Stat, val modificaciones: List[ModificacionStat]) | ||
|
||
case object Guerrero extends Trabajo(Fuerza, List(VariarStatEn(HP,10), VariarStatEn(Fuerza,15), VariarStatEn(Inteligencia,-10))) | ||
case object Mago extends Trabajo(Inteligencia, List(VariarStatEn(Inteligencia,20), VariarStatEn(Fuerza,-20))) | ||
case object Ladron extends Trabajo(Velocidad, List(VariarStatEn(Velocidad,10), VariarStatEn(HP,-5))) |
Oops, something went wrong.