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.
Files changed (122) hide show
  1. data/CHANGELOG.rdoc +38 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +44 -0
  4. data/LICENSE +20 -0
  5. data/README.md +199 -0
  6. data/Rakefile +17 -0
  7. data/bin/rubywarrior +5 -0
  8. data/features/command_options.feature +46 -0
  9. data/features/levels.feature +71 -0
  10. data/features/profiles.feature +56 -0
  11. data/features/step_definitions/common_steps.rb +19 -0
  12. data/features/step_definitions/interaction_steps.rb +65 -0
  13. data/features/support/env.rb +12 -0
  14. data/features/support/mockio.rb +57 -0
  15. data/features/towers.feature +14 -0
  16. data/i18n/en.yml +232 -0
  17. data/i18n/es.yml +233 -0
  18. data/lib/ruby_warrior.rb +53 -0
  19. data/lib/ruby_warrior/abilities/attack.rb +25 -0
  20. data/lib/ruby_warrior/abilities/base.rb +44 -0
  21. data/lib/ruby_warrior/abilities/bind.rb +20 -0
  22. data/lib/ruby_warrior/abilities/detonate.rb +34 -0
  23. data/lib/ruby_warrior/abilities/direction_of.rb +13 -0
  24. data/lib/ruby_warrior/abilities/direction_of_stairs.rb +13 -0
  25. data/lib/ruby_warrior/abilities/distance_of.rb +13 -0
  26. data/lib/ruby_warrior/abilities/explode.rb +28 -0
  27. data/lib/ruby_warrior/abilities/feel.rb +14 -0
  28. data/lib/ruby_warrior/abilities/form.rb +25 -0
  29. data/lib/ruby_warrior/abilities/health.rb +13 -0
  30. data/lib/ruby_warrior/abilities/listen.rb +15 -0
  31. data/lib/ruby_warrior/abilities/look.rb +16 -0
  32. data/lib/ruby_warrior/abilities/pivot.rb +17 -0
  33. data/lib/ruby_warrior/abilities/rescue.rb +24 -0
  34. data/lib/ruby_warrior/abilities/rest.rb +20 -0
  35. data/lib/ruby_warrior/abilities/shoot.rb +24 -0
  36. data/lib/ruby_warrior/abilities/walk.rb +21 -0
  37. data/lib/ruby_warrior/config.rb +22 -0
  38. data/lib/ruby_warrior/core_additions.rb +29 -0
  39. data/lib/ruby_warrior/floor.rb +71 -0
  40. data/lib/ruby_warrior/game.rb +209 -0
  41. data/lib/ruby_warrior/level.rb +123 -0
  42. data/lib/ruby_warrior/level_loader.rb +56 -0
  43. data/lib/ruby_warrior/player_generator.rb +41 -0
  44. data/lib/ruby_warrior/position.rb +82 -0
  45. data/lib/ruby_warrior/profile.rb +120 -0
  46. data/lib/ruby_warrior/runner.rb +34 -0
  47. data/lib/ruby_warrior/space.rb +71 -0
  48. data/lib/ruby_warrior/tower.rb +14 -0
  49. data/lib/ruby_warrior/turn.rb +38 -0
  50. data/lib/ruby_warrior/ui.rb +54 -0
  51. data/lib/ruby_warrior/units/archer.rb +34 -0
  52. data/lib/ruby_warrior/units/base.rb +100 -0
  53. data/lib/ruby_warrior/units/captive.rb +17 -0
  54. data/lib/ruby_warrior/units/golem.rb +20 -0
  55. data/lib/ruby_warrior/units/sludge.rb +30 -0
  56. data/lib/ruby_warrior/units/thick_sludge.rb +13 -0
  57. data/lib/ruby_warrior/units/warrior.rb +73 -0
  58. data/lib/ruby_warrior/units/wizard.rb +34 -0
  59. data/lib/ruby_warrior/version.rb +3 -0
  60. data/spec/fixtures/short-tower/level_001.rb +15 -0
  61. data/spec/fixtures/short-tower/level_002.rb +15 -0
  62. data/spec/fixtures/walking_player.rb +5 -0
  63. data/spec/ruby_warrior/abilities/attack_spec.rb +51 -0
  64. data/spec/ruby_warrior/abilities/base_spec.rb +38 -0
  65. data/spec/ruby_warrior/abilities/bind_spec.rb +19 -0
  66. data/spec/ruby_warrior/abilities/direction_of_spec.rb +13 -0
  67. data/spec/ruby_warrior/abilities/direction_of_stairs_spec.rb +13 -0
  68. data/spec/ruby_warrior/abilities/distance_of_spec.rb +13 -0
  69. data/spec/ruby_warrior/abilities/explode_spec.rb +32 -0
  70. data/spec/ruby_warrior/abilities/feel_spec.rb +13 -0
  71. data/spec/ruby_warrior/abilities/form_spec.rb +48 -0
  72. data/spec/ruby_warrior/abilities/health_spec.rb +13 -0
  73. data/spec/ruby_warrior/abilities/listen_spec.rb +17 -0
  74. data/spec/ruby_warrior/abilities/look_spec.rb +15 -0
  75. data/spec/ruby_warrior/abilities/pivot_spec.rb +18 -0
  76. data/spec/ruby_warrior/abilities/rescue_spec.rb +40 -0
  77. data/spec/ruby_warrior/abilities/rest_spec.rb +29 -0
  78. data/spec/ruby_warrior/abilities/shoot_spec.rb +22 -0
  79. data/spec/ruby_warrior/abilities/throw_spec.rb +46 -0
  80. data/spec/ruby_warrior/abilities/walk_spec.rb +25 -0
  81. data/spec/ruby_warrior/core_additions_spec.rb +7 -0
  82. data/spec/ruby_warrior/floor_spec.rb +81 -0
  83. data/spec/ruby_warrior/game_spec.rb +119 -0
  84. data/spec/ruby_warrior/level_loader_spec.rb +54 -0
  85. data/spec/ruby_warrior/level_spec.rb +203 -0
  86. data/spec/ruby_warrior/player_generator_spec.rb +12 -0
  87. data/spec/ruby_warrior/position_spec.rb +108 -0
  88. data/spec/ruby_warrior/profile_spec.rb +171 -0
  89. data/spec/ruby_warrior/space_spec.rb +190 -0
  90. data/spec/ruby_warrior/tower_spec.rb +15 -0
  91. data/spec/ruby_warrior/turn_spec.rb +42 -0
  92. data/spec/ruby_warrior/ui_spec.rb +93 -0
  93. data/spec/ruby_warrior/units/archer_spec.rb +23 -0
  94. data/spec/ruby_warrior/units/base_spec.rb +133 -0
  95. data/spec/ruby_warrior/units/captive_spec.rb +23 -0
  96. data/spec/ruby_warrior/units/golem_spec.rb +28 -0
  97. data/spec/ruby_warrior/units/sludge_spec.rb +27 -0
  98. data/spec/ruby_warrior/units/thick_sludge_spec.rb +19 -0
  99. data/spec/ruby_warrior/units/warrior_spec.rb +65 -0
  100. data/spec/ruby_warrior/units/wizard_spec.rb +23 -0
  101. data/spec/spec_helper.rb +10 -0
  102. data/templates/README.erb +33 -0
  103. data/templates/player.rb +5 -0
  104. data/towers/beginner/level_001.rb +18 -0
  105. data/towers/beginner/level_002.rb +19 -0
  106. data/towers/beginner/level_003.rb +23 -0
  107. data/towers/beginner/level_004.rb +20 -0
  108. data/towers/beginner/level_005.rb +24 -0
  109. data/towers/beginner/level_006.rb +21 -0
  110. data/towers/beginner/level_007.rb +20 -0
  111. data/towers/beginner/level_008.rb +23 -0
  112. data/towers/beginner/level_009.rb +22 -0
  113. data/towers/intermediate/level_001.rb +20 -0
  114. data/towers/intermediate/level_002.rb +22 -0
  115. data/towers/intermediate/level_003.rb +25 -0
  116. data/towers/intermediate/level_004.rb +26 -0
  117. data/towers/intermediate/level_005.rb +21 -0
  118. data/towers/intermediate/level_006.rb +25 -0
  119. data/towers/intermediate/level_007.rb +27 -0
  120. data/towers/intermediate/level_008.rb +25 -0
  121. data/towers/intermediate/level_009.rb +33 -0
  122. metadata +226 -0
