text2048 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +55 -1
- data/bin/2048 +3 -1
- data/lib/text2048/app.rb +18 -34
- data/lib/text2048/board.rb +93 -50
- data/lib/text2048/curses_view.rb +23 -59
- data/lib/text2048/curses_view/colorize.rb +53 -0
- data/lib/text2048/curses_view/keyboard.rb +35 -0
- data/lib/text2048/curses_view/tile.rb +135 -0
- data/lib/text2048/curses_view/tile_effects.rb +35 -0
- data/lib/text2048/monkey_patch/array/tile.rb +1 -1
- data/lib/text2048/monkey_patch/hash.rb +8 -0
- data/lib/text2048/monkey_patch/hash/converter.rb +17 -0
- data/lib/text2048/version.rb +1 -1
- data/spec/array_spec.rb +24 -24
- data/spec/spec_helper.rb +3 -0
- data/spec/text2048/app_spec.rb +106 -0
- data/spec/text2048/board_spec.rb +332 -51
- metadata +11 -3
- data/lib/text2048/curses_tile.rb +0 -125
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.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -50,16 +50,22 @@ files:
|
|
50
50
|
- lib/text2048.rb
|
51
51
|
- lib/text2048/app.rb
|
52
52
|
- lib/text2048/board.rb
|
53
|
-
- lib/text2048/curses_tile.rb
|
54
53
|
- lib/text2048/curses_view.rb
|
54
|
+
- lib/text2048/curses_view/colorize.rb
|
55
|
+
- lib/text2048/curses_view/keyboard.rb
|
56
|
+
- lib/text2048/curses_view/tile.rb
|
57
|
+
- lib/text2048/curses_view/tile_effects.rb
|
55
58
|
- lib/text2048/monkey_patch/array.rb
|
56
59
|
- lib/text2048/monkey_patch/array/board.rb
|
57
60
|
- lib/text2048/monkey_patch/array/tile.rb
|
61
|
+
- lib/text2048/monkey_patch/hash.rb
|
62
|
+
- lib/text2048/monkey_patch/hash/converter.rb
|
58
63
|
- lib/text2048/text_view.rb
|
59
64
|
- lib/text2048/tile.rb
|
60
65
|
- lib/text2048/version.rb
|
61
66
|
- spec/array_spec.rb
|
62
67
|
- spec/spec_helper.rb
|
68
|
+
- spec/text2048/app_spec.rb
|
63
69
|
- spec/text2048/board_spec.rb
|
64
70
|
- text2048.gemspec
|
65
71
|
homepage: http://github.com/yasuhito/text2048
|
@@ -89,6 +95,7 @@ summary: Text mode 2048 game.
|
|
89
95
|
test_files:
|
90
96
|
- spec/array_spec.rb
|
91
97
|
- spec/spec_helper.rb
|
98
|
+
- spec/text2048/app_spec.rb
|
92
99
|
- spec/text2048/board_spec.rb
|
93
100
|
- features/game_over.feature
|
94
101
|
- features/move_down.feature
|
@@ -97,3 +104,4 @@ test_files:
|
|
97
104
|
- features/move_up.feature
|
98
105
|
- features/step_definitions/2048_steps.rb
|
99
106
|
- features/support/env.rb
|
107
|
+
has_rdoc:
|
data/lib/text2048/curses_tile.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'curses'
|
4
|
-
|
5
|
-
# This module smells of :reek:UncommunicativeModuleName
|
6
|
-
module Text2048
|
7
|
-
# Shows tiles in curses.
|
8
|
-
class CursesTile
|
9
|
-
attr_reader :width
|
10
|
-
attr_reader :height
|
11
|
-
attr_reader :color
|
12
|
-
|
13
|
-
include Curses
|
14
|
-
|
15
|
-
DEFAULT_HEIGHT = 3
|
16
|
-
DEFAULT_WIDTH = 5
|
17
|
-
|
18
|
-
def self.width(scale)
|
19
|
-
@width = (DEFAULT_WIDTH * scale).to_i
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.height(scale)
|
23
|
-
(DEFAULT_HEIGHT * scale).to_i
|
24
|
-
end
|
25
|
-
|
26
|
-
def initialize(value, row, col, color, scale = 1)
|
27
|
-
klass = self.class
|
28
|
-
@value = value.to_i
|
29
|
-
@height = klass.height(scale)
|
30
|
-
@box_height = @height + 2
|
31
|
-
@width = klass.width(scale)
|
32
|
-
@box_width = @width + 2
|
33
|
-
@row = (@height + 1) * row + 2
|
34
|
-
@col = (@width + 1) * col + 1
|
35
|
-
@color = color
|
36
|
-
end
|
37
|
-
|
38
|
-
def show
|
39
|
-
draw_box
|
40
|
-
fill_tile_color
|
41
|
-
draw_number
|
42
|
-
self
|
43
|
-
end
|
44
|
-
|
45
|
-
def pop
|
46
|
-
attron(color_pair(@color + 100)) do
|
47
|
-
draw_box
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def draw_box
|
52
|
-
draw_square
|
53
|
-
[box_upper_left, box_upper_right,
|
54
|
-
box_lower_left, box_lower_right].each do |row, col|
|
55
|
-
setpos(row, col)
|
56
|
-
addstr('+')
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def fill_tile_color
|
61
|
-
attron(color_pair(@color + 100)) { fill }
|
62
|
-
end
|
63
|
-
|
64
|
-
def fill_black
|
65
|
-
attron(color_pair(COLOR_BLACK + 100)) { fill }
|
66
|
-
refresh
|
67
|
-
end
|
68
|
-
|
69
|
-
def draw_number
|
70
|
-
return if @value == 0
|
71
|
-
setpos(@row + @height / 2, @col)
|
72
|
-
attron(color_pair(@color)) do
|
73
|
-
addstr @value.to_s.center(@width)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def box_upper_left
|
80
|
-
[@row - 1, @col - 1]
|
81
|
-
end
|
82
|
-
|
83
|
-
def box_upper_right
|
84
|
-
[@row - 1, @col + @width]
|
85
|
-
end
|
86
|
-
|
87
|
-
def box_lower_left
|
88
|
-
[@row + @height, @col - 1]
|
89
|
-
end
|
90
|
-
|
91
|
-
def box_lower_right
|
92
|
-
[@row + @height, @col + @width]
|
93
|
-
end
|
94
|
-
|
95
|
-
def draw_square
|
96
|
-
draw_horizonal_line(*box_upper_left, @box_width)
|
97
|
-
draw_vertical_line(*box_upper_left, @box_height)
|
98
|
-
draw_vertical_line(*box_upper_right, @box_height)
|
99
|
-
draw_horizonal_line(*box_lower_left, @box_width)
|
100
|
-
end
|
101
|
-
|
102
|
-
def draw_horizonal_line(row, col, length)
|
103
|
-
setpos(row, col)
|
104
|
-
addstr('-' * length)
|
105
|
-
end
|
106
|
-
|
107
|
-
def draw_vertical_line(row, col, length)
|
108
|
-
(0..(length - 1)).each do |each|
|
109
|
-
setpos(row + each, col)
|
110
|
-
addstr('|')
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def fill
|
115
|
-
(0..(@height - 1)).each do |each|
|
116
|
-
setpos(@row + each, @col)
|
117
|
-
if @value != 0 && each == @height / 2
|
118
|
-
addstr @value.to_s.center(@width)
|
119
|
-
else
|
120
|
-
addstr('.' * @width)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|