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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec554203ec195d6a53199cf13febb46771d537cd
4
- data.tar.gz: c10cc6150bb6d5ca6d9d66521b51f5b33600291f
3
+ metadata.gz: 9e49ef4242beccb88b45d908f61f8853712db7d4
4
+ data.tar.gz: bc42a43f768919cc054fc67f7cfbe589604a12a2
5
5
  SHA512:
6
- metadata.gz: 3459c8086bc005d632fe6588078104b73d1e9e8401697d3546e47f23c17ae0847f2251c86c874f6787067eab32c25d0e6250b0b08f85d32d527bc58c2a868edb
7
- data.tar.gz: 503cd47c13fa2f107f6b895605dff24c609824232dc612c950d2490c0008561b260d78d98e0de2f87db6499ad1381133e1ebbf0b953cd09403732de7637e7a00
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] |= value } }
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] & value > 0
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 == 1 } }
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| row.map {|b| b == 1 ? '[]' : ' ' }.join('') }
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| row.each.with_index {|value, j| dup_board[tetrimino.y_coordinate + i][tetrimino.x_coordinate + j] |= value } }
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
 
@@ -6,27 +6,27 @@ class ConsoleTetris
6
6
  case degree
7
7
  when 0
8
8
  [
9
- [1, 1, 1, 1],
10
- [0, 0, 0, 1]
9
+ [4, 4, 4, 4],
10
+ [0, 0, 0, 4]
11
11
  ]
12
12
  when 90
13
13
  [
14
- [0, 1],
15
- [0, 1],
16
- [0, 1],
17
- [1, 1]
14
+ [0, 4],
15
+ [0, 4],
16
+ [0, 4],
17
+ [4, 4]
18
18
  ]
19
19
  when 180
20
20
  [
21
- [1, 0, 0, 0],
22
- [1, 1, 1, 1]
21
+ [4, 0, 0, 0],
22
+ [4, 4, 4, 4]
23
23
  ]
24
24
  when 270
25
25
  [
26
- [1, 1],
27
- [1, 0],
28
- [1, 0],
29
- [1, 0]
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
- [1, 1, 1, 1],
39
- [1, 0, 0, 0]
38
+ [7, 7, 7, 7],
39
+ [7, 0, 0, 0]
40
40
  ]
41
41
  when 90
42
42
  [
43
- [1, 1],
44
- [0, 1],
45
- [0, 1],
46
- [0, 1]
43
+ [7, 7],
44
+ [0, 7],
45
+ [0, 7],
46
+ [0, 7]
47
47
  ]
48
48
  when 180
49
49
  [
50
- [0, 0, 0, 1],
51
- [1, 1, 1, 1]
50
+ [0, 0, 0, 7],
51
+ [7, 7, 7, 7]
52
52
  ]
53
53
  when 270
54
54
  [
55
- [1, 0],
56
- [1, 0],
57
- [1, 0],
58
- [1, 1]
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
- [1, 1, 1, 1]
67
+ [6, 6, 6, 6]
68
68
  ]
69
69
  when 90, 270
70
70
  [
71
- [1],
72
- [1],
73
- [1],
74
- [1]
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
- [1, 1],
82
- [1, 1]
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, 1, 1],
91
- [1, 1, 0]
90
+ [0, 2, 2],
91
+ [2, 2, 0]
92
92
  ]
93
93
  when 90, 270
94
94
  [
95
- [1, 0],
96
- [1, 1],
97
- [0, 1]
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
- [1, 1, 1],
123
- [0, 1, 0]
122
+ [5, 5, 5],
123
+ [0, 5, 0]
124
124
  ]
125
125
  when 90
126
126
  [
127
- [0, 1],
128
- [1, 1],
129
- [0, 1]
127
+ [0, 5],
128
+ [5, 5],
129
+ [0, 5]
130
130
  ]
131
131
  when 180
132
132
  [
133
- [0, 1, 0],
134
- [1, 1, 1]
133
+ [0, 5, 0],
134
+ [5, 5, 5]
135
135
  ]
136
136
  when 270
137
137
  [
138
- [1, 0],
139
- [1, 1],
140
- [1, 0]
138
+ [5, 0],
139
+ [5, 5],
140
+ [5, 0]
141
141
  ]
142
142
  end
143
143
  end
@@ -1,3 +1,3 @@
1
1
  class ConsoleTetris
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  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.3
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-21 00:00:00.000000000 Z
11
+ date: 2017-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler