fpaus / algo3-tp2 Goto Github PK
View Code? Open in Web Editor NEWRepositorio para el trabajo practico 2 de Algoritmos y Programación 3
Repositorio para el trabajo practico 2 de Algoritmos y Programación 3
public void elJugadorQueSeQuedaSinEntidadesEsElPerdedorTest() throws PuntosInsuficientesExcepcion,
CasilleroFueraDelLosLimitesDelTableroExcepcion, UnidadInvalidaException {
Jugador jugador = new Jugador();
Bando bando = new Bando(jugador);
Tablero tablero = new Tablero(20, 20 , jugador, new Jugador());
Unidad unidad1 = new Catapulta(bando);
Unidad unidad2 = new Catapulta(bando);
Unidad unidad3 = new Catapulta(bando);
Unidad unidad4 = new Catapulta(bando);
jugador.colocarUnidadEnCasillero(unidad1, tablero.getCasilleroEnPosicion(1,2));
jugador.colocarUnidadEnCasillero(unidad2, tablero.getCasilleroEnPosicion(1,3));
jugador.colocarUnidadEnCasillero(unidad3, tablero.getCasilleroEnPosicion(1,4));
jugador.colocarUnidadEnCasillero(unidad4, tablero.getCasilleroEnPosicion(1,5));
unidad1.generarDanio(Properties.vidaCatapulta);
unidad2.generarDanio(Properties.vidaCatapulta);
unidad3.generarDanio(Properties.vidaCatapulta);
unidad4.generarDanio(Properties.vidaCatapulta);
assertEquals(jugador.sigueEnJuego(), false);
}
generarDanio
no se entiende cual es el propósito. Y lo que esto evidencia que dos unidades se ataquen. Necesitan tener aquí el siguiente intercambio de mensajes:
uniadadAgresora.atacar(unidadAgredida);
Debería existir una entiadad Punto
.
public Casillero getCasilleroEnPosicion(int x, int y) throws CasilleroFueraDelLosLimitesDelTableroExcepcion {
try {
return casilleros[x][y];
} catch (ArrayIndexOutOfBoundsException ex) {
throw new CasilleroFueraDelLosLimitesDelTableroExcepcion();
}
}
Será necesario cuando necesiten calcular distancias, casilleros a la izquierda, derecha, etc.
Este evidencia no ocultar la implementación de las clases resultando en un tren de puntos que evidencia alto acoplamiento. Ej.: unidad.getBando().getDuenio()
public void setUnidadAlInicioDelJuego(Unidad unidad) throws CasilleroEnemigoExcepcion, CasilleroOcupadoExcepcion {
if(unidad.getBando().getDuenio() != this.duenio.getDuenio()){
throw new CasilleroEnemigoExcepcion();
}
estado.setUnidad(this, unidad);
}
Aquí otro ejemplo más:
public Unidad comprarUnidad(Unidad unidad) throws PuntosInsuficientesExcepcion {
if (unidad.getCosto() > puntosDisponibles) {
throw new PuntosInsuficientesExcepcion();
}
return unidad;
}
Otro ejemplo más:
private int medirDistanciaEnX(Unidad unidadActual, Unidad unidadAliada) {
int unidadActualCoordenadaX = unidadActual.getCasillero().getCoordenadaX();
int unidadAliadaCoordenadaX = unidadAliada.getCasillero().getCoordenadaX();
return (Math.abs(unidadAliadaCoordenadaX - unidadActualCoordenadaX));
}
Como pueden quitar estos "getters
" y reducirlos a la mínima expresión (mínima cantidad de ocurrencias).
public boolean sigueEnJuego() {
return this.sigueEnJuego;
}
public boolean quedanPuntos(){
return puntosDisponibles != 0;
}
public boolean estaViva(){
return this.estaViva;
}
Pueden reemplazarlos utilizando algún mensaje que cumpla "Tell don't ask"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.