console-tetris 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/console_tetris/background_board.rb +21 -7
- data/lib/console_tetris/block.rb +46 -46
- data/lib/console_tetris/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e49ef4242beccb88b45d908f61f8853712db7d4
|
4
|
+
data.tar.gz: bc42a43f768919cc054fc67f7cfbe589604a12a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71ca0528a5749153d655461b5dbbab43fc6ff8fc7cb70c0919c7eddab185dfe2a86413fd2d89590a9c008360e9dc1b4b9db721902740aeece23b039aa1b72c4e
|
7
|
+
data.tar.gz: f9816aab6389c409e77f9ab1e54c1acf512f71a7d33755422f159f4271f2f89a1faaaf0f188fdd4f3775cf4896ba0c42f967661e23f46349e61587cd3d2b2400
|
@@ -12,7 +12,7 @@ class ConsoleTetris
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def stack!(tetrimino)
|
15
|
-
tetrimino.block.each.with_index {|row, i| row.each.with_index {|value, j| @board[tetrimino.y_coordinate + i][tetrimino.x_coordinate + j]
|
15
|
+
tetrimino.block.each.with_index {|row, i| row.each.with_index {|value, j| @board[tetrimino.y_coordinate + i][tetrimino.x_coordinate + j] += value } }
|
16
16
|
end
|
17
17
|
|
18
18
|
def overlap?(tetrimino)
|
@@ -20,13 +20,13 @@ class ConsoleTetris
|
|
20
20
|
row.map.with_index.any? {|value, j|
|
21
21
|
return false if @board[tetrimino.y_coordinate + i].nil?
|
22
22
|
|
23
|
-
@board[tetrimino.y_coordinate + i][tetrimino.x_coordinate + j]
|
23
|
+
@board[tetrimino.y_coordinate + i][tetrimino.x_coordinate + j] > 0 && value > 0
|
24
24
|
}
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
28
|
def remove_filled_line!
|
29
|
-
@board.reject! {|a| a.all? {|e| e
|
29
|
+
@board.reject! {|a| a.all? {|e| e != 0 } }
|
30
30
|
|
31
31
|
remove_size = BOARD_SIZE[:y] - @board.count
|
32
32
|
|
@@ -47,7 +47,13 @@ class ConsoleTetris
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def print_next_block(tetrimino)
|
50
|
-
block = tetrimino.block.map {|row|
|
50
|
+
block = tetrimino.block.map {|row|
|
51
|
+
row.map {|b|
|
52
|
+
next ' ' if b == 0
|
53
|
+
|
54
|
+
"\e[3#{b}m[]"
|
55
|
+
}.join('') + "\e[0m"
|
56
|
+
}
|
51
57
|
|
52
58
|
print "\e[5;1H"
|
53
59
|
print "\e[1J"
|
@@ -62,7 +68,13 @@ class ConsoleTetris
|
|
62
68
|
def print_block(tetrimino)
|
63
69
|
dup_board = @board.map {|board| board.dup }
|
64
70
|
|
65
|
-
tetrimino.block.each.with_index {|row, i|
|
71
|
+
tetrimino.block.each.with_index {|row, i|
|
72
|
+
row.each.with_index {|value, j|
|
73
|
+
next if dup_board[tetrimino.y_coordinate + i][tetrimino.x_coordinate + j].nil?
|
74
|
+
|
75
|
+
dup_board[tetrimino.y_coordinate + i][tetrimino.x_coordinate + j] += value
|
76
|
+
}
|
77
|
+
}
|
66
78
|
|
67
79
|
print_point
|
68
80
|
|
@@ -80,11 +92,13 @@ class ConsoleTetris
|
|
80
92
|
print case el
|
81
93
|
when 0
|
82
94
|
' '
|
83
|
-
when 1
|
84
|
-
|
95
|
+
when 1..7
|
96
|
+
"\e[3#{el}m[]"
|
85
97
|
end
|
86
98
|
end
|
87
99
|
|
100
|
+
print "\e[0m"
|
101
|
+
|
88
102
|
print "|\n"
|
89
103
|
end
|
90
104
|
|
data/lib/console_tetris/block.rb
CHANGED
@@ -6,27 +6,27 @@ class ConsoleTetris
|
|
6
6
|
case degree
|
7
7
|
when 0
|
8
8
|
[
|
9
|
-
[
|
10
|
-
[0, 0, 0,
|
9
|
+
[4, 4, 4, 4],
|
10
|
+
[0, 0, 0, 4]
|
11
11
|
]
|
12
12
|
when 90
|
13
13
|
[
|
14
|
-
[0,
|
15
|
-
[0,
|
16
|
-
[0,
|
17
|
-
[
|
14
|
+
[0, 4],
|
15
|
+
[0, 4],
|
16
|
+
[0, 4],
|
17
|
+
[4, 4]
|
18
18
|
]
|
19
19
|
when 180
|
20
20
|
[
|
21
|
-
[
|
22
|
-
[
|
21
|
+
[4, 0, 0, 0],
|
22
|
+
[4, 4, 4, 4]
|
23
23
|
]
|
24
24
|
when 270
|
25
25
|
[
|
26
|
-
[
|
27
|
-
[
|
28
|
-
[
|
29
|
-
[
|
26
|
+
[4, 4],
|
27
|
+
[4, 0],
|
28
|
+
[4, 0],
|
29
|
+
[4, 0]
|
30
30
|
]
|
31
31
|
end
|
32
32
|
end
|
@@ -35,27 +35,27 @@ class ConsoleTetris
|
|
35
35
|
case degree
|
36
36
|
when 0
|
37
37
|
[
|
38
|
-
[
|
39
|
-
[
|
38
|
+
[7, 7, 7, 7],
|
39
|
+
[7, 0, 0, 0]
|
40
40
|
]
|
41
41
|
when 90
|
42
42
|
[
|
43
|
-
[
|
44
|
-
[0,
|
45
|
-
[0,
|
46
|
-
[0,
|
43
|
+
[7, 7],
|
44
|
+
[0, 7],
|
45
|
+
[0, 7],
|
46
|
+
[0, 7]
|
47
47
|
]
|
48
48
|
when 180
|
49
49
|
[
|
50
|
-
[0, 0, 0,
|
51
|
-
[
|
50
|
+
[0, 0, 0, 7],
|
51
|
+
[7, 7, 7, 7]
|
52
52
|
]
|
53
53
|
when 270
|
54
54
|
[
|
55
|
-
[
|
56
|
-
[
|
57
|
-
[
|
58
|
-
[
|
55
|
+
[7, 0],
|
56
|
+
[7, 0],
|
57
|
+
[7, 0],
|
58
|
+
[7, 7]
|
59
59
|
]
|
60
60
|
end
|
61
61
|
end
|
@@ -64,22 +64,22 @@ class ConsoleTetris
|
|
64
64
|
case degree
|
65
65
|
when 0, 180
|
66
66
|
[
|
67
|
-
[
|
67
|
+
[6, 6, 6, 6]
|
68
68
|
]
|
69
69
|
when 90, 270
|
70
70
|
[
|
71
|
-
[
|
72
|
-
[
|
73
|
-
[
|
74
|
-
[
|
71
|
+
[6],
|
72
|
+
[6],
|
73
|
+
[6],
|
74
|
+
[6]
|
75
75
|
]
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
def type_o(degree)
|
80
80
|
[
|
81
|
-
[
|
82
|
-
[
|
81
|
+
[3, 3],
|
82
|
+
[3, 3]
|
83
83
|
]
|
84
84
|
end
|
85
85
|
|
@@ -87,14 +87,14 @@ class ConsoleTetris
|
|
87
87
|
case degree
|
88
88
|
when 0, 180
|
89
89
|
[
|
90
|
-
[0,
|
91
|
-
[
|
90
|
+
[0, 2, 2],
|
91
|
+
[2, 2, 0]
|
92
92
|
]
|
93
93
|
when 90, 270
|
94
94
|
[
|
95
|
-
[
|
96
|
-
[
|
97
|
-
[0,
|
95
|
+
[2, 0],
|
96
|
+
[2, 2],
|
97
|
+
[0, 2]
|
98
98
|
]
|
99
99
|
end
|
100
100
|
end
|
@@ -119,25 +119,25 @@ class ConsoleTetris
|
|
119
119
|
case degree
|
120
120
|
when 0
|
121
121
|
[
|
122
|
-
[
|
123
|
-
[0,
|
122
|
+
[5, 5, 5],
|
123
|
+
[0, 5, 0]
|
124
124
|
]
|
125
125
|
when 90
|
126
126
|
[
|
127
|
-
[0,
|
128
|
-
[
|
129
|
-
[0,
|
127
|
+
[0, 5],
|
128
|
+
[5, 5],
|
129
|
+
[0, 5]
|
130
130
|
]
|
131
131
|
when 180
|
132
132
|
[
|
133
|
-
[0,
|
134
|
-
[
|
133
|
+
[0, 5, 0],
|
134
|
+
[5, 5, 5]
|
135
135
|
]
|
136
136
|
when 270
|
137
137
|
[
|
138
|
-
[
|
139
|
-
[
|
140
|
-
[
|
138
|
+
[5, 0],
|
139
|
+
[5, 5],
|
140
|
+
[5, 0]
|
141
141
|
]
|
142
142
|
end
|
143
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console-tetris
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pekepek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|