Skip to content

Commit

Permalink
Ordenando soluciones
Browse files Browse the repository at this point in the history
  • Loading branch information
Giannoni-Ezequiel committed Nov 8, 2024
1 parent 5f19083 commit 8f01c07
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 45 deletions.
42 changes: 29 additions & 13 deletions controlador.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import juego.*
import BloquesJugables.*
import wollok.game.*

// -------------- Referencias del Matriz-Tablero --------------------

class ElementoMatriz{
var pieza = null
method pieza() = pieza
method pieza(nuevaPieza){pieza = nuevaPieza}
}
object controlador {
var finjuego = false
var contadoresDeLineaCompleta = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] //Se suma 1 cada vez que se ocupa un lugar de su fila, hay 1 contador por cada fila
var contadorLineas = 0
var contadorPuntaje = 0

// -------------- Tablero -------------------------------------------------

const matriz = [ //Para acceder a indice usar coordenada 19-y, asi fila inferior es y = 0 y la superior es y = 19
[new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz()],
[new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz()],
Expand All @@ -32,6 +40,8 @@ object controlador {
[new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz(), new ElementoMatriz()]
]

// ------------- Crear Bloque ---------------------------------

const cantidadDeBloques = 7
method generarBloqueAleatorio() {
const numeroAleatorio = (-0.999).randomUpTo(cantidadDeBloques - 1).roundUp()
Expand All @@ -56,18 +66,25 @@ object controlador {
}
return bloque
}

// --------------------- Game Over - Implementacion ------------------------------


method perder(){
game.addVisual(gameOver)
game.removeTickEvent("Caida")
game.schedule(100, {game.stop()})
}


// ---------------------- Level Up --------------------------------

method actualizarNivel(contador, bloqueUnidad, bloqueDecena){
bloqueUnidad.image("numero" + (contador%10) + ".png")
bloqueDecena.image("numero" + (contador/10).truncate(0) + ".png")
}

// ----------------- Verificar posiciones --------------------

method posEstaOcupada(x, y){//1 si pos esta ocupada, 0 si no esta ocupada
if (x < 18 || x > 27 || y < 0){
return 1
Expand Down Expand Up @@ -100,6 +117,8 @@ object controlador {
return -1
}
}
// --------------------- Completar Linea ----------------------------

method quitarLineaCompleta(yDeFilaCompleta){
self.eliminarLinea(19 - yDeFilaCompleta)
self.bajarLineas(19 - yDeFilaCompleta)
Expand Down Expand Up @@ -136,7 +155,6 @@ object controlador {

}


method bajarLineas(indexLinea){//recibe el indice (de la matriz) de la fila que se elimino
var matrizAuxiliar = matriz.take(indexLinea)//.filter({fila => fila.any({elemento => elemento.pieza() != null})}) //Agarro solo las filas que van a bajar y tienen alguna pieza
//La cantidad de lineas en esta matriz sera la cantidad de veces que se va a hacer el proceso de bajar
Expand Down Expand Up @@ -164,6 +182,8 @@ object controlador {
puntajes.lineasUnidadDeMil().image("numero" + ((contadorLineas/1000).truncate(0) %10) + ".png")
}

// --------------------- Score -----------------------------------

method actualizarPuntaje(valor){
contadorPuntaje += valor
puntajes.puntajeUnidad().image("numero" + (contadorPuntaje%10) + ".png")
Expand All @@ -174,16 +194,6 @@ object controlador {
}
}

class ElementoMatriz{
var pieza = null
method pieza() = pieza
method pieza(nuevaPieza){pieza = nuevaPieza}
}
object gameOver {
method image() = "gameover.png"
method position() = game.at(19, 10)
}

object puntajes {
const linasUnidad = new Numero(posision = game.at(37,10), imagen = "numero0.png")
const linasDecena = new Numero(posision = game.at(36,10), imagen = "numero0.png")
Expand Down Expand Up @@ -221,4 +231,10 @@ object puntajes {
game.addVisual(puntajeDecenaDeMil)

}
}

// ------- Game Over -------------------
object gameOver {
method image() = "gameover.png"
method position() = game.at(19, 10)
}
73 changes: 41 additions & 32 deletions juego.wlk
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import wollok.game.*
import BloquesJugables.*
import controlador.*

// ------------------ Bloque de Tetris ------------------
class BloqueTetris{
var xCentro
var yCentro
Expand All @@ -9,14 +11,15 @@ class BloqueTetris{
const b
const c
const d

method xCentro() = xCentro
method yCentro() = yCentro
method a() = a
method b() = b
method c() = c
method d() = d

// -------------------- Rotacion ------------------------

method rotar(dir){
if (dir == "derecha"){
const listaValoresReturn = [self.rotarHoraria(a), self.rotarHoraria(b), self.rotarHoraria(c), self.rotarHoraria(d)]
Expand Down Expand Up @@ -102,7 +105,7 @@ class BloqueTetris{
return controlador.posEstaOcupada(xRotada, yRotada)
}
}
// ------------------ Mover -----------------------
method mover(dir){
if (dir == "derecha" && controlador.dirEstaLibre("derecha", [a, b, c, d])){
xCentro += 1
Expand Down Expand Up @@ -164,6 +167,7 @@ class BloqueTetris{
method caer(){
self.mover("abajo")
}
// --------------------------- HardDrop ----------------------------

method hardDrop(){
if(controlador.dirEstaLibre("abajo", [a, b, c, d])){
Expand Down Expand Up @@ -195,6 +199,7 @@ class BloqueTetris{
}
}

// ------------------------------- Prediccion ---------------------------------------

method crearSombra(){
const sombraA = new Pieza(image = "sombraFina.png", position = game.at(a.position().x(), a.position().y()))
Expand All @@ -205,36 +210,6 @@ class BloqueTetris{
}
}

//esto podriamos generalizarlo con clases o herencias para incluir al bloque linea

class Pieza{//un "pixel" del bloque de tetris
var position
const image
var xRotada = 0
var yRotada = 0

method image() = image

method asignarPosicion(x, y){
position = game.at(x, y)
}
method position() = position

method caer(){
position = game.at(position.x(), position.y()-1)
}

method guardarPosicionRotada(x, y){
xRotada = x
yRotada = y
}

method asumirPosicionRotada(){
position = game.at(xRotada, yRotada)
}

}

class Tipo_bloqueSombra inherits BloqueTetris{
method descender(){
if(controlador.dirEstaLibre("abajo", [a, b, c, d])){
Expand Down Expand Up @@ -274,6 +249,40 @@ class Tipo_bloqueSombra inherits BloqueTetris{
}
}

//esto podriamos generalizarlo con clases o herencias para incluir al bloque linea

// ----------------------------- Piezas ------------------------------------
class Pieza{//un "pixel" del bloque de tetris
var position
const image
var xRotada = 0
var yRotada = 0

method image() = image

method asignarPosicion(x, y){
position = game.at(x, y)
}
method position() = position

method caer(){
position = game.at(position.x(), position.y()-1)
}

method guardarPosicionRotada(x, y){
xRotada = x
yRotada = y
}

method asumirPosicionRotada(){
position = game.at(xRotada, yRotada)
}

}



// -------------------- VISUAL --------------------------------
class Fondo{
const posision
const imagen
Expand Down

0 comments on commit 8f01c07

Please sign in to comment.