Skip to content

Commit

Permalink
Merge pull request #27 from Program-AR/fixing-exercises
Browse files Browse the repository at this point in the history
Fixes de los desafios (pasillo curvo de sandías y recolector de galaxias)
  • Loading branch information
asanzo authored Aug 16, 2022
2 parents d5f694b + ece7bcb commit f34e669
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
Binary file added src/assets/casilla.mariaSandiaCurva.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 37 additions & 20 deletions src/escenas/ElPasilloCurvoDeSandias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@


class ElPasilloCurvoDeSandias extends MariaLaComeSandias {
dimensionesCuadricula(){
dimensionesCuadricula() {
return {
cantidadColumnas: 4,
cantidadFilas: 8
}
}

escalaAutomata(){ return 1.9}
escalaAutomata() { return 1.9 }

agregarCuadricula() {
this.cuadricula = new CuadriculaEsparsa(0, 0,
{ alto: 420, ancho: 180, separacionEntreCasillas: 5 },
{ grilla: 'casilla.mariaSandia.png' }, this.matriz())
this.colorearCurvas()
}

matriz() {
Expand All @@ -31,30 +32,46 @@ class ElPasilloCurvoDeSandias extends MariaLaComeSandias {
['T', 'F', 'F', 'F']]
}

colorearCurvas() {
const coordenadasCurvas = this.curvasAleatorias().concat(this.extremosCurvas())
coordenadasCurvas.forEach(c => this.cuadricula.casilla(c.y, c.x).cambiarImagen('casilla.mariaSandiaCurva.png'))
}

completarConSandias() {
this.completarComienzosDeCurvas()
this.completarCurvaAleatoria(2,0)
this.completarCurvaAleatoria(1, 4)
this.completarCurvasAleatorias()
}

completarComienzosDeCurvas(){
[{x: 0, y: 4},
{x: 0, y: 6},
{x: 1, y: 0},
{x: 1, y: 2}
].forEach(({x, y}) => {
this.agregarSandia(x,y)
})
completarComienzosDeCurvas() {
this.extremosCurvas().forEach(({ x, y }) => {
this.agregarSandia(x, y)
})
}

extremosCurvas() {
return [{ x: 0, y: 4 },
{ x: 0, y: 6 },
{ x: 1, y: 0 },
{ x: 1, y: 2 }
]
}

coordenadasCurva(x, y) {
return [{ x, y },
{ x: x + 1, y },
{ x: x + 1, y: y + 1 },
{ x: x + 1, y: y + 2 },
{ x, y: y + 2 }
]
}

curvasAleatorias(){
return this.coordenadasCurva(2, 0).concat(this.coordenadasCurva(1, 4))
}

completarCurvaAleatoria(x, y){
[{x, y},
{x: x+1, y},
{x: x+1, y: y+1},
{x: x+1, y: y+2},
{x, y: y+2}
].forEach(({x, y}) => {
if(Math.random() > 0.5) this.agregarSandia(x,y)
completarCurvasAleatorias() {
this.curvasAleatorias().forEach(({ x, y }) => {
if (Math.random() > 0.5) this.agregarSandia(x, y)
})
}

Expand Down
26 changes: 24 additions & 2 deletions src/escenas/RecolectorDeGalaxias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <reference path = "../habilidades/Flotar.ts" />

class RecolectorDeGalaxias extends ElRecolectorDeEstrellas {
dimensionesCuadricula(){
dimensionesCuadricula() {
return {
alto: 420,
filas: 7,
Expand All @@ -12,7 +12,29 @@ class RecolectorDeGalaxias extends ElRecolectorDeEstrellas {
}
}

filasACompletar() { return [0,1,2,4,5,6] }
filasACompletar() { return [0, 1, 2, 4, 5, 6] }

randomColumn(cantidad) {
return Math.floor(Math.random() * cantidad);
}

completarFilaConEstrellas(fila) {
var columnas = [1, 2, 3, 4];
var index;
var columna;
[4, 3].forEach(cantidad => {
index = this.randomColumn(cantidad);
columna = columnas[index];
this.agregarEstrella(fila, columna);
columnas.splice(index, 1);
});

columnas.forEach(columna => {
if (Math.random() > 0.5) {
this.agregarEstrella(fila, columna);
}
})
}

ajustarAutomata() {
this.automata.escala *= 0.7;
Expand Down

0 comments on commit f34e669

Please sign in to comment.