-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tambien agrego un posible json para ir probando
- Loading branch information
Showing
7 changed files
with
137 additions
and
0 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
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} | ||
] |
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,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(); | ||
} | ||
} | ||
} | ||
} |
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,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
10
src/main/java/edu/fiuba/algo3/modelo/camino/CaminoFactory.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,10 @@ | ||
package edu.fiuba.algo3.modelo.camino; | ||
|
||
public class CaminoFactory { | ||
|
||
public static CaminoTipo crearTipo(Boolean esCamino) { | ||
if (esCamino) | ||
return new Camino(); | ||
return new NoEsCamino(); | ||
} | ||
} |
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,6 @@ | ||
package edu.fiuba.algo3.modelo.camino; | ||
|
||
public abstract class CaminoTipo { | ||
|
||
public abstract void pintar(); | ||
} |
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.camino; | ||
|
||
public class NoEsCamino extends CaminoTipo { | ||
@Override | ||
public void pintar() { | ||
|
||
} | ||
} |
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.efectos; | ||
|
||
import edu.fiuba.algo3.modelo.Efecto; | ||
import edu.fiuba.algo3.modelo.Gladiador; | ||
|
||
public class Ninguno implements Efecto { | ||
@Override | ||
public void aplicar(Gladiador g) { | ||
|
||
} | ||
} |