text2048 0.7.0 → 0.8.0

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: b3a9fa828625d47123e5b5da1f648bb3469f8238
4
- data.tar.gz: 686ec778c882bfbf3f2c9ae667e39a3f1aba8825
3
+ metadata.gz: 185c956718085eb81aef19c630b8cee21e67d71f
4
+ data.tar.gz: efb909b378a7c05e887ac9f6a4a45c84dd47e9c2
5
5
  SHA512:
6
- metadata.gz: 7b668ba69fe2bc9ddaa776de2480b794eeedab09ed9bf3e4ef36fa9b5b579477d9f945a15422f7ed914fed1d869e10f6ce9be15137f1b54ac26359aa19eba8aa
7
- data.tar.gz: a67611a3b78da79182004417ef90826b2d750fde61bd28b9cb206980469ddc055ab9ffe9f554960b9f03cf4ffaceeb2d6b02d17200b119e8877e7089db561e04
6
+ metadata.gz: 253d485900f6ea785acd1de33bbdab69f46126319640062ffd80cc5779bb7efa8b3f7a7f750d65141bbeb86bfd60805865f966c4db10402cfbace5c381bdc494
7
+ data.tar.gz: 91f25760bb10e3b313263ec88cc6006a38d077325296b4086eadbdd5cb909452c2161ff996ad7cf8f8c0eef9d0c0426bb43ffafb54b91a367c5723a764eca79a
data/README.md CHANGED
@@ -5,27 +5,30 @@ text2048
5
5
  [![Code Climate](http://img.shields.io/codeclimate/github/yasuhito/text2048.svg)][codeclimate]
6
6
  [![Coverage Status](http://img.shields.io/coveralls/yasuhito/text2048/develop.svg)][coveralls]
7
7
  [![Dependency Status](http://img.shields.io/gemnasium/yasuhito/text2048.svg)][gemnasium]
8
+ [![Gittip](http://img.shields.io/gittip/yasuhito.svg)][gittip]
8
9
 
9
10
  Text mode 2048 game.
10
11
 
11
- [![Screenshot](https://raw.github.com/yasuhito/text2048/develop/screen_shot.png)][screenshot]
12
-
13
12
  [gem]: https://rubygems.org/gems/text2048
14
13
  [travis]: http://travis-ci.org/yasuhito/text2048
15
14
  [codeclimate]: https://codeclimate.com/github/yasuhito/text2048
16
15
  [coveralls]: https://coveralls.io/r/yasuhito/text2048?branch=develop
17
16
  [gemnasium]: https://gemnasium.com/yasuhito/text2048
17
+ [gittip]: https://www.gittip.com/yasuhito/
18
+
19
+ [![Screenshot](https://raw.github.com/yasuhito/text2048/develop/screen_shot.png)][screenshot]
20
+
18
21
  [screenshot]: https://raw.github.com/yasuhito/text2048/develop/screen_shot.png
19
22
 
20
23
  Installation
21
- ============
24
+ ------------
22
25
 
23
26
  ```
24
27
  $ gem install text2048
25
28
  ```
26
29
 
27
30
  How to Play
28
- ===========
31
+ -----------
29
32
 
30
33
  ```
31
34
  $ 2048
@@ -35,7 +38,12 @@ $ 2048
35
38
  - +/- for increase or decrease the size of the tiles displayed.
36
39
 
37
40
  Links
38
- =====
41
+ -----
39
42
 
40
43
  * [The official version of 2048](http://gabrielecirulli.github.io/2048/) by Gabriele Cirulli
41
44
  * [bfontaine/term2048](https://github.com/bfontaine/term2048) a terminal-based version in Python
45
+
46
+ Author
47
+ ------
48
+
49
+ [Yasuhito Takamiya](https://github.com/yasuhito) ([@yasuhito](http://twitter.com/yasuhito))
@@ -76,7 +76,7 @@ module Text2048
76
76
  # @return [Board] a new board
77
77
  def generate
78
78
  tiles = @all_tiles.dup
79
- tiles[sample_zero_tile] = Tile.new(rand < 0.8 ? 2 : 4, :generated)
79
+ tiles[sample_zero_tile] = Tile.new(rand < 0.9 ? 2 : 4, :generated)
80
80
  new_board(tiles, @score)
81
81
  end
82
82
 
@@ -4,6 +4,7 @@ require 'curses'
4
4
  require 'forwardable'
5
5
  require 'text2048/curses_view/colorize'
6
6
  require 'text2048/curses_view/keyboard'
7
+ require 'text2048/curses_view/lcd'
7
8
  require 'text2048/curses_view/tile'
8
9
  require 'text2048/curses_view/tile_effects'
9
10
 
@@ -21,8 +22,8 @@ module Text2048
21
22
 
22
23
  def initialize
23
24
  @tiles = {}
24
- @scale = 2
25
- @scale_min = 1
25
+ @scale = 1
26
+ @scale_min = 0.5
26
27
  @scale_step = 0.5
27
28
  @keyboard = Keyboard.new
28
29
  end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ # This module smells of :reek:UncommunicativeModuleName
4
+ module Text2048
5
+ class CursesView
6
+ # Renders numbers like LCDs
7
+ class LCD
8
+ BITMAPS = [
9
+ 0b1111111110111,
10
+ 0b1010100100100,
11
+ 0b1111111011101,
12
+ 0b1111111101101,
13
+ 0b1011110101110,
14
+ 0b1111111101011,
15
+ 0b1111111111011,
16
+ 0b1010110100101,
17
+ 0b1111111111111,
18
+ 0b1111111101111
19
+ ]
20
+
21
+ TOP = 0
22
+ TOP_LEFT = 1
23
+ TOP_RIGHT = 2
24
+ MIDDLE = 3
25
+ BOTTOM_LEFT = 4
26
+ BOTTOM_RIGHT = 5
27
+ BOTTOM = 6
28
+
29
+ CORNER_TOP_LEFT = 7
30
+ CORNER_TOP_RIGHT = 8
31
+ CORNER_MIDDLE_LEFT = 9
32
+ CORNER_MIDDLE_RIGHT = 10
33
+ CORNER_BOTTOM_LEFT = 11
34
+ CORNER_BOTTOM_RIGHT = 12
35
+
36
+ def initialize(number)
37
+ @number = number
38
+ end
39
+
40
+ def render
41
+ digits = @number.to_s.split(//).map { |each| digit(each) }
42
+ digits.transpose.map { |each| each.join(' ') }.join("\n")
43
+ end
44
+
45
+ private
46
+
47
+ def digit(number)
48
+ lines =
49
+ [[CORNER_TOP_LEFT, TOP, CORNER_TOP_RIGHT],
50
+ [TOP_LEFT, nil, TOP_RIGHT],
51
+ [CORNER_MIDDLE_LEFT, MIDDLE, CORNER_MIDDLE_RIGHT],
52
+ [BOTTOM_LEFT, nil, BOTTOM_RIGHT],
53
+ [CORNER_BOTTOM_LEFT, BOTTOM, CORNER_BOTTOM_RIGHT]]
54
+ lines.map { |each| line(BITMAPS[number.to_i], each) }
55
+ end
56
+
57
+ # @todo This method smells of :reek:UtilityFunction
58
+ # @todo This method smells of :reek:FeatureEnvy
59
+ def line(bitmap, bits)
60
+ bits.map do |each|
61
+ if each
62
+ (bitmap & 1 << each).zero? ? ' ' : '*'
63
+ else
64
+ ' '
65
+ end
66
+ end.join
67
+ end
68
+ end
69
+ end
70
+ end
@@ -2,21 +2,22 @@
2
2
 
3
3
  require 'curses'
4
4
  require 'text2048/curses_view/colorize'
5
+ require 'text2048/curses_view/lcd'
5
6
 
6
7
  # This module smells of :reek:UncommunicativeModuleName
7
8
  module Text2048
8
9
  class CursesView
9
10
  # Shows tiles in curses.
11
+ # rubocop:disable ClassLength
10
12
  class Tile
11
13
  attr_reader :width
12
14
  attr_reader :height
13
15
  attr_reader :color
14
16
 
15
- include Curses
16
17
  include Colorize
17
18
 
18
- DEFAULT_HEIGHT = 3
19
- DEFAULT_WIDTH = 5
19
+ DEFAULT_HEIGHT = 7
20
+ DEFAULT_WIDTH = 17
20
21
 
21
22
  def self.width(scale)
22
23
  @width = (DEFAULT_WIDTH * scale).to_i
@@ -34,6 +35,7 @@ module Text2048
34
35
  @row = (@height + 1) * row + 2
35
36
  @col = (@width + 1) * col + 1
36
37
  @color = color
38
+ @scale = scale
37
39
  end
38
40
 
39
41
  def show
@@ -69,14 +71,40 @@ module Text2048
69
71
 
70
72
  def draw_number
71
73
  return if @value == 0
72
- setpos(@row + @height / 2, @col)
73
- colorize(@color) do
74
- addstr @value.to_s.center(@width)
74
+ if @scale >= 1
75
+ draw_lcd_number
76
+ else
77
+ setpos(@row + @height / 2, @col)
78
+ colorize(@color) do
79
+ addstr @value.to_s.center(@width)
80
+ end
75
81
  end
76
82
  end
77
83
 
78
84
  private
79
85
 
86
+ def draw_lcd_number
87
+ num_lcd = LCD.new(@value).render
88
+ num_lcd.split("\n").each_with_index do |each, index|
89
+ draw_lcd_line(each, @row + index + (@height - 5) / 2)
90
+ end
91
+ end
92
+
93
+ def col_padded
94
+ num_length = @value.to_s.length
95
+ @col + (@width - num_length * 4 + 1) / 2
96
+ end
97
+
98
+ # @todo This method smells of :reek:NestedIterators
99
+ # @todo This method smells of :reek:TooManyStatements
100
+ def draw_lcd_line(line, row)
101
+ line.split(//).each_with_index do |each, index|
102
+ setpos(row, col_padded + index)
103
+ color = each == '*' ? COLOR_BLACK + 100 : @color
104
+ colorize(color) { addstr each }
105
+ end
106
+ end
107
+
80
108
  def box_upper_left
81
109
  [@row - 1, @col - 1]
82
110
  end
@@ -131,5 +159,6 @@ module Text2048
131
159
  end
132
160
  end
133
161
  end
162
+ # rubocop:enable ClassLength
134
163
  end
135
164
  end
@@ -3,5 +3,5 @@
3
3
  # This module smells of :reek:UncommunicativeModuleName
4
4
  module Text2048
5
5
  # gem version.
6
- VERSION = '0.7.0'.freeze
6
+ VERSION = '0.8.0'.freeze
7
7
  end
@@ -0,0 +1,225 @@
1
+ # encoding: utf-8
2
+
3
+ require 'text2048'
4
+
5
+ describe Text2048::CursesView::LCD do
6
+ describe '#render' do
7
+ Given(:result) { Text2048::CursesView::LCD.new(number).render }
8
+
9
+ context 'with 0' do
10
+ When(:number) { 0 }
11
+ Then do
12
+ result ==
13
+ "***\n"\
14
+ "* *\n"\
15
+ "* *\n"\
16
+ "* *\n"\
17
+ '***'
18
+ end
19
+ end
20
+
21
+ context 'with 1' do
22
+ When(:number) { 1 }
23
+ Then do
24
+ result ==
25
+ " *\n"\
26
+ " *\n"\
27
+ " *\n"\
28
+ " *\n"\
29
+ ' *'
30
+ end
31
+ end
32
+
33
+ context 'with 2' do
34
+ When(:number) { 2 }
35
+ Then do
36
+ result ==
37
+ "***\n"\
38
+ " *\n"\
39
+ "***\n"\
40
+ "* \n"\
41
+ '***'
42
+ end
43
+ end
44
+
45
+ context 'with 3' do
46
+ When(:number) { 3 }
47
+ Then do
48
+ result ==
49
+ "***\n"\
50
+ " *\n"\
51
+ "***\n"\
52
+ " *\n"\
53
+ '***'
54
+ end
55
+ end
56
+
57
+ context 'with 4' do
58
+ When(:number) { 4 }
59
+ Then do
60
+ result ==
61
+ "* *\n"\
62
+ "* *\n"\
63
+ "***\n"\
64
+ " *\n"\
65
+ ' *'
66
+ end
67
+ end
68
+
69
+ context 'with 5' do
70
+ When(:number) { 5 }
71
+ Then do
72
+ result ==
73
+ "***\n"\
74
+ "* \n"\
75
+ "***\n"\
76
+ " *\n"\
77
+ '***'
78
+ end
79
+ end
80
+
81
+ context 'with 6' do
82
+ When(:number) { 6 }
83
+ Then do
84
+ result ==
85
+ "***\n"\
86
+ "* \n"\
87
+ "***\n"\
88
+ "* *\n"\
89
+ '***'
90
+ end
91
+ end
92
+
93
+ context 'with 7' do
94
+ When(:number) { 7 }
95
+ Then do
96
+ result ==
97
+ "***\n"\
98
+ " *\n"\
99
+ " *\n"\
100
+ " *\n"\
101
+ ' *'
102
+ end
103
+ end
104
+
105
+ context 'with 8' do
106
+ When(:number) { 8 }
107
+ Then do
108
+ result ==
109
+ "***\n"\
110
+ "* *\n"\
111
+ "***\n"\
112
+ "* *\n"\
113
+ '***'
114
+ end
115
+ end
116
+
117
+ context 'with 9' do
118
+ When(:number) { 9 }
119
+ Then do
120
+ result ==
121
+ "***\n"\
122
+ "* *\n"\
123
+ "***\n"\
124
+ " *\n"\
125
+ '***'
126
+ end
127
+ end
128
+
129
+ context 'with 16' do
130
+ When(:number) { 16 }
131
+ Then do
132
+ result ==
133
+ " * ***\n"\
134
+ " * * \n"\
135
+ " * ***\n"\
136
+ " * * *\n"\
137
+ ' * ***'
138
+ end
139
+ end
140
+
141
+ context 'with 32' do
142
+ When(:number) { 32 }
143
+ Then do
144
+ result ==
145
+ "*** ***\n"\
146
+ " * *\n"\
147
+ "*** ***\n"\
148
+ " * * \n"\
149
+ '*** ***'
150
+ end
151
+ end
152
+
153
+ context 'with 64' do
154
+ When(:number) { 64 }
155
+ Then do
156
+ result ==
157
+ "*** * *\n"\
158
+ "* * *\n"\
159
+ "*** ***\n"\
160
+ "* * *\n"\
161
+ '*** *'
162
+ end
163
+ end
164
+
165
+ context 'with 128' do
166
+ When(:number) { 128 }
167
+ Then do
168
+ result ==
169
+ " * *** ***\n"\
170
+ " * * * *\n"\
171
+ " * *** ***\n"\
172
+ " * * * *\n"\
173
+ ' * *** ***'
174
+ end
175
+ end
176
+
177
+ context 'with 256' do
178
+ When(:number) { 256 }
179
+ Then do
180
+ result ==
181
+ "*** *** ***\n"\
182
+ " * * * \n"\
183
+ "*** *** ***\n"\
184
+ "* * * *\n"\
185
+ '*** *** ***'
186
+ end
187
+ end
188
+
189
+ context 'with 512' do
190
+ When(:number) { 512 }
191
+ Then do
192
+ result ==
193
+ "*** * ***\n"\
194
+ "* * *\n"\
195
+ "*** * ***\n"\
196
+ " * * * \n"\
197
+ '*** * ***'
198
+ end
199
+ end
200
+
201
+ context 'with 1024' do
202
+ When(:number) { 1024 }
203
+ Then do
204
+ result ==
205
+ " * *** *** * *\n"\
206
+ " * * * * * *\n"\
207
+ " * * * *** ***\n"\
208
+ " * * * * *\n"\
209
+ ' * *** *** *'
210
+ end
211
+ end
212
+
213
+ context 'with 2048' do
214
+ When(:number) { 2048 }
215
+ Then do
216
+ result ==
217
+ "*** *** * * ***\n"\
218
+ " * * * * * * *\n"\
219
+ "*** * * *** ***\n"\
220
+ "* * * * * *\n"\
221
+ '*** *** * ***'
222
+ end
223
+ end
224
+ end
225
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text2048
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuhito Takamiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-13 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,6 +53,7 @@ files:
53
53
  - lib/text2048/curses_view.rb
54
54
  - lib/text2048/curses_view/colorize.rb
55
55
  - lib/text2048/curses_view/keyboard.rb
56
+ - lib/text2048/curses_view/lcd.rb
56
57
  - lib/text2048/curses_view/tile.rb
57
58
  - lib/text2048/curses_view/tile_effects.rb
58
59
  - lib/text2048/monkey_patch/array.rb
@@ -67,6 +68,7 @@ files:
67
68
  - spec/spec_helper.rb
68
69
  - spec/text2048/app_spec.rb
69
70
  - spec/text2048/board_spec.rb
71
+ - spec/text2048/curses_view/lcd_spec.rb
70
72
  - text2048.gemspec
71
73
  homepage: http://github.com/yasuhito/text2048
72
74
  licenses:
@@ -97,6 +99,7 @@ test_files:
97
99
  - spec/spec_helper.rb
98
100
  - spec/text2048/app_spec.rb
99
101
  - spec/text2048/board_spec.rb
102
+ - spec/text2048/curses_view/lcd_spec.rb
100
103
  - features/game_over.feature
101
104
  - features/move_down.feature
102
105
  - features/move_left.feature