rdgc-dm 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/lib/rdgc/map/area.rb CHANGED
@@ -79,6 +79,8 @@ module RDGC
79
79
  each do |x, y|
80
80
  set_tile(x, y, tile)
81
81
  end
82
+
83
+ self
82
84
  end
83
85
 
84
86
  def set_tile(x, y, tile)
@@ -11,6 +11,7 @@ module RDGC
11
11
  def set_blind(level)
12
12
  return unless [:none, :open, :blind, :dark].include?(level)
13
13
  @blind_level = level
14
+ self
14
15
  end
15
16
 
16
17
  def blind_level_none?
@@ -51,6 +52,7 @@ module RDGC
51
52
  @blind_mode = mode
52
53
  @blind_mode ||= BLIND_MODE_NORMAL
53
54
  init_blind
55
+ self
54
56
  end
55
57
 
56
58
  def blind_mode
@@ -76,10 +78,12 @@ module RDGC
76
78
  blind_data[x][y] = target
77
79
  end
78
80
  end
81
+
82
+ self
79
83
  end
80
84
 
81
85
  def visible?(x, y)
82
- return false unless has_xy?(x, y)
86
+ return false unless has_xy?(x, y)
83
87
  return true unless blind_mode?
84
88
  v = blind_data[x][y]
85
89
  return false unless v
@@ -91,7 +95,7 @@ module RDGC
91
95
  end
92
96
 
93
97
  def dark?(x, y)
94
- return false unless has_xy?(x, y)
98
+ return false unless has_xy?(x, y)
95
99
  blind_data[x][y] == :dark ? true : false
96
100
  end
97
101
 
@@ -112,11 +116,8 @@ module RDGC
112
116
  blind_data[x][y] = :none
113
117
  end
114
118
  end
115
- end
116
119
 
117
- def blind_data
118
- @blind_data ||= Hash.new{|hash, key| hash[key] = {}}
119
- @blind_data
120
+ self
120
121
  end
121
122
 
122
123
  def init_blind
@@ -128,12 +129,16 @@ module RDGC
128
129
  when BLIND_MODE_NORMAL
129
130
  init_blind_normal
130
131
  end
132
+
133
+ self
131
134
  end
132
135
 
133
136
  def init_blind_all(level)
134
137
  areas.each do |r|
135
138
  r.set_blind(level)
136
139
  end
140
+
141
+ self
137
142
  end
138
143
 
139
144
  def init_blind_normal
@@ -144,10 +149,27 @@ module RDGC
144
149
  roads.each do |r|
145
150
  r.set_blind(:blind)
146
151
  end
152
+
153
+ self
154
+ end
155
+
156
+ def blind_state(x, y)
157
+ return unless has_xy?(x, y)
158
+ blind_data[x][y]
159
+ end
160
+
161
+ def set_blind_state(x, y, state)
162
+ return unless has_xy?(x, y)
163
+ blind_data[x][y] = state
147
164
  end
148
165
 
149
166
  private
150
167
 
168
+ def blind_data
169
+ @blind_data ||= Hash.new{|hash, key| hash[key] = {}}
170
+ @blind_data
171
+ end
172
+
151
173
  def fill_dark_before_cancel
152
174
  areas.select{|r| r.blind_level_dark?}.each do |r|
153
175
  r.each do |x, y|
@@ -14,6 +14,8 @@ module RDGC
14
14
 
15
15
  fill_room
16
16
  fill_roads
17
+
18
+ self
17
19
  end
18
20
 
19
21
  def fill_room
@@ -21,6 +23,8 @@ module RDGC
21
23
  room.each_tile do |x, y, t|
22
24
  set_tile(x, y, t)
23
25
  end
26
+
27
+ self
24
28
  end
25
29
 
26
30
  def fill_roads
@@ -30,6 +34,8 @@ module RDGC
30
34
  set_tile(x, y, t)
31
35
  end
32
36
  end
