Upload
others
View
9
Download
0
Embed Size (px)
Citation preview
Fundamentos de Programación
ejercicio 5 tetris
José A. Mañas <[email protected]> Dpto. de Ingeniería de Sistemas Telemá@cos
hCp://www.lab.dit.upm.es/~fprg/ 20.12.2010
juego del tetris
• hCp://es.wikipedia.org/wiki/Tetris • hCp://en.wikipedia.org/wiki/Tetris
• versión adaptada de hCp://www.percederberg.net/ soPware/tetris/index.html
ejercicio 5 -‐ tetris 2
piezas
ejercicio 5 -‐ tetris 3
interface Pieza (1/2)
ejercicio 5 -‐ tetris 4
• int size();
• boolean enTablero(); • boolean vincular(Tablero tablero, boolean center); • void desvincular(); • boolean esCompletamenteVisible(); • boolean haAterrizado();
• void mueveIzquierda(); • void mueveDerecha(); • void mueveAbajo(); • void mueveAlFondo();
interface Pieza (2/2)
ejercicio 5 -‐ tetris 5
• void giroAleatorio(); • void giroDerecha(); • void giroIzquierda(); • int getOrientacion(); • void setOrientacion(int orientacion);
• int getDeltaX(int cuadrado); • int getDeltaY(int cuadrado); • int getDeltaX(int cuadrado, int orientacion); • int getDeltaY(int cuadrado, int orientacion);
posiciones
• getDeltaX(0) = -‐1 • getDeltaX(1) = -‐1 • getDeltaX(2) = 0 • getDeltaX(3) = 1
• getDeltaY(0) = 1 • getDeltaY(1) = 0 • getDeltaY(2) = 0 • getDeltaY(3) = 0
ejercicio 5 -‐ tetris 6
(-‐1, 0) (0, 0) (1, 0)
(-‐1, 1)
(-‐2, 0) (-‐1, 0) (0, 0) (1, 0)
(-‐1, 0) (0, 0) (1, 0)
(-‐1, 1)
(-‐1, 0) (0, 0) (1, 0)
(1, 1)
I
J
L
(-‐1, 0) (0, 0)
(0, 1) (-‐1, 1)
O
ejercicio 5 -‐ tetris 7
(-‐1, 0) (0, 0)
(1, 1) (0, 1) S
(0, 0) (1, 0)
(0, 1) (-‐1, 1) Z
(0, 0) (1, 0)
(0, 1)
(-‐1, 0)
T
ejercicio 5 -‐ tetris 8
orientaciones
• 0
• 1
• 2
• 3
ejercicio 5 -‐ tetris 9
giro estándar
ejercicio 5 -‐ tetris 10
public int getDeltaX(int cuadrado, int orientacion) { switch (orientacion % 4) { default: return getDeltaX(cuadrado); case 1: return -getDeltaY(cuadrado); case 2: return -getDeltaX(cuadrado); case 3: return getDeltaY(cuadrado); } }
giros
• piezas con 0 giros – O – hay que redefinir
• getDeltaX(int cuadrado, int orientacion) • getDeltaY(int cuadrado, int orientacion)
• piezas con 2 giros – I, S, Z – hay que redefinir
• getDeltaX(int cuadrado, int orientacion) • getDeltaY(int cuadrado, int orientacion)
• piezas con 4 giros – J, L, T – se pueden heredar los métodos del padre
ejercicio 5 -‐ tetris 11
PiezaAbstracta
• public abstract class PiezaAbstracta implements Pieza {
• public PiezaAbstracta(Color color) { • this.color = color; • } • ...
ejercicio 5 -‐ tetris 12
Pieza...
ejercicio 5 -‐ tetris 13
public class PiezaJ extends PiezaAbstracta {
public PiezaJ() { super(new Color(0xf5, 0xf4, 0xa7)); ... }
public int size() { ... }
public int getDeltaX(int cuadrado) { ... }
public int getDeltaY(int cuadrado) { ... } }
Entrega
• Hay que entregar el código de las 7 piezas – O, I, J, L, S, T y Z
ejercicio 5 -‐ tetris 14