Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created Nov 2, 2020
Embed
What would you like to do?
getRandomFigure() {
/*
* Nombres de los tetrominós tomados de: https://www.joe.co.uk/gaming/tetris-block-names-221127
* Regresamos una nueva instancia en cada ocasión, pues si definiéramos las figuras en constantes o variables, se tomaría la misma
* referencia en algunas ocasiones
* */
switch (Utils.getRandomNumberInRange(1, 7)) {
case 1:
/*
El cuadrado (smashboy)
**
**
*/
return new Tetromino([
[new Point(0, 0), new Point(1, 0), new Point(0, 1), new Point(1, 1)]
]);
case 2:
/*
La línea (hero)
****
*/
return new Tetromino([
[new Point(0, 0), new Point(1, 0), new Point(2, 0), new Point(3, 0)],
[new Point(0, 0), new Point(0, 1), new Point(0, 2), new Point(0, 3)],
]);
case 3:
/*
La L (orange ricky)
*
***
*/
return new Tetromino([
[new Point(0, 1), new Point(1, 1), new Point(2, 1), new Point(2, 0)],
[new Point(0, 0), new Point(0, 1), new Point(0, 2), new Point(1, 2)],
[new Point(0, 0), new Point(0, 1), new Point(1, 0), new Point(2, 0)],
[new Point(0, 0), new Point(1, 0), new Point(1, 1), new Point(1, 2)],
]);
case 4:
/*
La J (blue ricky)
*
***
*/
return new Tetromino([
[new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(2, 1)],
[new Point(0, 0), new Point(1, 0), new Point(0, 1), new Point(0, 2)],
[new Point(0, 0), new Point(1, 0), new Point(2, 0), new Point(2, 1)],
[new Point(0, 2), new Point(1, 2), new Point(1, 1), new Point(1, 0)],
]);
case 5:
/*
La Z (Cleveland Z)
**
**
*/
return new Tetromino([
[new Point(0, 0), new Point(1, 0), new Point(1, 1), new Point(2, 1)],
[new Point(0, 1), new Point(1, 1), new Point(1, 0), new Point(0, 2)],
]);
case 6:
/*
La otra Z (Rhode island Z)
**
**
*/
return new Tetromino([
[new Point(0, 1), new Point(1, 1), new Point(1, 0), new Point(2, 0)],
[new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 2)],
]);
case 7:
default:
/*
La T (Teewee)
*
***
*/
return new Tetromino([
[new Point(0, 1), new Point(1, 1), new Point(1, 0), new Point(2, 1)],
[new Point(0, 0), new Point(0, 1), new Point(0, 2), new Point(1, 1)],
[new Point(0, 0), new Point(1, 0), new Point(2, 0), new Point(1, 1)],
[new Point(0, 1), new Point(1, 0), new Point(1, 1), new Point(1, 2)],
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment