forked from fiuba/algo3_proyecto_base_tp2
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Decorator' into semana-1
- Loading branch information
Showing
30 changed files
with
777 additions
and
75 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
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,5 @@ | ||
package edu.fiuba.algo3.modelo; | ||
|
||
public interface Afectante { | ||
public void afectar(Jugador jugador); | ||
} |
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,4 @@ | ||
package edu.fiuba.algo3.modelo; | ||
|
||
public class Celda { | ||
} |
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,8 @@ | ||
package edu.fiuba.algo3.modelo; | ||
|
||
public abstract class Equipamiento { | ||
public abstract Equipamiento mejorarEquipamiento(); | ||
|
||
public abstract int recibirAtaque(); | ||
|
||
} |
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,58 @@ | ||
package edu.fiuba.algo3.modelo; | ||
|
||
import edu.fiuba.algo3.modelo.seniorities.Novato; | ||
import edu.fiuba.algo3.modelo.equipamientos.Desequipado; | ||
|
||
public class Gladiador { | ||
//Declaramos constantes ? | ||
private static final int ENERGIA_INICIAL = 20; | ||
private static final int SIN_ENERGIA = 0; | ||
|
||
private int energia; | ||
private Seniority seniority; | ||
private Equipamiento equipamiento; | ||
|
||
public Gladiador() { | ||
this.energia = ENERGIA_INICIAL; | ||
this.seniority = new Novato(); | ||
this.equipamiento = new Desequipado(); | ||
} | ||
|
||
// -------------------------------- PUBLICOS -------------------------------- // | ||
public void aumentarEnergiaConSeniority(){ | ||
this.energia += this.seniority.aumentarEnergia(); | ||
} | ||
|
||
public boolean energiaIgualA(int energia) { | ||
return this.energia == energia; | ||
} | ||
|
||
public boolean tieneEnergia(){ | ||
return this.energia > SIN_ENERGIA; | ||
} | ||
|
||
public void recibirAtaque(){ | ||
this.disminuirEnergia(this.equipamiento.recibirAtaque()); //ROMPE ENCAPSULAMIENTO | ||
} | ||
|
||
public void recibirDanio(int danio) { this.disminuirEnergia(danio); } | ||
|
||
public void mejorarEquipamiento(){ | ||
this.equipamiento = this.equipamiento.mejorarEquipamiento(); | ||
} | ||
|
||
public void mejorarSeniority(int turnos){ | ||
this.seniority = this.seniority.ascender(turnos); | ||
} | ||
|
||
public void recibirEnergia(int energia) { this.aumentarEnergia(energia); } | ||
|
||
// -------------------------------- PRIVADOS -------------------------------- // | ||
private void disminuirEnergia(int energia) { | ||
this.energia -= energia; | ||
} | ||
|
||
private void aumentarEnergia(int energia) { | ||
this.energia += energia; | ||
} | ||
} |
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,140 @@ | ||
package edu.fiuba.algo3.modelo; | ||
|
||
import javafx.scene.SceneAntialiasing; | ||
|
||
import java.util.Random; | ||
|
||
public class Jugador { | ||
private Gladiador gladiador; | ||
private int turnos; | ||
private int casillaActual; | ||
|
||
//private Casilla casilla; | ||
|
||
public Jugador(Gladiador gladiador) { | ||
this.gladiador = gladiador; | ||
this.turnos = 0; | ||
this.casillaActual = 0; | ||
} | ||
|
||
// -------------------------------- PUBLICOS -------------------------------- // | ||
public void jugarTurno() { | ||
int cantidadAAvanzar = this.tirarDado(); | ||
this.avanzar(cantidadAAvanzar); | ||
this.turnos++; | ||
this.gladiador.mejorarSeniority(this.turnos); | ||
this.aumentarEnergiaConSeniority(); | ||
} | ||
|
||
public void aumentarEnergiaConSeniority() { | ||
this.gladiador.aumentarEnergiaConSeniority(); | ||
} | ||
|
||
public boolean tieneTurnosIgualA(int cantidad) { | ||
return (this.turnos == cantidad); | ||
} | ||
|
||
public boolean energiaIgualA(int energia) { | ||
return this.gladiador.energiaIgualA(energia); | ||
} | ||
|
||
public boolean estaEnCasilla(int numeroCasilla) { | ||
return (this.casillaActual == numeroCasilla); | ||
} | ||
|
||
public void recibirEnergia(int aumentoEnergia) { | ||
this.gladiador.recibirEnergia(aumentoEnergia); | ||
} | ||
|
||
public void mejorarEquipamiento() { | ||
this.gladiador.mejorarEquipamiento(); | ||
} | ||
|
||
public void recibirAtaque() { | ||
this.gladiador.recibirAtaque(); | ||
} | ||
|
||
public void recibirDanio(int danio) { | ||
this.gladiador.recibirDanio(danio); | ||
} | ||
|
||
// -------------------------------- PRIVADOS -------------------------------- // | ||
private void avanzar(int cantidad) { | ||
this.casillaActual += cantidad; | ||
} | ||
|
||
private int tirarDado() { | ||
final int CARAS_DADO = 6; | ||
|
||
if (this.gladiador.tieneEnergia()) { | ||
Random random = new Random(); | ||
return random.nextInt(CARAS_DADO) + 1; | ||
} | ||
return 0; | ||
} | ||
} | ||
|
||
|
||
// Los metodos recibirAtaque y recibirDanio deberian ser el mismo. Quizas podemos usar Double Dispatch. | ||
// De hecho, quizas podemos hacer Double Dispatch con un metodo que se llame recibirEfecto. De esta manera | ||
// lograriamos que Jugador solo tenga un metodo que se llame recibirImpacto(Afectante afectante) que sea: | ||
// | ||
// public void recibirImpacto(Afectante afectante) { | ||
// this.gladiador.recibirImpacto(afectante); | ||
//} | ||
// Con este metodo reemplazariamos los metodos de: | ||
// mejorarEquipamiento() | ||
// recibirAtaque() | ||
// recibirDanio() | ||
// recibirEnergia() | ||
|
||
// Entonces Gladiador tendria: | ||
// public void recibirImpacto(Fiera fiera) { // Este metodo reemplaza el metodo 'recibirAtaque()' de Gladiador | ||
// this.disminuirEnergia(this.equipamiento.recibirAtaque()); | ||
// } | ||
// | ||
// public void recibirImpacto(Bacanal bacanal) { // Este metodo reemplaza el metodo 'recibirDanio()' de Gladiador | ||
// this.disminuirEnergia(bacanal.calcularEnergia); | ||
// } | ||
// | ||
// public void recibirImpacto(Lesion lesion) { | ||
// // PROBLEMA con la propuesta de cambio: | ||
// // Aqui el Jugador en el siguiente turno no avanza. | ||
// // Esta logica quizas es conveniente que este en Jugador por el hecho de que un | ||
// // jugador tiene la cantidad de turnos. | ||
// } | ||
// | ||
// public void recibirImpacto(Comida comida) { // Este metodo reemplaza el metodo 'recibirEnergia()' de Gladiador | ||
// this.aumentarEnergia(comida.calcularEnergia); | ||
// } | ||
// | ||
// public void recibirImpacto(MejorarEquipamiento mejorador) { // Este metodo reemplaza el metodo 'mejorarEquipamiento()' de Gladiador | ||
// this.equipamiento = this.equipamiento.mejorarEquipamiento; | ||
// } | ||
// | ||
|
||
// En BACANAL tendriamos que introducir el metodo: | ||
// public int calcularEnergia() { | ||
// //Aca el jugador tendria que tirar los dados. Pensar si hay una solucion posible. | ||
// int cantidadCopas = random.nextInt(CANTIDAD_COPAS_TOTAL) + 1; | ||
// return (ENERGIA_POR_COPA * cantidadCopas); | ||
// } | ||
// | ||
|
||
// En COMIDA tendriamos que introducir el metodo: | ||
// public int calcularEnergia() { | ||
// return this.aumentoEnergia; | ||
// } | ||
// | ||
|
||
|
||
// NOTA APARTE: | ||
// No implementamos Personaje. | ||
// Si creamos esta abstraccion e implementamos el metodo recibirImpacto como esta planteado arriba | ||
// podriamos extender nuestro codigo a que tenga distintos tipos de personajes que reaccionen de distinta manera | ||
// a los afectantes. | ||
// Esto se veria como: | ||
// public void recibirImpacto(Afectante afectante) { | ||
// this.personaje.recibirImpacto(afectante); | ||
//} | ||
// Entonces cada tipo de personaje tendria su propio metodo ante cada tipo de Afectante. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 edu.fiuba.algo3.modelo; | ||
|
||
public interface Seniority { | ||
public Seniority ascender(int turno); | ||
|
||
public int aumentarEnergia(); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/edu/fiuba/algo3/modelo/afectantes/Bacanal.java
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 edu.fiuba.algo3.modelo.afectantes; | ||
|
||
import edu.fiuba.algo3.modelo.Afectante; | ||
import edu.fiuba.algo3.modelo.Jugador; | ||
import java.util.Random; | ||
|
||
|
||
public class Bacanal implements Afectante { | ||
|
||
private static final int CANTIDAD_COPAS_TOTAL = 6; | ||
private static final int ENERGIA_POR_COPA = 4; | ||
|
||
private Random random = new Random(); | ||
|
||
// Deberiamos tener un constructor de bacanal? En principio parece que si pq | ||
// tiene que haber una instancia concreta en una casilla. | ||
|
||
public void afectar(Jugador jugador){ | ||
//Deberiamos implementar un dado ¿? | ||
int cantidadCopas = random.nextInt(CANTIDAD_COPAS_TOTAL) + 1; | ||
jugador.recibirDanio(ENERGIA_POR_COPA * cantidadCopas); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/edu/fiuba/algo3/modelo/afectantes/Comida.java
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,17 @@ | ||
package edu.fiuba.algo3.modelo.afectantes; | ||
|
||
import edu.fiuba.algo3.modelo.Afectante; | ||
import edu.fiuba.algo3.modelo.Gladiador; | ||
import edu.fiuba.algo3.modelo.Jugador; | ||
|
||
public class Comida implements Afectante { | ||
private int aumentoEnergia; | ||
|
||
public Comida() { | ||
this.aumentoEnergia = 15; | ||
} | ||
|
||
public void afectar(Jugador jugador) { | ||
jugador.recibirEnergia(this.aumentoEnergia); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/edu/fiuba/algo3/modelo/afectantes/Fiera.java
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,13 @@ | ||
package edu.fiuba.algo3.modelo.afectantes; | ||
|
||
import edu.fiuba.algo3.modelo.Afectante; | ||
import edu.fiuba.algo3.modelo.Jugador; | ||
|
||
public class Fiera implements Afectante { | ||
|
||
public void afectar(Jugador jugador){ | ||
jugador.recibirAtaque(); | ||
} | ||
} | ||
|
||
|
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,5 @@ | ||
package edu.fiuba.algo3.modelo.afectantes; | ||
|
||
public class Lesion { | ||
//el turno siguiente no avanza | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/edu/fiuba/algo3/modelo/afectantes/MejorarEquipamiento.java
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 @@ | ||
package edu.fiuba.algo3.modelo.afectantes; | ||
|
||
import edu.fiuba.algo3.modelo.Afectante; | ||
import edu.fiuba.algo3.modelo.Jugador; | ||
|
||
public class MejorarEquipamiento implements Afectante { | ||
|
||
public void afectar(Jugador jugador) { | ||
jugador.mejorarEquipamiento(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/fiuba/algo3/modelo/equipamientos/Armadura.java
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,22 @@ | ||
package edu.fiuba.algo3.modelo.equipamientos; | ||
|
||
import edu.fiuba.algo3.modelo.Afectante; | ||
import edu.fiuba.algo3.modelo.Equipamiento; | ||
import edu.fiuba.algo3.modelo.Jugador; | ||
import edu.fiuba.algo3.modelo.equipamientos.DecoradorEquipamiento; | ||
|
||
public class Armadura extends DecoradorEquipamiento { | ||
private static final int DANIO = 10; | ||
|
||
public Armadura(Equipamiento equipamiento){ | ||
this.equipamiento = equipamiento; | ||
} | ||
|
||
public Equipamiento mejorarEquipamiento() { | ||
return new EscudoYEspada(this); | ||
} | ||
|
||
public int recibirAtaque(){ | ||
return DANIO; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/fiuba/algo3/modelo/equipamientos/Casco.java
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,22 @@ | ||
package edu.fiuba.algo3.modelo.equipamientos; | ||
|
||
import edu.fiuba.algo3.modelo.Afectante; | ||
import edu.fiuba.algo3.modelo.Jugador; | ||
import edu.fiuba.algo3.modelo.Equipamiento; | ||
import edu.fiuba.algo3.modelo.equipamientos.DecoradorEquipamiento; | ||
|
||
public class Casco extends DecoradorEquipamiento { | ||
private static final int DANIO = 15; | ||
|
||
public Casco(Equipamiento equipamiento) { | ||
this.equipamiento = equipamiento; | ||
} | ||
|
||
public Equipamiento mejorarEquipamiento() { | ||
return new Armadura(this); | ||
} | ||
|
||
public int recibirAtaque() { | ||
return DANIO; | ||
} | ||
} |
Oops, something went wrong.