-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Semana 1 #2
Semana 1 #2
Changes from 23 commits
8a1b961
9f6091d
e9b42ad
3c8ecdd
9c3a56f
4ff59ab
c153daa
ec89e74
b2ca6a0
76cd139
b243489
0c79ef4
8bbb71f
dee620a
f3f2724
9a7b7be
cee2eb9
0de2b3c
e9bfb47
20d1e77
477e95f
1cc3132
dcc6322
e3a3714
a0f75ea
d74e856
ed2c888
0a73367
770b583
6090b2b
e7e4161
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package edu.fiuba.algo3.modelo; | ||
|
||
public class Celda { | ||
} |
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(); | ||
|
||
} |
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); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Que diferencia hay entre There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tenes toda la razón, es un error que tenemos visto y creemos que encontramos una posible solución. En cuanto comencemos con el refactor va a ser lo primero en arreglar. Gracias por la observación There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. De hecho, desarrollamos la idea de la solución en un comentario que está al final del archivo de la clase Jugador.java. |
||
|
||
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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No les veo mucha utilidad la verdad |
||
} |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esto debe pasar a ser |
||
|
||
//private Casilla casilla; | ||
|
||
public Jugador(Gladiador gladiador) { | ||
this.gladiador = gladiador; | ||
this.turnos = 0; | ||
this.casillaActual = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public Jugador(Gladiador gladiador, Casilla casillaInicial) {
this.gladiador = gladiador;
this.turnos = 0;
this.casillaActual =casillaInicial; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. En el código más reciente introdujimos este cambio. De alguna manera el código sobre el que hiciste esta corrección quedó es viejo. Me pregunto si habremos hecho mal el push al PR 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Para que se haga un push al PR se tiene que hacer un push en la rama There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfecto! Mañana a la mañana lo hacemos entonces. Debemos haberlo hecho a la rama Decorator y no nos dimos cuenta 🫣 |
||
} | ||
|
||
// -------------------------------- 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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Responsabilidad de casilla o celda, los nombres deben ser consistentes |
||
|
||
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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La nueva casilla deberia ser obtenida a partir de que la casilla actual conoce a sus vecinos |
||
|
||
private int tirarDado() { | ||
final int CARAS_DADO = 6; | ||
|
||
if (this.gladiador.tieneEnergia()) { | ||
Random random = new Random(); | ||
return random.nextInt(CARAS_DADO) + 1; | ||
} | ||
return 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esto tiene que estar encapsulado en una entidad que simule el dado, de manera que se pueda mockear y no depender de una clase que puede violar OC como Random |
||
} | ||
} | ||
|
||
|
||
// 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Me parece mejor. |
||
|
||
// 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. | ||
// } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Habria que buscar la manera de impedir que el jugador avance |
||
// | ||
// 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.
This file was deleted.
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(); | ||
} |
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. encapsularlo en un objeto Dado o ProvedorRandom, x |
||
|
||
// 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); | ||
} | ||
} |
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); | ||
} | ||
} |
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(); | ||
} | ||
} | ||
|
||
|
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 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Buscar manera de que haga algo |
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(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esta clase debería tener mas responsabilidad, porque sino todos los afectantes simplemente delegan o hacen poquitas cosas public void afectar(Jugador jugador) {
jugador.mejorarEquipamiento(this);
}
public Equipamiento mejorarEquipamiento(Casco casco)
//... asi para los equipamientos// |
||
} |
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; | ||
} | ||
} |
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se puede evitar el getter de la siguiente forma
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Genial Ale! Ese código pertenece a Gladiador verdad?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obvia la pregunta, acabo de ver el path de arriba jajaja