rdgc-dm 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +22 -0
- data/README.rdoc +148 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/rdgc/maker/divide_dungeon_maker.rb +371 -0
- data/lib/rdgc/maker/divide_temp_block.rb +269 -0
- data/lib/rdgc/maker/dungeon_maker.rb +57 -0
- data/lib/rdgc/maker/temp_block.rb +23 -0
- data/lib/rdgc/map/area.rb +103 -0
- data/lib/rdgc/map/block.rb +155 -0
- data/lib/rdgc/map/board.rb +81 -0
- data/lib/rdgc/map/road.rb +18 -0
- data/lib/rdgc/map/room.rb +69 -0
- data/lib/rdgc/map/tile.rb +35 -0
- data/lib/rdgc/map/tile_type.rb +11 -0
- data/lib/rdgc/util/config.rb +74 -0
- data/lib/rdgc/util/random_util.rb +104 -0
- data/lib/rdgc-dm.rb +17 -0
- data/rdgc-dm.gemspec +93 -0
- data/spec/rdgc/maker/01_temp_block_spec.rb +45 -0
- data/spec/rdgc/maker/02_divide_temp_block_spec.rb +241 -0
- data/spec/rdgc/maker/03_divide_dungeon_maker_divide_spec.rb +224 -0
- data/spec/rdgc/maker/04_divide_dungeon_maker_create_spec.rb +244 -0
- data/spec/rdgc/map/01_tile_spec.rb +56 -0
- data/spec/rdgc/map/02_area_spec.rb +118 -0
- data/spec/rdgc/map/03_road_spec.rb +23 -0
- data/spec/rdgc/map/04_room_spec.rb +190 -0
- data/spec/rdgc/map/05_block_spec.rb +273 -0
- data/spec/rdgc/map/06_board_spec.rb +132 -0
- data/spec/rdgc/util/01_config_spec.rb +44 -0
- data/spec/rdgc/util/02_random_util_spec.rb +153 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +11 -0
- metadata +124 -0
@@ -0,0 +1,224 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
|
3
|
+
|
4
|
+
include RDGC::Map
|
5
|
+
include RDGC::Maker
|
6
|
+
|
7
|
+
describe RDGC::Maker::DivideDungeonMaker, 'is divide block by recursive' do
|
8
|
+
|
9
|
+
describe "each acceptable params" do
|
10
|
+
|
11
|
+
it "min_room_size, max_room_size" do
|
12
|
+
maker = DivideDungeonMaker.new
|
13
|
+
maker.min_room_size.should be_nil
|
14
|
+
maker.max_room_size.should be_nil
|
15
|
+
|
16
|
+
maker.params[:min_room_size] = 5
|
17
|
+
maker.params[:max_room_size] = 20
|
18
|
+
|
19
|
+
maker.min_room_size.should == 5
|
20
|
+
maker.max_room_size.should == 20
|
21
|
+
end
|
22
|
+
|
23
|
+
it "min_block_size" do
|
24
|
+
# デフォルト
|
25
|
+
maker = DivideDungeonMaker.new
|
26
|
+
maker.min_block_size.should == Util::Config.min_block_size
|
27
|
+
|
28
|
+
# デフォルトより小さいとデフォルト
|
29
|
+
maker = DivideDungeonMaker.new
|
30
|
+
maker.params[:min_block_size] = 1
|
31
|
+
maker.min_block_size.should == Util::Config.min_block_size
|
32
|
+
|
33
|
+
maker = DivideDungeonMaker.new
|
34
|
+
maker.params[:min_block_size] = 10
|
35
|
+
maker.min_block_size.should == 10
|
36
|
+
|
37
|
+
# 一度読むと書き換えできない
|
38
|
+
maker.params[:min_block_size] = 20
|
39
|
+
maker.min_block_size.should == 10
|
40
|
+
|
41
|
+
# min_room_sizeが存在し、min_block_sizeが存在しない場合、影響を受ける
|
42
|
+
maker = DivideDungeonMaker.new
|
43
|
+
maker.params[:min_room_size] = 5
|
44
|
+
maker.min_block_size.should == 8
|
45
|
+
end
|
46
|
+
|
47
|
+
it "min_room_count" do
|
48
|
+
# デフォルトは2
|
49
|
+
maker = DivideDungeonMaker.new
|
50
|
+
maker.min_room_count.should == 2
|
51
|
+
|
52
|
+
# 値は一度だけセットできる
|
53
|
+
maker = DivideDungeonMaker.new
|
54
|
+
maker.params[:min_room_count] = 3
|
55
|
+
maker.min_room_count.should == 3
|
56
|
+
maker.params[:min_room_count] = 5
|
57
|
+
maker.min_room_count.should == 3
|
58
|
+
|
59
|
+
# 明示的に1を指定すると1
|
60
|
+
maker = DivideDungeonMaker.new
|
61
|
+
maker.params[:min_room_count] = 1
|
62
|
+
maker.min_room_count.should == 1
|
63
|
+
|
64
|
+
# 0以下ならデフォルト
|
65
|
+
maker = DivideDungeonMaker.new
|
66
|
+
maker.params[:min_room_count] = 0
|
67
|
+
maker.min_room_count.should == 2
|
68
|
+
end
|
69
|
+
|
70
|
+
it "max_room_count" do
|
71
|
+
maker = DivideDungeonMaker.new
|
72
|
+
maker.max_room_count.should == 0
|
73
|
+
|
74
|
+
maker.params[:max_room_count] = 8
|
75
|
+
maker.max_room_count.should == 8
|
76
|
+
end
|
77
|
+
|
78
|
+
it "max_depth" do
|
79
|
+
maker = DivideDungeonMaker.new
|
80
|
+
maker.max_depth.should == 0
|
81
|
+
|
82
|
+
maker.params[:max_depth] = 3
|
83
|
+
maker.max_depth.should == 3
|
84
|
+
end
|
85
|
+
|
86
|
+
it "cross_road_ratio" do
|
87
|
+
# デフォルトは2
|
88
|
+
maker = DivideDungeonMaker.new
|
89
|
+
maker.cross_road_ratio.should == DivideDungeonMaker::DEFAULT_CROSS_ROAD_RATIO
|
90
|
+
|
91
|
+
# 値は一度だけセットできる
|
92
|
+
maker = DivideDungeonMaker.new
|
93
|
+
maker.params[:cross_road_ratio] = 3
|
94
|
+
maker.cross_road_ratio.should == 3
|
95
|
+
maker.params[:cross_road_ratio] = 5
|
96
|
+
maker.cross_road_ratio.should == 3
|
97
|
+
|
98
|
+
# 0未満ならデフォルト
|
99
|
+
maker = DivideDungeonMaker.new
|
100
|
+
maker.params[:cross_road_ratio] = -1
|
101
|
+
maker.cross_road_ratio.should == 2
|
102
|
+
|
103
|
+
# 0はセット可能
|
104
|
+
maker = DivideDungeonMaker.new
|
105
|
+
maker.params[:cross_road_ratio] = 0
|
106
|
+
maker.cross_road_ratio.should == 0
|
107
|
+
|
108
|
+
# 9を超えるならデフォルト
|
109
|
+
maker = DivideDungeonMaker.new
|
110
|
+
maker.params[:cross_road_ratio] = 10
|
111
|
+
maker.cross_road_ratio.should == 2
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "divide whole_block" do
|
117
|
+
|
118
|
+
it "divide_queue store dividable block, and done_queue store divided block" do
|
119
|
+
maker = DivideDungeonMaker.new
|
120
|
+
maker.queue_size.should == 0
|
121
|
+
|
122
|
+
maker.divide_queue << DivideTempBlock.create_whole_block(20, 20)
|
123
|
+
maker.divide_queue.size.should == 1
|
124
|
+
maker.queue_size.should == 1
|
125
|
+
|
126
|
+
maker.done_queue << DivideTempBlock.create_whole_block(20, 20)
|
127
|
+
maker.done_queue.size.should == 1
|
128
|
+
maker.queue_size.should == 2
|
129
|
+
end
|
130
|
+
|
131
|
+
it "#finish? will check divide end" do
|
132
|
+
maker = DivideDungeonMaker.new
|
133
|
+
maker.finish?.should be_true
|
134
|
+
|
135
|
+
maker.done_queue << DivideTempBlock.create_whole_block(20, 20)
|
136
|
+
maker.finish?.should be_true
|
137
|
+
|
138
|
+
maker.divide_queue << DivideTempBlock.create_whole_block(20, 20)
|
139
|
+
maker.finish?.should be_false
|
140
|
+
|
141
|
+
maker.params[:max_block_count] = 3
|
142
|
+
maker.finish?.should be_false
|
143
|
+
|
144
|
+
maker.done_queue << DivideTempBlock.create_whole_block(20, 20)
|
145
|
+
maker.finish?.should be_true
|
146
|
+
end
|
147
|
+
|
148
|
+
it "#dividable_block? check block dividable" do
|
149
|
+
# max_depthの指定がない場合
|
150
|
+
maker = DivideDungeonMaker.new
|
151
|
+
b = DivideTempBlock.create_whole_block(20, 20)
|
152
|
+
|
153
|
+
maker.dividable_block?(b).should be_false
|
154
|
+
b.dividable
|
155
|
+
maker.dividable_block?(b).should be_true
|
156
|
+
|
157
|
+
# max_depthが指定されている場合
|
158
|
+
maker = DivideDungeonMaker.new
|
159
|
+
maker.params[:max_depth] = 3
|
160
|
+
b = DivideTempBlock.create_whole_block(20, 20)
|
161
|
+
|
162
|
+
b.dividable
|
163
|
+
maker.dividable_block?(b).should be_true
|
164
|
+
b.depth = 3
|
165
|
+
maker.dividable_block?(b).should be_false
|
166
|
+
end
|
167
|
+
|
168
|
+
it "create_whole_block" do
|
169
|
+
maker = DivideDungeonMaker.new
|
170
|
+
tb = maker.create_whole_block(30, 40)
|
171
|
+
tb.should be_an_instance_of(DivideTempBlock)
|
172
|
+
tb.width.should == 30
|
173
|
+
tb.height.should == 40
|
174
|
+
tb.min_size.should == Util::Config.min_block_size
|
175
|
+
tb.dividable?.should be_true
|
176
|
+
end
|
177
|
+
|
178
|
+
it "divide block" do
|
179
|
+
each_create_block do |b|
|
180
|
+
b.should be_an_instance_of(DivideTempBlock)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
it "min_block_size/max_block_count/max_depth affect divide as possible" do
|
185
|
+
10.times do
|
186
|
+
each_create_block(:min_block_size, 6) do |b|
|
187
|
+
b.should be_an_instance_of(DivideTempBlock)
|
188
|
+
b.width.should >= 6
|
189
|
+
b.height.should >= 6
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
10.times do
|
194
|
+
count = 0
|
195
|
+
each_create_block(:max_block_count, 5) do |b|
|
196
|
+
b.should be_an_instance_of(DivideTempBlock)
|
197
|
+
count += 0
|
198
|
+
end
|
199
|
+
count.should <= 5
|
200
|
+
end
|
201
|
+
|
202
|
+
10.times do
|
203
|
+
count = 0
|
204
|
+
each_create_block(:max_depth, 3) do |b|
|
205
|
+
b.should be_an_instance_of(DivideTempBlock)
|
206
|
+
b.depth <= 3
|
207
|
+
count += 1
|
208
|
+
end
|
209
|
+
count.should <= 8
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def each_create_block(name = nil, val = nil)
|
214
|
+
maker = DivideDungeonMaker.new
|
215
|
+
maker.params[name] = val if name && val
|
216
|
+
tb = maker.create_whole_block(40, 40)
|
217
|
+
bl = maker.make_blocks(tb)
|
218
|
+
|
219
|
+
bl.each{|b| yield(b)}
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
|
3
|
+
|
4
|
+
include RDGC::Map
|
5
|
+
include RDGC::Maker
|
6
|
+
|
7
|
+
describe RDGC::Maker::DivideDungeonMaker, 'create room/road for each block' do
|
8
|
+
|
9
|
+
describe "create room" do
|
10
|
+
|
11
|
+
it "create_room by default" do
|
12
|
+
10.times do
|
13
|
+
maker = create_maker_with_blocks
|
14
|
+
maker.create_room
|
15
|
+
|
16
|
+
maker.blocks.each do |b|
|
17
|
+
rsl_room = b.has_room?
|
18
|
+
rsl_cross = b.has_cross_point?
|
19
|
+
(rsl_room || rsl_cross).should be_true
|
20
|
+
(rsl_room && rsl_cross).should be_false
|
21
|
+
end
|
22
|
+
|
23
|
+
maker.blocks.select{|b| b.has_room?}.size.should >= 2
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "min_room_size/max_room_size affect room size" do
|
28
|
+
val = 5
|
29
|
+
|
30
|
+
10.times do
|
31
|
+
maker = create_maker_with_blocks(:min_room_size => val)
|
32
|
+
maker.create_room
|
33
|
+
|
34
|
+
maker.blocks.select{|b| b.has_room?}.map{|b| b.room}.each do |r|
|
35
|
+
r.width.should >= val
|
36
|
+
r.height.should >= val
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
10.times do
|
41
|
+
maker = create_maker_with_blocks(:max_room_size => val)
|
42
|
+
maker.create_room
|
43
|
+
|
44
|
+
maker.blocks.select{|b| b.has_room?}.map{|b| b.room}.each do |r|
|
45
|
+
r.width.should <= val
|
46
|
+
r.height.should <= val
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "min_room_count/max_room_count affect room count" do
|
52
|
+
10.times do
|
53
|
+
maker = create_maker_with_blocks(:min_room_count => 3)
|
54
|
+
maker.create_room
|
55
|
+
maker.blocks.select{|b| b.has_room?}.size.should >= 3
|
56
|
+
end
|
57
|
+
|
58
|
+
10.times do
|
59
|
+
maker = create_maker_with_blocks(:max_room_count => 3)
|
60
|
+
maker.create_room
|
61
|
+
maker.blocks.select{|b| b.has_room?}.size.should <= 3
|
62
|
+
end
|
63
|
+
|
64
|
+
10.times do
|
65
|
+
maker = create_maker_with_blocks(:min_room_count => 1, :max_room_count => 1)
|
66
|
+
maker.create_room
|
67
|
+
maker.blocks.select{|b| b.has_room?}.size.should == 1
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
it "cross_road_ratio affect room create" do
|
73
|
+
10.times do
|
74
|
+
maker = create_maker_with_blocks(:cross_road_ratio => 9)
|
75
|
+
maker.create_room
|
76
|
+
|
77
|
+
all_size = maker.blocks.size
|
78
|
+
maker.blocks.select{|b| b.has_room?}.size.should >= 2
|
79
|
+
maker.blocks.select{|b| b.has_cross_point?}.size.should <= all_size - 2
|
80
|
+
end
|
81
|
+
|
82
|
+
10.times do
|
83
|
+
maker = create_maker_with_blocks(:cross_road_ratio => 0)
|
84
|
+
maker.create_room
|
85
|
+
|
86
|
+
all_size = maker.blocks.size
|
87
|
+
maker.blocks.select{|b| b.has_room?}.size.should == all_size
|
88
|
+
maker.blocks.select{|b| b.has_cross_point?}.size.should == 0
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "create road" do
|
95
|
+
|
96
|
+
it "room block should has roads, if min_room_count too big" do
|
97
|
+
10.times do
|
98
|
+
maker = create_maker_with_blocks(:min_room_count => 99)
|
99
|
+
maker.create_room
|
100
|
+
maker.create_road
|
101
|
+
|
102
|
+
maker.blocks.select{|b| b.has_room?}.each do |b|
|
103
|
+
b.has_road?.should be_true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "no create road if only one block" do
|
109
|
+
maker = create_maker_with_blocks(:min_block_size => 99)
|
110
|
+
maker.create_room
|
111
|
+
maker.blocks.size.should == 1
|
112
|
+
|
113
|
+
maker.create_road
|
114
|
+
maker.blocks.select{|b| b.has_road?}.should be_empty
|
115
|
+
end
|
116
|
+
|
117
|
+
it "#move_room_and_connect spec" do
|
118
|
+
|
119
|
+
b1 = DivideTempBlock.create(0, 10, 0, 10)
|
120
|
+
b2 = DivideTempBlock.create(0, 10, 11, 20)
|
121
|
+
b3 = DivideTempBlock.create(0, 10, 21, 30)
|
122
|
+
b4 = DivideTempBlock.create(0, 10, 31, 40)
|
123
|
+
|
124
|
+
b1.create_room
|
125
|
+
b2.create_room
|
126
|
+
b4.create_room
|
127
|
+
b1.create_road_to(b2)
|
128
|
+
b2.add_remain_cling_blocks(b3)
|
129
|
+
|
130
|
+
maker = DivideDungeonMaker.new
|
131
|
+
maker.instance_eval do
|
132
|
+
@params = {:min_room_count => 10}
|
133
|
+
@blocks = [b1, b2, b3, b4]
|
134
|
+
end
|
135
|
+
|
136
|
+
maker.move_room_and_connect
|
137
|
+
|
138
|
+
b3.has_room?.should be_true
|
139
|
+
b3.has_road?.should be_true
|
140
|
+
b4.has_room?.should be_false
|
141
|
+
b4.has_road?.should be_false
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "make all" do
|
147
|
+
|
148
|
+
it "create provide complete board" do
|
149
|
+
board = DivideDungeonMaker.create(40, 40)
|
150
|
+
board.should be_an_instance_of(Map::Board)
|
151
|
+
board.blocks.select{|b| b.has_room?}.each do |b|
|
152
|
+
b.should be_an_instance_of(Block)
|
153
|
+
b.should_not be_an_instance_of(DivideTempBlock)
|
154
|
+
b.has_road?.should be_true
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
it "create accept params" do
|
159
|
+
params = {}
|
160
|
+
params[:min_room_size] = 5
|
161
|
+
params[:max_room_size] = 10
|
162
|
+
params[:min_block_size] = 8
|
163
|
+
params[:min_room_count] = 3
|
164
|
+
params[:max_room_count] = 8
|
165
|
+
params[:max_depth] = 4
|
166
|
+
params[:cross_road_ratio] = 4
|
167
|
+
|
168
|
+
10.times do
|
169
|
+
board = DivideDungeonMaker.create(80, 80, params)
|
170
|
+
board.should be_an_instance_of(Map::Board)
|
171
|
+
|
172
|
+
board.blocks.size.should <= 16 # depth
|
173
|
+
|
174
|
+
room_count = 0
|
175
|
+
board.blocks.each do |b|
|
176
|
+
b.should be_an_instance_of(Block)
|
177
|
+
b.should_not be_an_instance_of(DivideTempBlock)
|
178
|
+
|
179
|
+
b.width.should >= params[:min_block_size]
|
180
|
+
b.height.should >= params[:min_block_size]
|
181
|
+
|
182
|
+
next unless b.has_room?
|
183
|
+
room = b.room
|
184
|
+
|
185
|
+
room.width.should >= params[:min_room_size]
|
186
|
+
room.width.should <= params[:max_room_size]
|
187
|
+
room.height.should >= params[:min_room_size]
|
188
|
+
room.height.should <= params[:max_room_size]
|
189
|
+
|
190
|
+
room_count += 1
|
191
|
+
end
|
192
|
+
room_count.should >= params[:min_room_count]
|
193
|
+
room_count.should <= params[:max_room_count]
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
it "only one block board" do
|
198
|
+
params = {}
|
199
|
+
params[:min_room_count] = 1
|
200
|
+
params[:max_room_count] = 1
|
201
|
+
params[:min_block_size] = 99
|
202
|
+
|
203
|
+
10.times do
|
204
|
+
board = DivideDungeonMaker.create(40, 40, params)
|
205
|
+
board.should be_an_instance_of(Map::Board)
|
206
|
+
|
207
|
+
board.blocks.size.should == 1
|
208
|
+
board.blocks.map(&:room).size.should == 1
|
209
|
+
board.blocks.inject([]){|l, b| l + b.roads}.should be_empty
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
it "only room board" do
|
214
|
+
10.times do
|
215
|
+
board = DivideDungeonMaker.create(40, 40, :cross_road_ratio => 0)
|
216
|
+
board.should be_an_instance_of(Map::Board)
|
217
|
+
|
218
|
+
board.blocks.each do |b|
|
219
|
+
b.has_room?.should be_true
|
220
|
+
b.has_road?.should be_true
|
221
|
+
b.has_cross_point?.should be_false
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
def create_maker_with_blocks(params = nil)
|
229
|
+
maker = DivideDungeonMaker.new
|
230
|
+
maker.instance_eval do
|
231
|
+
@params = params
|
232
|
+
end
|
233
|
+
|
234
|
+
tb = maker.create_whole_block(40, 40)
|
235
|
+
bl = maker.make_blocks(tb)
|
236
|
+
|
237
|
+
bl.each do |b|
|
238
|
+
maker.blocks << b
|
239
|
+
end
|
240
|
+
|
241
|
+
maker
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
|
3
|
+
|
4
|
+
include RDGC::Map
|
5
|
+
|
6
|
+
describe RDGC::Map::Tile do
|
7
|
+
|
8
|
+
it "created for :out" do
|
9
|
+
t = Tile.new(:out)
|
10
|
+
t.out?.should be_true
|
11
|
+
t.movable?.should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "created for :wall" do
|
15
|
+
t = Tile.new(:wall)
|
16
|
+
t.wall?.should be_true
|
17
|
+
t.movable?.should be_false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "created for :room" do
|
21
|
+
t = Tile.new(:room)
|
22
|
+
t.room?.should be_true
|
23
|
+
t.movable?.should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "created for :road" do
|
27
|
+
t = Tile.new(:road)
|
28
|
+
t.road?.should be_true
|
29
|
+
t.movable?.should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "TileType::OUT behaves for :out" do
|
33
|
+
t = TileType::OUT
|
34
|
+
t.out?.should be_true
|
35
|
+
t.movable?.should be_false
|
36
|
+
end
|
37
|
+
|
38
|
+
it "TileType::WALL behaves for :wall" do
|
39
|
+
t = TileType::WALL
|
40
|
+
t.wall?.should be_true
|
41
|
+
t.movable?.should be_false
|
42
|
+
end
|
43
|
+
|
44
|
+
it "TileType::ROOM behaves for :room" do
|
45
|
+
t = TileType::ROOM
|
46
|
+
t.room?.should be_true
|
47
|
+
t.movable?.should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "TileType::ROAD behaves for :road" do
|
51
|
+
t = TileType::ROAD
|
52
|
+
t.road?.should be_true
|
53
|
+
t.movable?.should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
|
3
|
+
|
4
|
+
include RDGC::Map
|
5
|
+
|
6
|
+
describe RDGC::Map::Area, "provide area, filled with Tile" do
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
@top = 8
|
10
|
+
@bottom = 10
|
11
|
+
@left = 11
|
12
|
+
@right = 19
|
13
|
+
|
14
|
+
@area = Area.new
|
15
|
+
@area.top = @top
|
16
|
+
@area.bottom = @bottom
|
17
|
+
@area.left = @left
|
18
|
+
@area.right = @right
|
19
|
+
end
|
20
|
+
|
21
|
+
it "top <= bottom, left <= right" do
|
22
|
+
(@top <= @bottom).should be_true
|
23
|
+
(@left <= @right).should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "#height should be (bottom - top + 1)" do
|
27
|
+
@area.height.should == (@bottom - @top + 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "#width should be (right - left + 1)" do
|
31
|
+
@area.width.should == (@right - @left + 1)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "#coordinates/#to_co puts params" do
|
35
|
+
expect = "t:#{@top} b:#{@bottom} l:#{@left} r:#{@right} / w:#{@area.width} h:#{@area.height}"
|
36
|
+
@area.coordinates.should == expect
|
37
|
+
@area.to_co.should == expect
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#has_xy? should be true if in area, false out of area, for (x, y)" do
|
41
|
+
@area.has_xy?(@left, @top).should be_true
|
42
|
+
@area.has_xy?(@left-1, @top).should be_false
|
43
|
+
@area.has_xy?(@left, @top-1).should be_false
|
44
|
+
@area.has_xy?(@right, @bottom).should be_true
|
45
|
+
@area.has_xy?(@right+1, @bottom).should be_false
|
46
|
+
@area.has_xy?(@right, @bottom+1).should be_false
|
47
|
+
end
|
48
|
+
|
49
|
+
it "#each_x provides each left to right" do
|
50
|
+
last = nil
|
51
|
+
@area.each_x.with_index do |x, i|
|
52
|
+
x.should == @left + i
|
53
|
+
last = @left + i
|
54
|
+
end
|
55
|
+
last.should == @right
|
56
|
+
end
|
57
|
+
|
58
|
+
it "#each_y provides each top to bottom" do
|
59
|
+
last = nil
|
60
|
+
@area.each_y.with_index do |y, i|
|
61
|
+
y.should == @top + i
|
62
|
+
last = @top + i
|
63
|
+
end
|
64
|
+
last.should == @bottom
|
65
|
+
end
|
66
|
+
|
67
|
+
it "#each provides all coordinates" do
|
68
|
+
@area.each do |x, y|
|
69
|
+
@area.has_xy?(x, y).should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
cs = @area.each
|
73
|
+
cs.should be_kind_of(Enumerable)
|
74
|
+
cs.each do |x, y|
|
75
|
+
@area.has_xy?(x, y).should be_true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "#fill_tile set tile for all coordinates" do
|
80
|
+
@area.fill_tile(TileType::WALL)
|
81
|
+
@area.each do |x, y|
|
82
|
+
@area.tile(x, y).should == TileType::WALL
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "#each_tile provides each coordinate's tile" do
|
87
|
+
@area.fill_tile(TileType::ROAD)
|
88
|
+
@area.each_tile do |x, y, t|
|
89
|
+
t.should == TileType::ROAD
|
90
|
+
end
|
91
|
+
|
92
|
+
ts = @area.each_tile
|
93
|
+
ts.should be_kind_of(Enumerable)
|
94
|
+
tiles = ts.to_a.map{|a| a.last}
|
95
|
+
tiles.all?{|t| t == TileType::ROAD}
|
96
|
+
end
|
97
|
+
|
98
|
+
it "#set_tile will set tile object for (x, y)" do
|
99
|
+
@area.set_tile(@left, @top, TileType::ROOM).should be_an_instance_of(Tile)
|
100
|
+
t = @area.tile(@left, @top)
|
101
|
+
t.should be_an_instance_of(Tile)
|
102
|
+
t.should == TileType::ROOM
|
103
|
+
end
|
104
|
+
|
105
|
+
it "#set_tile failed, and #tile is nil, if out of area" do
|
106
|
+
@area.set_tile(@left-1, @top-1, TileType::ROOM).should be_nil
|
107
|
+
t = @area.tile(@left-1, @top-1)
|
108
|
+
t.should be_nil
|
109
|
+
end
|
110
|
+
|
111
|
+
it "#random_point provides random point in area" do
|
112
|
+
10.times do
|
113
|
+
x, y = @area.random_point
|
114
|
+
@area.has_xy?(x, y).should be_true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
|
3
|
+
|
4
|
+
include RDGC::Map
|
5
|
+
|
6
|
+
describe RDGC::Map::Road, "is Area, filled with TileType::ROAD" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@top = 8
|
10
|
+
@bottom = 8
|
11
|
+
@left = 11
|
12
|
+
@right = 19
|
13
|
+
|
14
|
+
@road = Road.create(@top, @bottom, @left, @right)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "filled with TileType::ROAD" do
|
18
|
+
@road.each_tile do |x, y, t|
|
19
|
+
t.should == TileType::ROAD
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|