forked from fiuba/algo3_proyecto_base_tp2
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Agregamos test 09 con la logica de celdas y tablero
Co-authored-by: Sebakrag <sebaskrag@gmail.com> Co-authored-by: agus-germi <agerminario@fi.uba.ar> Co-authored-by: SairBarreto <gbarreto@fi.uba.ar>
- Loading branch information
1 parent
1cc3132
commit e3a3714
Showing
16 changed files
with
251 additions
and
36 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
MIT License | ||
giMIT License | ||
|
||
Copyright (c) 2020 Martin Picco, Seblaz | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,27 @@ | ||
package edu.fiuba.algo3.modelo; | ||
|
||
public class Celda { | ||
|
||
public abstract class Celda { | ||
protected Celda siguiente; | ||
protected int x; | ||
protected int y; | ||
protected Afectante afectante; | ||
|
||
public void afectar(Jugador jugador){ | ||
this.afectante.afectar(jugador); | ||
} | ||
|
||
public boolean tieneCoordenadas(int x, int y){ | ||
return ((this.x == x) && (this.y == y)); | ||
} | ||
|
||
public Celda celdaSiguiente(){ | ||
return this.siguiente; | ||
} | ||
|
||
public void setSiguiente(Celda siguiente) { | ||
this.siguiente = siguiente; | ||
} | ||
|
||
public abstract boolean esCeldaFinal(); | ||
} |
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
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
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
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,42 @@ | ||
package edu.fiuba.algo3.modelo; | ||
|
||
import edu.fiuba.algo3.modelo.afectantes.Vacio; | ||
import edu.fiuba.algo3.modelo.celdas.CeldaComun; | ||
import edu.fiuba.algo3.modelo.celdas.CeldaFinal; | ||
import edu.fiuba.algo3.modelo.celdas.CeldaInicial; | ||
import java.util.ArrayList; | ||
import java.util.Random; | ||
|
||
public class Tablero { | ||
private Celda celdaInicial; | ||
private int tamanio; // | ||
//private ArrayList<Afectante> afectantes; | ||
|
||
public Tablero(int cantidadCeldas, CeldaInicial celdaInicial) { | ||
this.tamanio = cantidadCeldas; | ||
this.celdaInicial = celdaInicial; | ||
//this.afectantes = new ArrayList<>(); | ||
} | ||
|
||
public void armarMapa(){ | ||
Afectante afectante = new Vacio(); // Esto deberia ser un RANDOM siguiendo el mapa del JSON. | ||
Celda actual = this.celdaInicial; | ||
int i = 1; | ||
for (; i < (this.tamanio - 1); i++) { | ||
Celda celdaComun = new CeldaComun(i, i, afectante); | ||
actual.setSiguiente(celdaComun); | ||
actual = celdaComun; | ||
} | ||
Celda celdaMedio = this.buscarCeldaDelMedio(); | ||
Celda celdaFinal = new CeldaFinal(celdaMedio, i, i); | ||
actual.setSiguiente(celdaFinal); | ||
} | ||
|
||
private Celda buscarCeldaDelMedio() { | ||
Celda celdaMedio = this.celdaInicial; | ||
for (int i = 1; i < (tamanio / 2) ; i++) { | ||
celdaMedio = celdaMedio.celdaSiguiente(); | ||
} | ||
return celdaMedio; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/edu/fiuba/algo3/modelo/afectantes/Vacio.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,13 @@ | ||
package edu.fiuba.algo3.modelo.afectantes; | ||
|
||
import edu.fiuba.algo3.modelo.Afectante; | ||
import edu.fiuba.algo3.modelo.Jugador; | ||
|
||
public class Vacio implements Afectante { | ||
|
||
public Vacio() { } | ||
|
||
public void afectar(Jugador jugador) { | ||
// no hace nada... ;) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/edu/fiuba/algo3/modelo/celdas/CeldaComun.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,18 @@ | ||
package edu.fiuba.algo3.modelo.celdas; | ||
|
||
import edu.fiuba.algo3.modelo.Celda; | ||
import edu.fiuba.algo3.modelo.afectantes.*; | ||
import edu.fiuba.algo3.modelo.Afectante; | ||
|
||
public class CeldaComun extends Celda { | ||
public CeldaComun(int x, int y, Afectante afectante) { | ||
this.siguiente = siguiente; | ||
this.afectante = afectante; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public boolean esCeldaFinal(){ | ||
return false; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/edu/fiuba/algo3/modelo/celdas/CeldaFinal.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,27 @@ | ||
package edu.fiuba.algo3.modelo.celdas; | ||
|
||
import edu.fiuba.algo3.modelo.Celda; | ||
import edu.fiuba.algo3.modelo.afectantes.*; | ||
import edu.fiuba.algo3.modelo.Jugador; | ||
|
||
public class CeldaFinal extends Celda { | ||
|
||
public CeldaFinal(Celda siguiente, int x, int y) { | ||
this.siguiente = siguiente; | ||
this.afectante = new Vacio(); | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public void afectar(Jugador jugador) { | ||
if (!(jugador.totalmenteEquipado())) { | ||
jugador.posicionar(this.celdaSiguiente()); | ||
} | ||
// jugador.ganarJuego(); A analizar... | ||
// this.juego.gano(jugador); A analizar... | ||
} | ||
|
||
public boolean esCeldaFinal(){ | ||
return true; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/edu/fiuba/algo3/modelo/celdas/CeldaInicial.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,23 @@ | ||
package edu.fiuba.algo3.modelo.celdas; | ||
|
||
import edu.fiuba.algo3.modelo.Afectante; | ||
import edu.fiuba.algo3.modelo.Celda; | ||
import edu.fiuba.algo3.modelo.afectantes.*; | ||
|
||
public class CeldaInicial extends Celda { | ||
|
||
// Conviene tener solo CeldaComun y CeldaFinal? Haciendo que | ||
// CeldaComun tenga un constructor que reciba las coordenadas | ||
// y que instanciemos CeldaComun con x=0 e y=0 para crear la | ||
// celda inicial. | ||
|
||
public CeldaInicial() { | ||
this.afectante = new Vacio(); | ||
this.x = 0; | ||
this.y = 0; | ||
} | ||
|
||
public boolean esCeldaFinal(){ | ||
return false; | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.