106 lines
1.4 KiB
TypeScript
106 lines
1.4 KiB
TypeScript
import { Point } from "./lib/util";
|
|
|
|
export const enum RotationStyle {
|
|
None,
|
|
Center,
|
|
BetweenCenter,
|
|
}
|
|
|
|
export const enum TileColor {
|
|
Red,
|
|
Green,
|
|
Blue,
|
|
Purple,
|
|
Orange,
|
|
Cyan,
|
|
Yellow,
|
|
}
|
|
|
|
export type PieceSchema = {
|
|
tiles: [Point, Point, Point, Point];
|
|
rotation: RotationStyle;
|
|
color: TileColor;
|
|
};
|
|
|
|
export const TETRIS_PIECE: Record<string, PieceSchema> = {
|
|
O: {
|
|
tiles: [
|
|
[0, 0],
|
|
[0, 1],
|
|
[1, 1],
|
|
[1, 0],
|
|
],
|
|
rotation: RotationStyle.None,
|
|
color: TileColor.Red,
|
|
},
|
|
L: {
|
|
tiles: [
|
|
[1, 0],
|
|
[0, 0],
|
|
[-1, 0],
|
|
[-1, 1],
|
|
],
|
|
rotation: RotationStyle.Center,
|
|
color: TileColor.Green,
|
|
},
|
|
J: {
|
|
tiles: [
|
|
[1, 0],
|
|
[1, 1],
|
|
[0, 0],
|
|
[-1, 0],
|
|
],
|
|
rotation: RotationStyle.Center,
|
|
color: TileColor.Blue,
|
|
},
|
|
I: {
|
|
tiles: [
|
|
[0, 0],
|
|
[-1, 0],
|
|
[1, 0],
|
|
[2, 0],
|
|
],
|
|
rotation: RotationStyle.BetweenCenter,
|
|
color: TileColor.Purple,
|
|
},
|
|
T: {
|
|
tiles: [
|
|
[1, 0],
|
|
[0, 0],
|
|
[-1, 0],
|
|
[0, 1],
|
|
],
|
|
rotation: RotationStyle.Center,
|
|
color: TileColor.Orange,
|
|
},
|
|
S: {
|
|
tiles: [
|
|
[1, 0],
|
|
[0, 0],
|
|
[0, 1],
|
|
[-1, 1],
|
|
],
|
|
rotation: RotationStyle.Center,
|
|
color: TileColor.Cyan,
|
|
},
|
|
Z: {
|
|
tiles: [
|
|
[1, 1],
|
|
[0, 0],
|
|
[0, 1],
|
|
[-1, 0],
|
|
],
|
|
rotation: RotationStyle.Center,
|
|
color: TileColor.Yellow,
|
|
},
|
|
};
|
|
export const TETRIS_PIECE_LIST: Array<PieceSchema> = [
|
|
TETRIS_PIECE.O,
|
|
TETRIS_PIECE.S,
|
|
TETRIS_PIECE.Z,
|
|
TETRIS_PIECE.L,
|
|
TETRIS_PIECE.J,
|
|
TETRIS_PIECE.T,
|
|
TETRIS_PIECE.I,
|
|
];
|