Skip to content

Commit

Permalink
El festin frutal
Browse files Browse the repository at this point in the history
  • Loading branch information
dlopezalvas committed Aug 4, 2022
1 parent 5209983 commit e641d10
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 7 deletions.
60 changes: 60 additions & 0 deletions src/escenas/ElFestinFrutal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/// <reference path = "LaEleccionDelMono.ts" />
/// <reference path = "../actores/Cuadricula.ts" />
/// <reference path = "../actores/BananaAnimada.ts" />
/// <reference path = "../actores/ManzanaAnimada.ts" />
/// <reference path = "../actores/MonoAnimado.ts" />
/// <reference path = "../comportamientos/MovimientosEnCuadricula.ts" />

class ElFestinFrutal extends LaEleccionDelMono{
ajustarAutomata(){
this.cuadricula.agregarActorEnPerspectiva(this.automata,0,0);
this.automata.y -= 25
}

estadoAlTerminar(){
return this.comioTodaLaFruta()
}

agregarCuadricula() {
this.cuadricula = new CuadriculaEsparsa(0, 0,
{ alto: 400, ancho: 360, separacionEntreCasillas: 5 },
{ grilla: 'casillas.violeta.png' }, this.matriz())

}

matriz() {
return [
['T', 'T', 'T', 'T', 'T'],
['T', 'F', 'T', 'T', 'T'],
['T', 'F', 'T', 'T', 'T'],
['T', 'F', 'T', 'T', 'T'],
['T', 'F', 'T', 'T', 'T'],
['T', 'F', 'T', 'T', 'T'],
['T', 'F', 'T', 'T', 'T']
]
}

completarConFruta(){
[0,2,3,4].forEach(columna => this.completarColumnaConFrutas(columna))
}

completarColumnaConFrutas(columna){
[1,2,3,4,5,6].forEach(fila => this.agregarFrutaAleatoria(fila, columna))
}

agregarFrutaAleatoria(fila, columna){
if(Math.random() > 0.5){
this.agregarFruta(BananaAnimada, 49, fila, columna)
}else{
this.agregarFruta(ManzanaAnimada, 35, fila, columna)
}
}

agregarFruta(fruta, desplazamientoY, fila, columna){
const _fruta = new fruta(0,0)
this.cuadricula.agregarActorEnPerspectiva(_fruta,fila,columna)
_fruta.escala = 0.5
_fruta.y -= desplazamientoY
}

}
2 changes: 1 addition & 1 deletion src/escenas/ElMonoYLasBananas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference path = "../actores/BananaAnimada.ts" />

class ElMonoYLasBananas extends LaEleccionDelMono {
agregarFruta(){
completarConFruta(){
if (Math.random() < .5) {
this.agregar(BananaAnimada);
}
Expand Down
28 changes: 22 additions & 6 deletions src/escenas/LaEleccionDelMono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,36 @@ class LaEleccionDelMono extends EscenaActividad {
fondo;
cuadricula;
iniciar() {
this.estado = new Estado(() => this.cantidadObjetosConEtiqueta('BananaAnimada')==0 && this.cantidadObjetosConEtiqueta('ManzanaAnimada')==0 && this.automata.casillaActual().sos(0,1));
this.estado = new Estado(() => this.estadoAlTerminar());
this.fondo = new Fondo('fondos.selva.png',0,0);
this.agregarCuadricula()

this.automata = new MonoAnimado(0,0);
this.ajustarAutomata()

this.completarConFruta();
}

ajustarAutomata(){
this.cuadricula.agregarActorEnPerspectiva(this.automata,0,0,false);
}

estadoAlTerminar(){
return this.comioTodaLaFruta() && this.automata.casillaActual().sos(0,1)
}

agregarCuadricula(){
this.cuadricula = new Cuadricula(0,0,1,2,
{alto: 200},
{grilla: 'casillas.violeta.png',
cantColumnas: 1})
}

this.automata = new MonoAnimado(0,0);
this.cuadricula.agregarActorEnPerspectiva(this.automata,0,0,false);

this.agregarFruta();
comioTodaLaFruta(){
return this.cantidadObjetosConEtiqueta('BananaAnimada') == 0 && this.cantidadObjetosConEtiqueta('ManzanaAnimada') == 0
}

agregarFruta(){
completarConFruta(){
if (Math.random() < .5) {
this.agregar(ManzanaAnimada);
} else {
Expand Down

0 comments on commit e641d10

Please sign in to comment.