-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlock.qml
111 lines (108 loc) · 3.62 KB
/
Block.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import QtQuick 2.0
Item {
id: block
property int col
property int row
property var cellOffsetList
property int cellOffsetListIndex: 0
property var cellOffsets: cellOffsetList[cellOffsetListIndex]
property string color
width: gameField.cellSize * (1 + Math.max(cellOffsets[0][1], cellOffsets[1][1], cellOffsets[2][1], cellOffsets[3][1]))
height: gameField.cellSize * (1 + Math.max(cellOffsets[0][0], cellOffsets[1][0], cellOffsets[2][0], cellOffsets[3][0]))
Cell {
row: parent.row + parent.cellOffsets[0][0]
col: parent.col + parent.cellOffsets[0][1]
maxRow: gameField.rows
cellSize: gameField.cellSize
color: parent.color
}
Cell {
row: parent.row + parent.cellOffsets[1][0]
col: parent.col + parent.cellOffsets[1][1]
maxRow: gameField.rows
cellSize: gameField.cellSize
color: parent.color
}
Cell {
row: parent.row + parent.cellOffsets[2][0]
col: parent.col + parent.cellOffsets[2][1]
maxRow: gameField.rows
cellSize: gameField.cellSize
color: parent.color
}
Cell {
row: parent.row + parent.cellOffsets[3][0]
col: parent.col + parent.cellOffsets[3][1]
maxRow: gameField.rows
cellSize: gameField.cellSize
color: parent.color
}
states: [
State {
name: 'I'
PropertyChanges {
target: block
color: 'cyan'
cellOffsetList: [[[0, 0], [0, 1], [0, 2], [0, 3]], [[-1, 1], [0, 1], [1, 1], [2, 1]]]
}
},
State {
name: 'O';
PropertyChanges {
target: block
color: 'yellow'
cellOffsetList: [[[0, 0], [0, 1], [1, 0], [1, 1]]]
}
},
State {
name: 'T';
PropertyChanges {
target: block
color: 'purple'
cellOffsetList: [[[0, 0], [0, 1], [0, 2], [1, 1]], [[0, 2], [0, 1], [-1, 1], [1, 1]], [[0, 0], [0, 1], [0, 2], [-1, 1]], [[0, 0], [0, 1], [-1, 1], [1, 1]]]
}
},
State {
name: 'J';
PropertyChanges {
target: block
color: 'blue'
cellOffsetList: [[[0, 0], [0, 1], [0, 2], [1, 2]], [[-1, 1], [0, 1], [1, 1], [-1, 2]], [[0, 0], [0, 1], [0, 2], [-1, 0]], [[-1, 1], [0, 1], [1, 1], [1, 0]]]
}
},
State {
name: 'L';
PropertyChanges {
target: block
color: 'orange'
cellOffsetList: [[[0, 0], [0, 1], [0, 2], [1, 0]], [[-1, 1], [0, 1], [1, 1], [1, 2]], [[0, 0], [0, 1], [0, 2], [-1, 2]], [[1, 1], [0, 1], [-1, 1], [-1, 0]]]
}
},
State {
name: 'S';
PropertyChanges {
target: block
color: 'green'
cellOffsetList: [[[0, 1], [0, 2], [1, 0], [1, 1]], [[0, 1], [0, 2], [-1, 1], [1, 2]]]
}
},
State {
name: 'Z';
PropertyChanges {
target: block
color: 'red'
cellOffsetList: [[[0, 0], [0, 1], [1, 1], [1, 2]], [[0, 0], [0, 1], [1, 0], [-1, 1]]]
}
}
]
function rotateCW() {
var index = block.cellOffsetListIndex + block.cellOffsetList.length - 1
index %= block.cellOffsetList.length
cellOffsetListIndex = index
}
function rotateCCW() {
var index = block.cellOffsetListIndex + 1
index %= block.cellOffsetList.length
cellOffsetListIndex = index
}
}