37
+
38
+ self
33
39
  end
34
40
 
35
41
  def room
@@ -101,6 +107,7 @@ module RDGC
101
107
  remove_room
102
108
  remove_roads
103
109
  remove_cross_point
110
+ self
104
111
  end
105
112
 
106
113
  def empty?
@@ -19,6 +19,8 @@ module RDGC
19
19
 
20
20
  set_coordinates
21
21
  fill
22
+
23
+ self
22
24
  end
23
25
 
24
26
  def set_coordinates
@@ -27,6 +29,8 @@ module RDGC
27
29
  self.bottom = blocks.map(&:bottom).max
28
30
  self.left = blocks.map(&:left).min
29
31
  self.right = blocks.map(&:right).max
32
+
33
+ self
30
34
  end
31
35
 
32
36
  def fill
@@ -44,6 +48,8 @@ module RDGC
44
48
  set_tile(x, y, t)
45
49
  end
46
50
  end
51
+
52
+ self
47
53
  end
48
54
 
49
55
  def blocks
@@ -1,4 +1,4 @@
1
- # -*- coding: UTF-8 -*-
1
+ # coding: UTF-8
2
2
  module RDGC
3
3
  module Map
4
4
  class Direction
data/lib/rdgc/map/road.rb CHANGED
@@ -11,6 +11,7 @@ module RDGC
11
11
 
12
12
  def fill
13
13
  fill_tile TileType::ROAD
14
+ self
14
15
  end
15
16
 
16
17
  end
data/lib/rdgc/map/room.rb CHANGED
@@ -22,6 +22,7 @@ module RDGC
22
22
 
23
23
  def fill
24
24
  fill_tile TileType::ROOM
25
+ self
25
26
  end
26
27
 
27
28
  private
@@ -4,68 +4,45 @@ module RDGC
4
4
  class Config
5
5
 
6
6
  DEFAULT_CONFIG = {
7
- :min_room_size => 4,
8
- :act_max_count => 200
7
+ :min_room_size => 4
9
8
  }
10
9
 
11
- self.class.class_eval do
12
- @config_hash = DEFAULT_CONFIG
13
- end
14
-
15
- def self.set(hash)
16
- return if seted?
10
+ class << self
17
11
 
18
- default = nil
19
- self.class.class_eval do
20
- default = @config_hash
21
- end
12
+ def set(hash)
13
+ return if seted?
22
14
 
23
- hash = default.merge(hash)
24
-
25
- self.class.class_eval do
15
+ hash = DEFAULT_CONFIG.merge(hash)
26
16
  @config_hash = hash
27
17
  @seted = true
28
- end
29
18
 
30
- true
31
- end
32
-
33
- def self.min_room_size
34
- self.get(:min_room_size)
35
- end
36
-
37
- def self.min_block_size
38
- # デフォルトのblock最小値 = 最小部屋サイズ+上下空き2+接線通路分1
39
- self.min_room_size + 3
40
- end
41
-
42
- def self.act_max_count
43
- self.get(:act_max_count)
44
- end
19
+ true
20
+ end
45
21
 
46
- def self.seted?
47
- ret = false
48
- self.class.class_eval do
49
- ret = @seted
22
+ def get(key)
23
+ @config_hash ||= DEFAULT_CONFIG
24
+ @config_hash[key]
50
25
  end
51
- ret
52
- end
53
26
 
54
- def self.get(key)
55
- val = nil
56
- self.class.class_eval do
57
- val = @config_hash[key]
27
+ def seted?
28
+ @seted ? true : false
58
29
  end
59
- val
60
- end
61
30
 
62
- def self.reset!
63
- self.class.class_eval do
31
+ def reset!
64
32
  @config_hash = DEFAULT_CONFIG
65
33
  @seted = false
34
+ true
35
+ end
36
+
37
+ def min_room_size
38
+ get(:min_room_size)
39
+ end
40
+
41
+ def min_block_size
42
+ # デフォルトのblock最小値 = 最小部屋サイズ+上下空き2+接線通路分1
43
+ min_room_size + 3
66
44
  end
67
45
 
68
- true
69
46
  end
70
47
 
71
48
  end
@@ -3,6 +3,8 @@ module RDGC
3
3
  module Util
4
4
  module RandomUtil
5
5
 
6
+ module_function
7
+
6
8
  def bool_rand
7
9
  case rand(2)
8
10
  when 1
@@ -49,8 +51,6 @@ module RDGC
49
51
  ret
50
52
  end
51
53
 
52
- module_function :bool_rand, :range_rand, :select_rand, :dice
53
-
54
54
  end
55
55
  end
56
56
  end
@@ -101,4 +101,10 @@ class Array
101
101
  ret
102
102
  end
103
103
 
104
- end
104
+ if RUBY_VERSION >= '1.9.1'
105
+ def choice
106
+ self.sample
107
+ end
108
+ end
109
+
110
+ end
data/rdgc-dm.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rdgc-dm}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["parrot_studio"]
12
- s.date = %q{2010-05-13}
12
+ s.date = %q{2010-09-22}
13
13
  s.description = %q{ This gem is part of RDGC - Ruby(Random) Dungeon Game Core.
14
14
  RDGC is core of random dungeon game (like rogue), make dungeon, manage monsters etc.
15
15
  }
@@ -63,7 +63,7 @@ Gem::Specification.new do |s|
63
63
  s.rdoc_options = ["--charset=UTF-8"]
64
64
  s.require_paths = ["lib"]
65
65
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
66
- s.rubygems_version = %q{1.3.6}
66
+ s.rubygems_version = %q{1.3.7}
67
67
  s.summary = %q{Random Dungeon Maker from RDGC}
68
68
  s.test_files = [
69
69
  "spec/spec_helper.rb",
@@ -87,7 +87,7 @@ Gem::Specification.new do |s|
87
87
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
88
88
  s.specification_version = 3
89
89
 
90
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
90
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
91
91
  else
92
92
  end
93
93
  else
@@ -175,13 +175,18 @@ describe "blind mode" do
175
175
  @road2.blind_level_blind?.should be_true
176
176
  end
177
177
 
178
+ it "#blind_state/#set_blind_state will get/set blind_state" do
179
+ @board.set_blind_state(10, 9, :blind)
180
+ @board.blind_state(10, 9).should == :blind
181
+ end
182
+
178
183
  it "#fill_blind will fill blind_data as each area's blind_level" do
179
184
  @board.set_blind_mode
180
185
  @board.fill_blind
181
186
 
182
187
  @board.areas.each do |r|
183
188
  r.each do |x, y|
184
- @board.blind_data[x][y].should == :blind
189
+ @board.blind_state(x, y).should == :blind
185
190
  end
186
191
  end
187
192
 
@@ -190,7 +195,7 @@ describe "blind mode" do
190
195
 
191
196
  @board.areas.each do |r|
192
197
  r.each do |x, y|
193
- @board.blind_data[x][y].should == :none
198
+ @board.blind_state(x, y).should == :none
194
199
  end
195
200
  end
196
201
  end
@@ -204,7 +209,7 @@ describe "blind mode" do
204
209
  @room.each.all?{|x, y| @board.dark?(x, y)}.should be_true
205
210
 
206
211
  tx, ty = @room.random_point
207
- @board.blind_data[tx][ty] = :none
212
+ @board.set_blind_state(tx, ty, :none)
208
213
  @board.dark?(tx, ty).should be_false
209
214
  end
210
215
 
@@ -216,7 +221,7 @@ describe "blind mode" do
216
221
 
217
222
  5.times do
218
223
  tx, ty = @room.random_point
219
- @board.blind_data[tx][ty] = :none
224
+ @board.set_blind_state(tx, ty, :none)
220
225
  end
221
226
  @room.each.all?{|x, y| @board.dark?(x, y)}.should be_false
222
227
 
@@ -231,33 +236,33 @@ describe "blind mode" do
231
236
  @board.fill_blind
232
237
 
233
238
  @board.open_blind(10, 4, 0)
234
- @board.blind_data[10][4].should == :none
235
- @board.blind_data[10][3].should == :blind
236
- @board.blind_data[10][5].should == :blind
239
+ @board.blind_state(10, 4).should == :none
240
+ @board.blind_state(10, 3).should == :blind
241
+ @board.blind_state(10, 5).should == :blind
237
242
 
238
243
  @board.open_blind(10, 4, 1)
239
- @board.blind_data[10][4].should == :none
240
- @board.blind_data[10][3].should == :none
241
- @board.blind_data[10][5].should == :none
242
- @board.blind_data[10][2].should == :blind
243
- @board.blind_data[10][6].should == :blind
244
+ @board.blind_state(10, 4).should == :none
245
+ @board.blind_state(10, 3).should == :none
246
+ @board.blind_state(10, 5).should == :none
247
+ @board.blind_state(10, 2).should == :blind
248
+ @board.blind_state(10, 6).should == :blind
244
249
 
245
250
  @board.open_blind(10, 4, 2)
246
- @board.blind_data[10][4].should == :none
247
- @board.blind_data[10][3].should == :none
248
- @board.blind_data[10][2].should == :none
249
- @board.blind_data[10][1].should == :blind
250
-
251
- @board.blind_data[10][5].should == :none
252
- @board.blind_data[9][5].should == :none
253
- @board.blind_data[10][6].should == :none
254
- @board.blind_data[11][5].should == :none
255
-
256
- @board.blind_data[8][5].should == :blind
257
- @board.blind_data[12][5].should == :blind
258
- @board.blind_data[9][6].should == :blind
259
- @board.blind_data[11][6].should == :blind
260
- @board.blind_data[10][7].should == :blind
251
+ @board.blind_state(10, 4).should == :none
252
+ @board.blind_state(10, 3).should == :none
253
+ @board.blind_state(10, 2).should == :none
254
+ @board.blind_state(10, 1).should == :blind
255
+
256
+ @board.blind_state(10, 5).should == :none
257
+ @board.blind_state(9, 5).should == :none
258
+ @board.blind_state(10, 6).should == :none
259
+ @board.blind_state(11, 5).should == :none
260
+
261
+ @board.blind_state(8, 5).should == :blind
262
+ @board.blind_state(12, 5).should == :blind
263
+ @board.blind_state(9, 6).should == :blind
264
+ @board.blind_state(11, 6).should == :blind
265
+ @board.blind_state(10, 7).should == :blind
261
266
  end
262
267
 
263
268
  it "#open_blind will clear blind all of area for :open" do
@@ -265,13 +270,13 @@ describe "blind mode" do
265
270
  @board.fill_blind
266
271
 
267
272
  @board.open_blind(10, 4, 1)
268
- @board.blind_data[10][4].should == :none
269
- @board.blind_data[10][3].should == :none
270
- @board.blind_data[10][5].should == :none
271
- @board.blind_data[10][2].should == :blind
273
+ @board.blind_state(10, 4).should == :none
274
+ @board.blind_state(10, 3).should == :none
275
+ @board.blind_state(10, 5).should == :none
276
+ @board.blind_state(10, 2).should == :blind
272
277
 
273
278
  @room.each do |x, y|
274
- @board.blind_data[x][y].should == :none
279
+ @board.blind_state(x, y).should == :none
275
280
  end
276
281
  end
277
282
 
@@ -283,25 +288,25 @@ describe "blind mode" do
283
288
  # 1歩目
284
289
  @board.open_blind(10, 5, 1)
285
290
 
286
- @board.blind_data[10][4].should == :none
291
+ @board.blind_state(10, 4).should == :none
287
292
 
288
- @board.blind_data[10][5].should == :none
289
- @board.blind_data[9][5].should == :none
290
- @board.blind_data[11][5].should == :none
291
- @board.blind_data[10][6].should == :none
293
+ @board.blind_state(10, 5).should == :none
294
+ @board.blind_state(9, 5).should == :none
295
+ @board.blind_state(11, 5).should == :none
296
+ @board.blind_state(10, 6).should == :none
292
297
 
293
298
  # 2歩目
294
299
  @board.open_blind(10, 6, 1)
295
- @board.blind_data[10][4].should == :none
300
+ @board.blind_state(10, 4).should == :none
296
301
 
297
- @board.blind_data[10][6].should == :none
298
- @board.blind_data[9][6].should == :none
299
- @board.blind_data[11][6].should == :none
300
- @board.blind_data[10][5].should == :none
301
- @board.blind_data[10][7].should == :none
302
+ @board.blind_state(10, 6).should == :none
303
+ @board.blind_state(9, 6).should == :none
304
+ @board.blind_state(11, 6).should == :none
305
+ @board.blind_state(10, 5).should == :none
306
+ @board.blind_state(10, 7).should == :none
302
307
 
303
- @board.blind_data[9][5].should == :dark
304
- @board.blind_data[11][5].should == :dark
308
+ @board.blind_state(9, 5).should == :dark
309
+ @board.blind_state(11, 5).should == :dark
305
310
  end
306
311
 
307
312
  it "#visible?/#invisible?" do
@@ -8,35 +8,28 @@ describe RDGC::Util::Config do
8
8
  it "default value" do
9
9
  Util::Config.min_room_size.should == 4
10
10
  Util::Config.min_block_size.should == 7
11
- Util::Config.act_max_count.should == 200
12
11
  end
13
12
 
14
13
  it "value change only once, and #reset! will force change default value" do
15
14
  val1 = {
16
- :min_room_size => 5,
17
- :act_max_count => 100
15
+ :min_room_size => 5
18
16
  }
19
17
 
20
18
  Util::Config.set(val1).should be_true
21
19
  Util::Config.min_room_size.should == 5
22
- Util::Config.act_max_count.should == 100
23
20
 
24
21
  val2 = {
25
- :min_room_size => 10,
26
- :act_max_count => 80
22
+ :min_room_size => 10
27
23
  }
28
24
 
29
25
  Util::Config.set(val2).should be_false
30
26
  Util::Config.min_room_size.should == 5
31
- Util::Config.act_max_count.should == 100
32
27
 
33
28
  Util::Config.reset!.should be_true
34
29
  Util::Config.min_room_size.should == 4
35
- Util::Config.act_max_count.should == 200
36
30
 
37
31
  Util::Config.set(val2).should be_true
38
32
  Util::Config.min_room_size.should == 10
39
- Util::Config.act_max_count.should == 80
40
33
 
41
34
  Util::Config.reset!.should be_true
42
35
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdgc-dm
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 21
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 0
9
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - parrot_studio
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-13 00:00:00 +09:00
18
+ date: 2010-09-22 00:00:00 +09:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -77,25 +78,29 @@ rdoc_options:
77
78
  require_paths:
78
79
  - lib
79
80
  required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
80
82
  requirements:
81
83
  - - ">="
82
84
  - !ruby/object:Gem::Version
85
+ hash: 57
83
86
  segments:
84
87
  - 1
85
88
  - 8
86
89
  - 7
87
90
  version: 1.8.7
88
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
89
93
  requirements:
90
94
  - - ">="
91
95
  - !ruby/object:Gem::Version
96
+ hash: 3
92
97
  segments:
93
98
  - 0
94
99
  version: "0"
95
100
  requirements: []
96
101
 
97
102
  rubyforge_project:
98
- rubygems_version: 1.3.6
103
+ rubygems_version: 1.3.7
99
104
  signing_key:
100
105
  specification_version: 3
101
106
  summary: Random Dungeon Maker from RDGC