@@ -0,0 +1,34 @@
1
+ module RubyWarrior
2
+ module Units
3
+ class Wizard < 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
+ 11
23
+ end
24
+
25
+ def max_health
26
+ 3
27
+ end
28
+
29
+ def character
30
+ "#{R18n.t.wizard.first_letter}"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module RubyWarrior
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,15 @@
1
+ # --
2
+ # |@>|
3
+ # --
4
+
5
+ description "You see before yourself a long hallway with stairs at the end. There is nothing in the way."
6
+ tip "Call warrior.walk! to walk forward in the Player 'play_turn' method."
7
+
8
+ time_bonus 15
9
+ ace_score 17
10
+ size 2, 1
11
+ stairs 1, 0
12
+
13
+ warrior 0, 0, :east do |u|
14
+ u.add_abilities :walk!
15
+ end
@@ -0,0 +1,15 @@
1
+ # --
2
+ # |@>|
3
+ # --
4
+
5
+ description "You see before yourself a long hallway with stairs at the end. There is nothing in the way."
6
+ tip "Call warrior.walk! to walk forward in the Player 'play_turn' method."
7
+
8
+ time_bonus 15
9
+ ace_score 17
10
+ size 2, 1
11
+ stairs 1, 0
12
+
13
+ warrior 0, 0, :east do |u|
14
+ u.add_abilities :walk!
15
+ end
@@ -0,0 +1,5 @@
1
+ class Player
2
+ def play_turn(warrior)
3
+ warrior.walk!
4
+ end
5
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Attack do
4
+ before(:each) do
5
+ @attacker = stub(:position => stub, :attack_power => 3, :say => nil)
6
+ @attack = RubyWarrior::Abilities::Attack.new(@attacker)
7
+ end
8
+
9
+ it "should subtract attack power amount from health" do
10
+ receiver = RubyWarrior::Units::Base.new
11
+ receiver.stubs(:alive?).returns(true)
12
+ receiver.health = 5
13
+ @attack.stubs(:unit).returns(receiver)
14
+ @attack.perform
15
+ receiver.health.should == 2
16
+ end
17
+
18
+ it "should do nothing if recipient is nil" do
19
+ @attack.stubs(:unit).returns(nil)
20
+ lambda { @attack.perform }.should_not raise_error
21
+ end
22
+
23
+ it "should get object at position from offset" do
24
+ @attacker.position.expects(:relative_space).with(1, 0)
25
+ @attack.space(:forward)
26
+ end
27
+
28
+ it "should award points when killing unit" do
29
+ receiver = stub(:take_damage => nil, :max_health => 8, :alive? => false)
30
+ @attack.stubs(:unit).returns(receiver)
31
+ @attacker.expects(:earn_points).with(8)
32
+ @attack.perform
33
+ end
34
+
35
+ it "should not award points when not killing unit" do
36
+ receiver = stub(:max_health => 8, :alive? => true)
37
+ receiver.expects(:take_damage)
38
+ @attack.stubs(:unit).returns(receiver)
39
+ @attacker.expects(:earn_points).never
40
+ @attack.perform
41
+ end
42
+
43
+ it "should reduce attack power when attacking backward" do
44
+ receiver = RubyWarrior::Units::Base.new
45
+ receiver.stubs(:alive?).returns(true)
46
+ receiver.health = 5
47
+ @attack.stubs(:unit).returns(receiver)
48
+ @attack.perform(:backward)
49
+ receiver.health.should == 3
50
+ end
51
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Base do
4
+ before(:each) do
5
+ @unit = stub
6
+ @ability = RubyWarrior::Abilities::Base.new(@unit)
7
+ end
8
+
9
+ it "should have offset for directions" do
10
+ @ability.offset(:forward).should == [1, 0]
11
+ @ability.offset(:right).should == [0, 1]
12
+ @ability.offset(:backward).should == [-1, 0]
13
+ @ability.offset(:left).should == [0, -1]
14
+ end
15
+
16
+ it "should have offset for relative forward/right amounts" do
17
+ @ability.offset(:forward, 2).should == [2, 0]
18
+ @ability.offset(:forward, 2, 1).should == [2, -1]
19
+ @ability.offset(:right, 2, 1).should == [1, 2]
20
+ @ability.offset(:backward, 2, 1).should == [-2, 1]
21
+ @ability.offset(:left, 2, 1).should == [-1, -2]
22
+ end
23
+
24
+ it "should fetch unit at given direction with distance" do
25
+ @ability.expects(:space).with(:right, 3, 1).returns(stub(:unit => 'unit'))
26
+ @ability.unit(:right, 3, 1).should == 'unit'
27
+ end
28
+
29
+ it "should have no description" do
30
+ @ability.description.should be_nil
31
+ end
32
+
33
+ it "should raise an exception if direction isn't recognized" do
34
+ lambda {
35
+ @ability.verify_direction(:foo)
36
+ }.should raise_error("Unknown direction :foo. Should be :forward, :backward, :left or :right.")
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Bind do
4
+ before(:each) do
5
+ @bind = RubyWarrior::Abilities::Bind.new(stub(:say => nil))
6
+ end
7
+
8
+ it "should bind recipient" do
9
+ receiver = RubyWarrior::Units::Base.new
10
+ @bind.stubs(:unit).returns(receiver)
11
+ @bind.perform
12
+ receiver.should be_bound
13
+ end
14
+
15
+ it "should do nothing if no recipient" do
16
+ @bind.stubs(:unit).returns(nil)
17
+ lambda { @bind.perform }.should_not raise_error
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::DirectionOf do
4
+ before(:each) do
5
+ @position = stub
6
+ @distance = RubyWarrior::Abilities::DirectionOf.new(stub(:position => @position, :say => nil))
7
+ end
8
+
9
+ it "should return relative direction of given space" do
10
+ @position.stubs(:relative_direction_of).with(:space).returns(:left)
11
+ @distance.perform(:space).should == :left
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::DirectionOfStairs do
4
+ before(:each) do
5
+ @position = stub
6
+ @distance = RubyWarrior::Abilities::DirectionOfStairs.new(stub(:position => @position, :say => nil))
7
+ end
8
+
9
+ it "should return relative direction of stairs" do
10
+ @position.stubs(:relative_direction_of_stairs).returns(:left)
11
+ @distance.perform.should == :left
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::DistanceOf do
4
+ before(:each) do
5
+ @position = stub
6
+ @distance = RubyWarrior::Abilities::DistanceOf.new(stub(:position => @position, :say => nil))
7
+ end
8
+
9
+ it "should return distance from stairs" do
10
+ @position.stubs(:distance_of).with(:space).returns(5)
11
+ @distance.perform(:space).should == 5
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Explode do
4
+ before(:each) do
5
+ @floor = RubyWarrior::Floor.new
6
+ @floor.width = 2
7
+ @floor.height = 3
8
+ @captive = RubyWarrior::Units::Captive.new
9
+ @floor.add(@captive, 0, 0)
10
+ @explode = RubyWarrior::Abilities::Explode.new(@captive)
11
+ end
12
+
13
+ it "should subtract 100 health from each unit on the floor" do
14
+ unit = RubyWarrior::Units::Base.new
15
+ unit.health = 20
16
+ @floor.add(unit, 0, 1)
17
+ @captive.health = 10
18
+ @explode.perform
19
+ @captive.health.should == -90
20
+ unit.health.should == -80
21
+ end
22
+
23
+ it "should explode when bomb time reaches zero" do
24
+ @captive.health = 10
25
+ @explode.time = 3
26
+ @explode.pass_turn
27
+ @explode.pass_turn
28
+ @captive.health.should == 10
29
+ @explode.pass_turn
30
+ @captive.health.should == -90
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Feel do
4
+ before(:each) do
5
+ @unit = stub(:position => stub, :say => nil)
6
+ @feel = RubyWarrior::Abilities::Feel.new(@unit)
7
+ end
8
+
9
+ it "should get object at position from offset" do
10
+ @unit.position.expects(:relative_space).with(1, 0)
11
+ @feel.perform(:forward)
12
+ end
13
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Form do
4
+ before(:each) do
5
+ @floor = RubyWarrior::Floor.new
6
+ @floor.width = 2
7
+ @floor.height = 3
8
+ @warrior = RubyWarrior::Units::Warrior.new
9
+ @floor.add(@warrior, 0, 0, :east)
10
+ @form = RubyWarrior::Abilities::Form.new(@warrior)
11
+ end
12
+
13
+ it "should form a golem in front of warrior" do
14
+ @form.perform
15
+ @floor.get(1, 0).should be_kind_of(RubyWarrior::Units::Golem)
16
+ end
17
+
18
+ it "should form a golem in given direction" do
19
+ @form.perform(:right)
20
+ @floor.get(0, 1).should be_kind_of(RubyWarrior::Units::Golem)
21
+ end
22
+
23
+ it "should not form golem if space isn't empty" do
24
+ @floor.add(RubyWarrior::Units::Base.new, 1, 0)
25
+ @form.perform(:forward)
26
+ @form.perform(:left)
27
+ @floor.units.size.should == 2
28
+ end
29
+
30
+ it "should reduce warrior's health by half (rounding down) and give it to the golem" do
31
+ @warrior.health = 19
32
+ @form.perform
33
+ @warrior.health.should == 10
34
+ @floor.get(1, 0).max_health.should == 9
35
+ end
36
+
37
+ it "should add passed block as golem's turn block" do
38
+ @passed = nil
39
+ @form.perform(:forward) { |turn| @passed = turn }
40
+ @floor.get(1, 0).play_turn(:turn)
41
+ @passed.should == :turn
42
+ end
43
+
44
+ it "should start in same direction as warrior" do
45
+ @form.perform(:right)
46
+ @floor.get(0, 1).position.direction.should == :east
47
+ end
48
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Health do
4
+ before(:each) do
5
+ @warrior = RubyWarrior::Units::Warrior.new
6
+ @health = RubyWarrior::Abilities::Health.new(@warrior)
7
+ end
8
+
9
+ it "should return the amount of health" do
10
+ @warrior.health = 10
11
+ @health.perform.should == 10
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Listen do
4
+ before(:each) do
5
+ @floor = RubyWarrior::Floor.new
6
+ @floor.width = 2
7
+ @floor.height = 3
8
+ @warrior = RubyWarrior::Units::Warrior.new
9
+ @floor.add(@warrior, 0, 0)
10
+ @listen = RubyWarrior::Abilities::Listen.new(@warrior)
11
+ end
12
+
13
+ it "should return an array of spaces which have units on them besides main unit" do
14
+ @floor.add(RubyWarrior::Units::Base.new, 0, 1)
15
+ @listen.perform.should have(1).record
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Look do
4
+ before(:each) do
5
+ @unit = stub(:position => stub, :say => nil)
6
+ @feel = RubyWarrior::Abilities::Look.new(@unit)
7
+ end
8
+
9
+ it "should get 3 objects at position from offset" do
10
+ @unit.position.expects(:relative_space).with(1, 0).returns(1)
11
+ @unit.position.expects(:relative_space).with(2, 0).returns(2)
12
+ @unit.position.expects(:relative_space).with(3, 0).returns(3)
13
+ @feel.perform(:forward).should == [1, 2, 3]
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Pivot do
4
+ before(:each) do
5
+ @position = stub
6
+ @pivot = RubyWarrior::Abilities::Pivot.new(stub(:position => @position, :say => nil))
7
+ end
8
+
9
+ it "should flip around when not passing arguments" do
10
+ @position.expects(:rotate).with(2)
11
+ @pivot.perform
12
+ end
13
+
14
+ it "should rotate 1 when pivoting right" do
15
+ @position.expects(:rotate).with(1)
16
+ @pivot.perform(:right)
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Rescue do
4
+ before(:each) do
5
+ @warrior = RubyWarrior::Units::Warrior.new
6
+ @rescue = RubyWarrior::Abilities::Rescue.new(@warrior)
7
+ end
8
+
9
+ it "should rescue captive" do
10
+ captive = RubyWarrior::Units::Captive.new
11
+ captive.position = stub
12
+ @rescue.expects(:space).with(:forward).returns(stub(:captive? => true))
13
+ @rescue.expects(:unit).with(:forward).returns(captive)
14
+ @warrior.expects(:earn_points).with(20)
15
+ @rescue.perform
16
+ captive.position.should be_nil
17
+ end
18
+
19
+ it "should do nothing to other unit if not bound" do
20
+ unit = RubyWarrior::Units::Base.new
21
+ unit.position = stub
22
+ @rescue.expects(:space).with(:forward).returns(stub(:captive? => false))
23
+ @rescue.expects(:unit).with(:forward).never
24
+ @warrior.expects(:earn_points).never
25
+ @rescue.perform
26
+ unit.position.should_not be_nil
27
+ end
28
+
29
+ it "should release other unit when bound" do
30
+ unit = RubyWarrior::Units::Base.new
31
+ unit.bind
32
+ unit.position = stub
33
+ @rescue.expects(:space).with(:forward).returns(stub(:captive? => true))
34
+ @rescue.expects(:unit).with(:forward).returns(unit)
35
+ @warrior.expects(:earn_points).never
36
+ @rescue.perform
37
+ unit.should_not be_bound
38
+ unit.position.should_not be_nil
39
+ end
40
+ end