MCPcopy Create free account
hub / github.com/chvin/react-tetris / constructor

Method constructor

src/unit/block.js:5–54  ·  view source on GitHub ↗
(option)

Source from the content-addressed store, hash-verified

3
4class Block {
5 constructor(option) {
6 this.type = option.type;
7
8 if (!option.rotateIndex) {
9 this.rotateIndex = 0;
10 } else {
11 this.rotateIndex = option.rotateIndex;
12 }
13
14 if (!option.timeStamp) {
15 this.timeStamp = Date.now();
16 } else {
17 this.timeStamp = option.timeStamp;
18 }
19
20 if (!option.shape) { // init
21 this.shape = List(blockShape[option.type].map(e => List(e)));
22 } else {
23 this.shape = option.shape;
24 }
25 if (!option.xy) {
26 switch (option.type) {
27 case 'I': // I
28 this.xy = List([0, 3]);
29 break;
30 case 'L': // L
31 this.xy = List([-1, 4]);
32 break;
33 case 'J': // J
34 this.xy = List([-1, 4]);
35 break;
36 case 'Z': // Z
37 this.xy = List([-1, 4]);
38 break;
39 case 'S': // S
40 this.xy = List([-1, 4]);
41 break;
42 case 'O': // O
43 this.xy = List([-1, 4]);
44 break;
45 case 'T': // T
46 this.xy = List([-1, 4]);
47 break;
48 default:
49 break;
50 }
51 } else {
52 this.xy = List(option.xy);
53 }
54 }
55 rotate() {
56 const shape = this.shape;
57 let result = List([]);

Callers 3

AtFunction · 0.45
SeFunction · 0.45
app-1.0.1.jsFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected