rubywarrior-i18n 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +38 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +44 -0
- data/LICENSE +20 -0
- data/README.md +199 -0
- data/Rakefile +17 -0
- data/bin/rubywarrior +5 -0
- data/features/command_options.feature +46 -0
- data/features/levels.feature +71 -0
- data/features/profiles.feature +56 -0
- data/features/step_definitions/common_steps.rb +19 -0
- data/features/step_definitions/interaction_steps.rb +65 -0
- data/features/support/env.rb +12 -0
- data/features/support/mockio.rb +57 -0
- data/features/towers.feature +14 -0
- data/i18n/en.yml +232 -0
- data/i18n/es.yml +233 -0
- data/lib/ruby_warrior.rb +53 -0
- data/lib/ruby_warrior/abilities/attack.rb +25 -0
- data/lib/ruby_warrior/abilities/base.rb +44 -0
- data/lib/ruby_warrior/abilities/bind.rb +20 -0
- data/lib/ruby_warrior/abilities/detonate.rb +34 -0
- data/lib/ruby_warrior/abilities/direction_of.rb +13 -0
- data/lib/ruby_warrior/abilities/direction_of_stairs.rb +13 -0
- data/lib/ruby_warrior/abilities/distance_of.rb +13 -0
- data/lib/ruby_warrior/abilities/explode.rb +28 -0
- data/lib/ruby_warrior/abilities/feel.rb +14 -0
- data/lib/ruby_warrior/abilities/form.rb +25 -0
- data/lib/ruby_warrior/abilities/health.rb +13 -0
- data/lib/ruby_warrior/abilities/listen.rb +15 -0
- data/lib/ruby_warrior/abilities/look.rb +16 -0
- data/lib/ruby_warrior/abilities/pivot.rb +17 -0
- data/lib/ruby_warrior/abilities/rescue.rb +24 -0
- data/lib/ruby_warrior/abilities/rest.rb +20 -0
- data/lib/ruby_warrior/abilities/shoot.rb +24 -0
- data/lib/ruby_warrior/abilities/walk.rb +21 -0
- data/lib/ruby_warrior/config.rb +22 -0
- data/lib/ruby_warrior/core_additions.rb +29 -0
- data/lib/ruby_warrior/floor.rb +71 -0
- data/lib/ruby_warrior/game.rb +209 -0
- data/lib/ruby_warrior/level.rb +123 -0
- data/lib/ruby_warrior/level_loader.rb +56 -0
- data/lib/ruby_warrior/player_generator.rb +41 -0
- data/lib/ruby_warrior/position.rb +82 -0
- data/lib/ruby_warrior/profile.rb +120 -0
- data/lib/ruby_warrior/runner.rb +34 -0
- data/lib/ruby_warrior/space.rb +71 -0
- data/lib/ruby_warrior/tower.rb +14 -0
- data/lib/ruby_warrior/turn.rb +38 -0
- data/lib/ruby_warrior/ui.rb +54 -0
- data/lib/ruby_warrior/units/archer.rb +34 -0
- data/lib/ruby_warrior/units/base.rb +100 -0
- data/lib/ruby_warrior/units/captive.rb +17 -0
- data/lib/ruby_warrior/units/golem.rb +20 -0
- data/lib/ruby_warrior/units/sludge.rb +30 -0
- data/lib/ruby_warrior/units/thick_sludge.rb +13 -0
- data/lib/ruby_warrior/units/warrior.rb +73 -0
- data/lib/ruby_warrior/units/wizard.rb +34 -0
- data/lib/ruby_warrior/version.rb +3 -0
- data/spec/fixtures/short-tower/level_001.rb +15 -0
- data/spec/fixtures/short-tower/level_002.rb +15 -0
- data/spec/fixtures/walking_player.rb +5 -0
- data/spec/ruby_warrior/abilities/attack_spec.rb +51 -0
- data/spec/ruby_warrior/abilities/base_spec.rb +38 -0
- data/spec/ruby_warrior/abilities/bind_spec.rb +19 -0
- data/spec/ruby_warrior/abilities/direction_of_spec.rb +13 -0
- data/spec/ruby_warrior/abilities/direction_of_stairs_spec.rb +13 -0
- data/spec/ruby_warrior/abilities/distance_of_spec.rb +13 -0
- data/spec/ruby_warrior/abilities/explode_spec.rb +32 -0
- data/spec/ruby_warrior/abilities/feel_spec.rb +13 -0
- data/spec/ruby_warrior/abilities/form_spec.rb +48 -0
- data/spec/ruby_warrior/abilities/health_spec.rb +13 -0
- data/spec/ruby_warrior/abilities/listen_spec.rb +17 -0
- data/spec/ruby_warrior/abilities/look_spec.rb +15 -0
- data/spec/ruby_warrior/abilities/pivot_spec.rb +18 -0
- data/spec/ruby_warrior/abilities/rescue_spec.rb +40 -0
- data/spec/ruby_warrior/abilities/rest_spec.rb +29 -0
- data/spec/ruby_warrior/abilities/shoot_spec.rb +22 -0
- data/spec/ruby_warrior/abilities/throw_spec.rb +46 -0
- data/spec/ruby_warrior/abilities/walk_spec.rb +25 -0
- data/spec/ruby_warrior/core_additions_spec.rb +7 -0
- data/spec/ruby_warrior/floor_spec.rb +81 -0
- data/spec/ruby_warrior/game_spec.rb +119 -0
- data/spec/ruby_warrior/level_loader_spec.rb +54 -0
- data/spec/ruby_warrior/level_spec.rb +203 -0
- data/spec/ruby_warrior/player_generator_spec.rb +12 -0
- data/spec/ruby_warrior/position_spec.rb +108 -0
- data/spec/ruby_warrior/profile_spec.rb +171 -0
- data/spec/ruby_warrior/space_spec.rb +190 -0
- data/spec/ruby_warrior/tower_spec.rb +15 -0
- data/spec/ruby_warrior/turn_spec.rb +42 -0
- data/spec/ruby_warrior/ui_spec.rb +93 -0
- data/spec/ruby_warrior/units/archer_spec.rb +23 -0
- data/spec/ruby_warrior/units/base_spec.rb +133 -0
- data/spec/ruby_warrior/units/captive_spec.rb +23 -0
- data/spec/ruby_warrior/units/golem_spec.rb +28 -0
- data/spec/ruby_warrior/units/sludge_spec.rb +27 -0
- data/spec/ruby_warrior/units/thick_sludge_spec.rb +19 -0
- data/spec/ruby_warrior/units/warrior_spec.rb +65 -0
- data/spec/ruby_warrior/units/wizard_spec.rb +23 -0
- data/spec/spec_helper.rb +10 -0
- data/templates/README.erb +33 -0
- data/templates/player.rb +5 -0
- data/towers/beginner/level_001.rb +18 -0
- data/towers/beginner/level_002.rb +19 -0
- data/towers/beginner/level_003.rb +23 -0
- data/towers/beginner/level_004.rb +20 -0
- data/towers/beginner/level_005.rb +24 -0
- data/towers/beginner/level_006.rb +21 -0
- data/towers/beginner/level_007.rb +20 -0
- data/towers/beginner/level_008.rb +23 -0
- data/towers/beginner/level_009.rb +22 -0
- data/towers/intermediate/level_001.rb +20 -0
- data/towers/intermediate/level_002.rb +22 -0
- data/towers/intermediate/level_003.rb +25 -0
- data/towers/intermediate/level_004.rb +26 -0
- data/towers/intermediate/level_005.rb +21 -0
- data/towers/intermediate/level_006.rb +25 -0
- data/towers/intermediate/level_007.rb +27 -0
- data/towers/intermediate/level_008.rb +25 -0
- data/towers/intermediate/level_009.rb +33 -0
- metadata +226 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
module RubyWarrior
|
2
|
+
class Space
|
3
|
+
def initialize(floor, x, y)
|
4
|
+
@floor, @x, @y = floor, x, y
|
5
|
+
end
|
6
|
+
|
7
|
+
def wall?
|
8
|
+
@floor.out_of_bounds? @x, @y
|
9
|
+
end
|
10
|
+
|
11
|
+
def warrior?
|
12
|
+
unit.kind_of? Units::Warrior
|
13
|
+
end
|
14
|
+
|
15
|
+
def golem?
|
16
|
+
unit.kind_of? Units::Golem
|
17
|
+
end
|
18
|
+
|
19
|
+
def player?
|
20
|
+
warrior? || golem?
|
21
|
+
end
|
22
|
+
|
23
|
+
def enemy?
|
24
|
+
unit && !player? && !captive?
|
25
|
+
end
|
26
|
+
|
27
|
+
def captive?
|
28
|
+
unit && unit.bound?
|
29
|
+
end
|
30
|
+
|
31
|
+
def empty?
|
32
|
+
unit.nil? && !wall?
|
33
|
+
end
|
34
|
+
|
35
|
+
def stairs?
|
36
|
+
@floor.stairs_location == location
|
37
|
+
end
|
38
|
+
|
39
|
+
def ticking?
|
40
|
+
unit && unit.abilities.include?(:explode!)
|
41
|
+
end
|
42
|
+
|
43
|
+
def unit
|
44
|
+
@floor.get(@x, @y)
|
45
|
+
end
|
46
|
+
|
47
|
+
def location
|
48
|
+
[@x, @y]
|
49
|
+
end
|
50
|
+
|
51
|
+
def character
|
52
|
+
if unit
|
53
|
+
unit.character
|
54
|
+
elsif stairs?
|
55
|
+
">"
|
56
|
+
else
|
57
|
+
" "
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_s
|
62
|
+
if unit
|
63
|
+
unit.to_s
|
64
|
+
elsif wall?
|
65
|
+
R18n.t.wall
|
66
|
+
else
|
67
|
+
R18n.t.nothing
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RubyWarrior
|
2
|
+
class Tower
|
3
|
+
attr_reader :path
|
4
|
+
|
5
|
+
def initialize(path)
|
6
|
+
@path = File.join(File.expand_path('../../../towers/', __FILE__), path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
R18n.t.level[File.basename(path)]
|
11
|
+
end
|
12
|
+
alias_method :to_s, :name
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RubyWarrior
|
2
|
+
class Turn
|
3
|
+
attr_reader :action
|
4
|
+
|
5
|
+
def initialize(abilities)
|
6
|
+
@action = nil
|
7
|
+
@senses = {}
|
8
|
+
|
9
|
+
abilities.each do |name, sense|
|
10
|
+
if name.to_s =~ /\!$/
|
11
|
+
add_action(name)
|
12
|
+
else
|
13
|
+
add_sense(name, sense)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def add_action(action)
|
21
|
+
instance_eval <<-EOS
|
22
|
+
def #{action}(*args)
|
23
|
+
raise "#{R18n.t.only_one_turn}" if @action
|
24
|
+
@action = [:#{action}, *args]
|
25
|
+
end
|
26
|
+
EOS
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_sense(name, sense)
|
30
|
+
instance_eval <<-EOS
|
31
|
+
def #{name}(*args)
|
32
|
+
@senses[:#{name}].perform(*args)
|
33
|
+
end
|
34
|
+
EOS
|
35
|
+
@senses[name] = sense
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module RubyWarrior
|
2
|
+
class UI
|
3
|
+
class << self
|
4
|
+
def puts(msg)
|
5
|
+
Config.out_stream.puts(msg) if Config.out_stream
|
6
|
+
end
|
7
|
+
|
8
|
+
def puts_with_delay(msg)
|
9
|
+
result = puts(msg)
|
10
|
+
sleep(Config.delay) if Config.delay
|
11
|
+
result
|
12
|
+
end
|
13
|
+
|
14
|
+
def print(msg)
|
15
|
+
Config.out_stream.print(msg) if Config.out_stream
|
16
|
+
end
|
17
|
+
|
18
|
+
def gets
|
19
|
+
Config.in_stream ? Config.in_stream.gets : ''
|
20
|
+
end
|
21
|
+
|
22
|
+
def request(msg)
|
23
|
+
print(msg)
|
24
|
+
gets.chomp
|
25
|
+
end
|
26
|
+
|
27
|
+
def ask(msg)
|
28
|
+
request("#{msg} [#{R18n.t.answer.yes_no}] ") == R18n.t.answer.yes_initial
|
29
|
+
end
|
30
|
+
|
31
|
+
# REFACTORME
|
32
|
+
def choose(item, options)
|
33
|
+
if options.length == 1
|
34
|
+
response = options.first
|
35
|
+
else
|
36
|
+
options.each_with_index do |option, i|
|
37
|
+
if option.kind_of? Array
|
38
|
+
puts "[#{i+1}] #{option.last}"
|
39
|
+
else
|
40
|
+
puts "[#{i+1}] #{option}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
choice = request(R18n.t.item.choose_typing_number(item))
|
44
|
+
response = options[choice.to_i-1]
|
45
|
+
end
|
46
|
+
if response.kind_of? Array
|
47
|
+
response.first
|
48
|
+
else
|
49
|
+
response
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RubyWarrior
|
2
|
+
module Units
|
3
|
+
class Archer < Base
|
4
|
+
def initialize
|
5
|
+
add_abilities :shoot!, :look
|
6
|
+
end
|
7
|
+
|
8
|
+
def play_turn(turn)
|
9
|
+
[:forward, :left, :right].each do |direction|
|
10
|
+
turn.look(direction).each do |space|
|
11
|
+
if space.player?
|
12
|
+
turn.shoot!(direction)
|
13
|
+
return
|
14
|
+
elsif !space.empty?
|
15
|
+
break
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def shoot_power
|
22
|
+
3
|
23
|
+
end
|
24
|
+
|
25
|
+
def max_health
|
26
|
+
7
|
27
|
+
end
|
28
|
+
|
29
|
+
def character
|
30
|
+
"#{R18n.t.archer.first_letter}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module RubyWarrior
|
2
|
+
module Units
|
3
|
+
class Base
|
4
|
+
attr_writer :health
|
5
|
+
attr_accessor :position
|
6
|
+
|
7
|
+
def attack_power
|
8
|
+
0
|
9
|
+
end
|
10
|
+
|
11
|
+
def max_health
|
12
|
+
0
|
13
|
+
end
|
14
|
+
|
15
|
+
def earn_points(points)
|
16
|
+
end
|
17
|
+
|
18
|
+
def health
|
19
|
+
@health ||= max_health
|
20
|
+
end
|
21
|
+
|
22
|
+
def take_damage(amount)
|
23
|
+
unbind if bound?
|
24
|
+
if health
|
25
|
+
self.health -= amount
|
26
|
+
say R18n.t.take_damage_health_left(amount, health < 0 ? 0 : health)
|
27
|
+
if health <= 0
|
28
|
+
@position = nil
|
29
|
+
say R18n.t.player.dies
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def alive?
|
35
|
+
!position.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
def bound?
|
39
|
+
@bound
|
40
|
+
end
|
41
|
+
|
42
|
+
def unbind
|
43
|
+
say R18n.t.player.released_from_bonds
|
44
|
+
@bound = false
|
45
|
+
end
|
46
|
+
|
47
|
+
def bind
|
48
|
+
@bound = true
|
49
|
+
end
|
50
|
+
|
51
|
+
def say(msg)
|
52
|
+
UI.puts_with_delay "#{name} #{msg}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def name
|
56
|
+
R18n.t[self.class.name.split('::').last.downcase].name.capitalize
|
57
|
+
end
|
58
|
+
alias_method :to_s, :name
|
59
|
+
|
60
|
+
def add_abilities(*new_abilities)
|
61
|
+
new_abilities.each do |ability|
|
62
|
+
abilities[ability] = eval("Abilities::#{ability.to_s.sub('!', '').camelize}").new(self) # TODO use something similar to constantize here
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def next_turn
|
67
|
+
Turn.new(abilities)
|
68
|
+
end
|
69
|
+
|
70
|
+
def prepare_turn
|
71
|
+
@current_turn = next_turn
|
72
|
+
play_turn(@current_turn)
|
73
|
+
end
|
74
|
+
|
75
|
+
def perform_turn
|
76
|
+
if @position
|
77
|
+
abilities.values.each do |ability|
|
78
|
+
ability.pass_turn
|
79
|
+
end
|
80
|
+
if @current_turn.action && !bound?
|
81
|
+
name, *args = @current_turn.action
|
82
|
+
abilities[name].perform(*args)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def play_turn(turn)
|
88
|
+
# to be overriden by subclass
|
89
|
+
end
|
90
|
+
|
91
|
+
def abilities
|
92
|
+
@abilities ||= {}
|
93
|
+
end
|
94
|
+
|
95
|
+
def character
|
96
|
+
"?"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RubyWarrior
|
2
|
+
module Units
|
3
|
+
class Golem < Base
|
4
|
+
attr_writer :turn
|
5
|
+
attr_accessor :max_health
|
6
|
+
|
7
|
+
def play_turn(turn)
|
8
|
+
@turn.call(turn) if @turn
|
9
|
+
end
|
10
|
+
|
11
|
+
def attack_power
|
12
|
+
3
|
13
|
+
end
|
14
|
+
|
15
|
+
def character
|
16
|
+
"#{R18n.t.golem.first_letter}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RubyWarrior
|
2
|
+
module Units
|
3
|
+
class Sludge < Base
|
4
|
+
def initialize
|
5
|
+
add_abilities :attack!, :feel
|
6
|
+
end
|
7
|
+
|
8
|
+
def play_turn(turn)
|
9
|
+
[:forward, :left, :right, :backward].each do |direction|
|
10
|
+
if turn.feel(direction).player?
|
11
|
+
turn.attack!(direction)
|
12
|
+
return
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def attack_power
|
18
|
+
3
|
19
|
+
end
|
20
|
+
|
21
|
+
def max_health
|
22
|
+
12
|
23
|
+
end
|
24
|
+
|
25
|
+
def character
|
26
|
+
"#{R18n.t.sludge.first_letter}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module RubyWarrior
|
2
|
+
module Units
|
3
|
+
class Warrior < Base
|
4
|
+
attr_writer :name
|
5
|
+
attr_reader :score
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@score = 0 # TODO make score dynamic
|
9
|
+
@golem_abilities = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def play_turn(turn)
|
13
|
+
player.play_turn(turn)
|
14
|
+
end
|
15
|
+
|
16
|
+
def player
|
17
|
+
@player ||= Player.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def earn_points(points)
|
21
|
+
@score += points
|
22
|
+
say R18n.t.warrior.earns_points(points)
|
23
|
+
end
|
24
|
+
|
25
|
+
def attack_power
|
26
|
+
5
|
27
|
+
end
|
28
|
+
|
29
|
+
def shoot_power
|
30
|
+
3
|
31
|
+
end
|
32
|
+
|
33
|
+
def max_health
|
34
|
+
20
|
35
|
+
end
|
36
|
+
|
37
|
+
def name
|
38
|
+
if @name && !@name.empty?
|
39
|
+
@name
|
40
|
+
else
|
41
|
+
"#{R18n.t.warrior.warrior.capitalize}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
name
|
47
|
+
end
|
48
|
+
|
49
|
+
def character
|
50
|
+
"@"
|
51
|
+
end
|
52
|
+
|
53
|
+
def perform_turn
|
54
|
+
say "#{R18n.t.warrior.does_nothing}" if @current_turn.action.nil?
|
55
|
+
super
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_golem_abilities(*abilities)
|
59
|
+
@golem_abilities += abilities
|
60
|
+
end
|
61
|
+
|
62
|
+
def has_golem?
|
63
|
+
!@golem_abilities.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
def base_golem
|
67
|
+
golem = Golem.new
|
68
|
+
golem.add_abilities *@golem_abilities
|
69
|
+
golem
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|