Skip to content

Commit

Permalink
fix: casos de uso. Dado creado en el handle.
Browse files Browse the repository at this point in the history
  • Loading branch information
agus-germi committed Dec 10, 2023
1 parent 857ce8e commit d7d064f
Showing 5 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.fiuba.algo3.interfaz.controladores;


import edu.fiuba.algo3.modelo.Dado;
import edu.fiuba.algo3.modelo.Juego;
import edu.fiuba.algo3.modelo.excepcion.PasaronTreintaRondasYnoHuboGanadorError;
import edu.fiuba.algo3.modelo.excepcion.UnJugadorGanoLaPartidaError;
@@ -19,7 +20,8 @@ public ControladorJugarTurno(Juego juego) {
@Override
public void handle(ActionEvent evento) {
try {
this.juego.jugarTurnoDeJugadorActual();
Dado dado = new Dado(6);
this.juego.jugarTurnoDeJugadorActual(dado);
} catch (UnJugadorGanoLaPartidaError | PasaronTreintaRondasYnoHuboGanadorError e) {
this.juego.finalizarJuego();
}
11 changes: 7 additions & 4 deletions src/main/java/edu/fiuba/algo3/modelo/Juego.java
Original file line number Diff line number Diff line change
@@ -39,24 +39,27 @@ public void iniciarPartida(ArrayList<String> nombresJugadores) {
notificarObservadores(this.jugadorInicial.getNombre(), this.ronda);
}

public void jugarTurnoDeJugadorActual() throws UnJugadorGanoLaPartidaError, PasaronTreintaRondasYnoHuboGanadorError {
Dado dado = new Dado(6);
public void jugarTurnoDeJugadorActual(Dado dado) throws UnJugadorGanoLaPartidaError, PasaronTreintaRondasYnoHuboGanadorError {

this.hayGanador = this.jugadorTurnoActual.jugarTurno(dado.tirar(), this.tablero);
if (this.hayGanador) {
throw new UnJugadorGanoLaPartidaError();
}

if (this.indiceJugadorActual < (this.jugadores.size() - 1)) {
this.indiceJugadorActual++;

} else {
this.indiceJugadorActual = 0;

}

this.jugadorTurnoActual = this.jugadores.get(this.indiceJugadorActual);
if ((this.jugadorTurnoActual == this.jugadorInicial) && quedanRondasPorJugar())
if ((this.jugadorTurnoActual == this.jugadorInicial) && quedanRondasPorJugar()) {
this.ronda++;

}
if (!quedanRondasPorJugar()) {

logger.info("La partida ha terminado sin un ganador después de 30 rondas.");
throw new PasaronTreintaRondasYnoHuboGanadorError(); // TODO: Le sacamos "Error" del nombre?
}
1 change: 0 additions & 1 deletion src/main/java/edu/fiuba/algo3/modelo/Jugador.java
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@ public boolean jugarTurno(int avances, Tablero tablero) {
Celda celdaAnterior = this.celdaActual;
Celda celdaProxima = tablero.avanzar(avances, this.celdaActual);
this.celdaActual = this.gladiador.mover(celdaProxima, this.turno);

notificarObservadores(this.nombre, celdaAnterior, avances);

if (celdaActual == tablero.getCeldaFinal()) {
Original file line number Diff line number Diff line change
@@ -36,10 +36,10 @@ private void ascenderASemiSenior(Jugador jugador, Tablero tablero) {
}
}

private void jugarVeintiNueveRondas(Juego juego) {
private void jugarVeintiNueveRondas(Juego juego, Dado dado) {
for (int i = 0; i < 29; i++) {
juego.jugarTurnoDeJugadorActual();
juego.jugarTurnoDeJugadorActual();
juego.jugarTurnoDeJugadorActual(dado);
juego.jugarTurnoDeJugadorActual(dado);
}
}

@@ -344,11 +344,11 @@ public void test12AlPasarTreintaTurnosYnadieLlegaAlaMetaSeTerminoElJuego() {

Juego juego = new Juego(logger, tablero);
juego.iniciarPartida(nombresJugadores);
Dado dado = new Dado(1);
jugarVeintiNueveRondas(juego, dado);

jugarVeintiNueveRondas(juego);

juego.jugarTurnoDeJugadorActual();
juego.jugarTurnoDeJugadorActual(dado);

Assertions.assertThrows(PasaronTreintaRondasYnoHuboGanadorError.class,()-> juego.jugarTurnoDeJugadorActual());
Assertions.assertThrows(PasaronTreintaRondasYnoHuboGanadorError.class,()-> juego.jugarTurnoDeJugadorActual(dado));
}
}
24 changes: 13 additions & 11 deletions src/main/test/edu/fiuba/algo3/entregas/CasosDeUsoSemana3Test.java
Original file line number Diff line number Diff line change
@@ -15,10 +15,11 @@

public class CasosDeUsoSemana3Test {

private void jugarCantidadDeRondas(Juego juego, int cantidadRondas) {
private void jugarCantidadDeRondas(Juego juego, int cantidadRondas,Dado dado) {
for (int i = 0; i < cantidadRondas; i++) {
juego.jugarTurnoDeJugadorActual();
juego.jugarTurnoDeJugadorActual();
juego.jugarTurnoDeJugadorActual(dado);
juego.jugarTurnoDeJugadorActual(dado);

}
}

@@ -34,19 +35,20 @@ public void test22SimularYVerificarQueJugadorGaneUnaPartida() {
celdas.add(new CeldaComun(0,4, new Potenciador(), new Vacio(), logger));
celdas.add(new CeldaFinal(0,5,logger));

Tablero tablero = new Tablero(1,6);
Tablero tablero = new Tablero(1,5);
tablero.armarMapa(celdas);

ArrayList<String> nombresJugadores = new ArrayList<>();
nombresJugadores.add("Pepe");
nombresJugadores.add("juan");

Dado dado = new Dado(1);
Juego juego = new Juego(logger, tablero);
juego.iniciarPartida(nombresJugadores);

jugarCantidadDeRondas(juego, 4);
jugarCantidadDeRondas(juego, 4, dado);

Assertions.assertThrows(UnJugadorGanoLaPartidaError.class, () -> juego.jugarTurnoDeJugadorActual());
Assertions.assertThrows(UnJugadorGanoLaPartidaError.class, () -> juego.jugarTurnoDeJugadorActual(dado));
//Assertions.assertThrows(UnJugadorGanoLaPartidaError.class, () -> juego.jugarTurnoDeJugadorActual());
}

@Test
@@ -63,14 +65,14 @@ public void test23SimularyVerificarQueElJugadorPierdeUnaPartida() {
ArrayList<String> nombresJugadores = new ArrayList<>();
nombresJugadores.add("Pepe");
nombresJugadores.add("juan");

Dado dado = new Dado(1);
Juego juego = new Juego(logger, tablero);
juego.iniciarPartida(nombresJugadores);

jugarCantidadDeRondas(juego, 29);
jugarCantidadDeRondas(juego, 29, dado);

juego.jugarTurnoDeJugadorActual();
juego.jugarTurnoDeJugadorActual(dado);

Assertions.assertThrows(PasaronTreintaRondasYnoHuboGanadorError.class,()-> juego.jugarTurnoDeJugadorActual());
Assertions.assertThrows(PasaronTreintaRondasYnoHuboGanadorError.class,()-> juego.jugarTurnoDeJugadorActual(dado));
}
}

0 comments on commit d7d064f

Please sign in to comment.