Skip to content

Commit

Permalink
Tambien agrego un posible json para ir probando
Browse files Browse the repository at this point in the history
  • Loading branch information
Damlima committed Nov 20, 2023
1 parent 384c37c commit 1504031
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 0 deletions.
31 changes: 31 additions & 0 deletions mapa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{"x": 0, "y": 0, "esCamino": true, "ordenRecorrido": 1, "efecto": "Comida"},
{"x": 1, "y": 0, "esCamino": true, "ordenRecorrido": 2, "efecto": null},
{"x": 2, "y": 0, "esCamino": false, "ordenRecorrido": null, "efecto": null},
{"x": 3, "y": 0, "esCamino": true, "ordenRecorrido": 3, "efecto": "Comida"},
{"x": 4, "y": 0, "esCamino": true, "ordenRecorrido": 4, "efecto": null},

{"x": 0, "y": 1, "esCamino": true, "ordenRecorrido": 5, "efecto": "Bacanal"},
{"x": 1, "y": 1, "esCamino": false, "ordenRecorrido": null, "efecto": null},
{"x": 2, "y": 1, "esCamino": true, "ordenRecorrido": 6, "efecto": null},
{"x": 3, "y": 1, "esCamino": false, "ordenRecorrido": null, "efecto": null},
{"x": 4, "y": 1, "esCamino": true, "ordenRecorrido": 7, "efecto": "Fiera"},

{"x": 0, "y": 2, "esCamino": false, "ordenRecorrido": null, "efecto": null},
{"x": 1, "y": 2, "esCamino": true, "ordenRecorrido": 8, "efecto": null},
{"x": 2, "y": 2, "esCamino": true, "ordenRecorrido": 9, "efecto": "Equipamiento"},
{"x": 3, "y": 2, "esCamino": true, "ordenRecorrido": 10, "efecto": null},
{"x": 4, "y": 2, "esCamino": false, "ordenRecorrido": null, "efecto": null},

{"x": 0, "y": 3, "esCamino": true, "ordenRecorrido": 11, "efecto": "Equipamiento"},
{"x": 1, "y": 3, "esCamino": false, "ordenRecorrido": null, "efecto": null},
{"x": 2, "y": 3, "esCamino": true, "ordenRecorrido": 12, "efecto": null},
{"x": 3, "y": 3, "esCamino": false, "ordenRecorrido": null, "efecto": null},
{"x": 4, "y": 3, "esCamino": true, "ordenRecorrido": 13, "efecto": null},

{"x": 0, "y": 4, "esCamino": true, "ordenRecorrido": 14, "efecto": null},
{"x": 1, "y": 4, "esCamino": true, "ordenRecorrido": 15, "efecto": null},
{"x": 2, "y": 4, "esCamino": false, "ordenRecorrido": null, "efecto": null},
{"x": 3, "y": 4, "esCamino": true, "ordenRecorrido": 16, "efecto": null},
{"x": 4, "y": 4, "esCamino": true, "ordenRecorrido": 17, "efecto": null}
]
61 changes: 61 additions & 0 deletions src/main/java/edu/fiuba/algo3/modelo/TableroB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package edu.fiuba.algo3.modelo;

import java.util.*;

import com.google.gson.JsonObject;
import edu.fiuba.algo3.modelo.camino.CaminoFactory;
import edu.fiuba.algo3.modelo.camino.CaminoTipo;

public class TableroB {

private final ArrayList<ArrayList<Casilla>> casillas;
private final Map<Integer, Casilla> camino;
private final Map<Gladiador, Integer> posicionGladiadiores;

public TableroB(List<Gladiador> gladiadores, List<JsonObject> mapa) {
this.casillas = new ArrayList<>();
this.camino = new HashMap<>();
this.posicionGladiadiores = new HashMap<>();
crearTablero(mapa);
asignarPosicionesDe(gladiadores);
}

public void mover(Gladiador g, int a) {
int nuevaUbicacion = posicionGladiadiores.get(g) + a;
posicionGladiadiores.put(g, nuevaUbicacion) ;
camino.get(nuevaUbicacion).aplicarEfecto(g);
}

public boolean estaEl(Gladiador g, int en) {
return this.posicionGladiadiores.get(g) == en;
}

private void asignarPosicionesDe(List<Gladiador> g) {
for (Gladiador gladiador: g) {
posicionGladiadiores.put(gladiador, 0);
}
}

private void crearTablero(List<JsonObject> mapa) {
int y = 0;
ArrayList<Casilla> fila = new ArrayList<>();
for (JsonObject dato: mapa) {
Efecto efecto = EfectoFactory.crearEfecto(dato.get("efecto").toString().replaceAll("^\"|\"$", ""));
boolean esCamino = dato.get("esCamino").getAsBoolean();;
CaminoTipo tipo = CaminoFactory.crearTipo(esCamino);
Casilla casilla = new Casilla(efecto, tipo);
if (esCamino)
camino.put(dato.get("ordenRecorrido").getAsInt(), casilla);

if (dato.get("y").getAsInt() == y) {
fila.add(casilla);
}
else {
casillas.add(fila);
fila = new ArrayList<>();
fila.add(casilla);
y = dato.get("y").getAsInt();
}
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/edu/fiuba/algo3/modelo/camino/Camino.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package edu.fiuba.algo3.modelo.camino;

import edu.fiuba.algo3.modelo.camino.CaminoTipo;

public class Camino extends CaminoTipo {
@Override
public void pintar() {

}
}
10 changes: 10 additions & 0 deletions src/main/java/edu/fiuba/algo3/modelo/camino/CaminoFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package edu.fiuba.algo3.modelo.camino;

public class CaminoFactory {

public static CaminoTipo crearTipo(Boolean esCamino) {
if (esCamino)
return new Camino();
return new NoEsCamino();
}
}
6 changes: 6 additions & 0 deletions src/main/java/edu/fiuba/algo3/modelo/camino/CaminoTipo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package edu.fiuba.algo3.modelo.camino;

public abstract class CaminoTipo {

public abstract void pintar();
}
8 changes: 8 additions & 0 deletions src/main/java/edu/fiuba/algo3/modelo/camino/NoEsCamino.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package edu.fiuba.algo3.modelo.camino;

public class NoEsCamino extends CaminoTipo {
@Override
public void pintar() {

}
}
11 changes: 11 additions & 0 deletions src/main/java/edu/fiuba/algo3/modelo/efectos/Ninguno.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package edu.fiuba.algo3.modelo.efectos;

import edu.fiuba.algo3.modelo.Efecto;
import edu.fiuba.algo3.modelo.Gladiador;

public class Ninguno implements Efecto {
@Override
public void aplicar(Gladiador g) {

}
}

0 comments on commit 1504031

Please sign in to comment.