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,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Tower do
4
+ before(:each) do
5
+ @tower = RubyWarrior::Tower.new('path/to/tower')
6
+ end
7
+
8
+ it "should consider last part of path as name" do
9
+ @tower.name.should == 'tower'
10
+ end
11
+
12
+ it "should use name when converting to string" do
13
+ @tower.to_s.should == @tower.name
14
+ end
15
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Turn do
4
+ describe "with actions" do
5
+ before(:each) do
6
+ @turn = RubyWarrior::Turn.new({:walk! => nil, :attack! => nil})
7
+ end
8
+
9
+ it "should have no action performed at first" do
10
+ @turn.action.should be_nil
11
+ end
12
+
13
+ it "should be able to perform action and recall it" do
14
+ @turn.walk!
15
+ @turn.action.should == [:walk!]
16
+ end
17
+
18
+ it "should include arguments passed to action" do
19
+ @turn.walk! :forward
20
+ @turn.action.should == [:walk!, :forward]
21
+ end
22
+
23
+ it "should not be able to call multiple actions per turn" do
24
+ @turn.walk! :forward
25
+ lambda { @turn.attack! }.should raise_error
26
+ end
27
+ end
28
+
29
+ describe "with senses" do
30
+ before(:each) do
31
+ @feel = RubyWarrior::Abilities::Feel.new(Object.new)
32
+ @feel.stubs(:space).returns(Object.new)
33
+ @feel.stubs(:space).with(:backward).returns(Object.new)
34
+ @turn = RubyWarrior::Turn.new({:feel => @feel})
35
+ end
36
+
37
+ it "should be able to call sense with any argument and return expected results" do
38
+ @turn.feel.should == @feel.perform
39
+ @turn.feel(:backward).should == @feel.perform(:backward)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::UI do
4
+ before(:each) do
5
+ @ui = RubyWarrior::UI
6
+ @config = RubyWarrior::Config
7
+ @out = StringIO.new
8
+ @in = StringIO.new
9
+ @config.out_stream = @out
10
+ @config.in_stream = @in
11
+ end
12
+
13
+ it "should add puts to out stream" do
14
+ @ui.puts "hello"
15
+ @out.string.should == "hello\n"
16
+ end
17
+
18
+ it "should add print to out stream without newline" do
19
+ @ui.print "hello"
20
+ @out.string.should == "hello"
21
+ end
22
+
23
+ it "should fetch gets from in stream" do
24
+ @in.puts "bar"
25
+ @in.rewind
26
+ @ui.gets.should == "bar\n"
27
+ end
28
+
29
+ it "should gets should return empty string if no input" do
30
+ @config.in_stream = nil
31
+ @ui.gets.should == ""
32
+ end
33
+
34
+ it "should request text input" do
35
+ @in.puts "bar"
36
+ @in.rewind
37
+ @ui.request("foo").should == "bar"
38
+ @out.string.should == "foo"
39
+ end
40
+
41
+ it "should ask for yes/no and return true when yes" do
42
+ @ui.expects(:request).with('foo? [yn] ').returns('y')
43
+ @ui.ask("foo?").should be_true
44
+ end
45
+
46
+ it "should ask for yes/no and return false when no" do
47
+ @ui.stubs(:request).returns('n')
48
+ @ui.ask("foo?").should be_false
49
+ end
50
+
51
+ it "should ask for yes/no and return false for any input" do
52
+ @ui.stubs(:request).returns('aklhasdf')
53
+ @ui.ask("foo?").should be_false
54
+ end
55
+
56
+ it "should present multiple options and return selected one" do
57
+ @ui.expects(:request).with(includes('item')).returns('2')
58
+ @ui.choose('item', [:foo, :bar, :test]).should == :bar
59
+ @out.string.should include('[1] foo')
60
+ @out.string.should include('[2] bar')
61
+ @out.string.should include('[3] test')
62
+ end
63
+
64
+ it "choose should accept array as option" do
65
+ @ui.stubs(:request).returns('3')
66
+ @ui.choose('item', [:foo, :bar, [:tower, 'easy']]).should == :tower
67
+ @out.string.should include('[3] easy')
68
+ end
69
+
70
+ it "choose should return option without prompt if only one item" do
71
+ @ui.expects(:puts).never
72
+ @ui.expects(:gets).never
73
+ @ui.stubs(:request).returns('3')
74
+ @ui.choose('item', [:foo]).should == :foo
75
+ end
76
+
77
+ it "choose should return first value in array of option if only on item" do
78
+ @ui.choose('item', [[:foo, :bar]]).should == :foo
79
+ end
80
+
81
+ it "should delay after puts when specified" do
82
+ @config.delay = 1.3
83
+ @ui.expects(:puts).with("foo")
84
+ @ui.expects(:sleep).with(1.3)
85
+ @ui.puts_with_delay("foo")
86
+ end
87
+
88
+ it "should not delay puts when delay isn't specified" do
89
+ @ui.expects(:puts).with("foo")
90
+ @ui.expects(:sleep).never
91
+ @ui.puts_with_delay("foo")
92
+ end
93
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Units::Archer do
4
+ before(:each) do
5
+ @archer = RubyWarrior::Units::Archer.new
6
+ end
7
+
8
+ it "should have look and shoot abilities" do
9
+ @archer.abilities.keys.to_set.should == [:shoot!, :look].to_set
10
+ end
11
+
12
+ it "should have shoot power of 3" do
13
+ @archer.shoot_power.should == 3
14
+ end
15
+
16
+ it "should have 7 max health" do
17
+ @archer.max_health.should == 7
18
+ end
19
+
20
+ it "should appear as a on map" do
21
+ @archer.character.should == "a"
22
+ end
23
+ end
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Units::Base do
4
+ before(:each) do
5
+ @unit = RubyWarrior::Units::Base.new
6
+ end
7
+
8
+ it "should have an attack power which defaults to zero" do
9
+ @unit.attack_power.should be_zero
10
+ end
11
+
12
+ it "should consider itself dead when no position" do
13
+ @unit.position.should be_nil
14
+ @unit.should_not be_alive
15
+ end
16
+
17
+ it "should consider itself alive with position" do
18
+ @unit.position = stub
19
+ @unit.should be_alive
20
+ end
21
+
22
+ it "should default max health to 10" do
23
+ @unit.max_health.should be_zero
24
+ end
25
+
26
+ it "should do nothing when earning points" do
27
+ lambda { @unit.earn_points(10) }.should_not raise_error
28
+ end
29
+
30
+ it "should default health to max health" do
31
+ @unit.stubs(:max_health).returns(10)
32
+ @unit.health.should == 10
33
+ end
34
+
35
+ it "should subtract health when taking damage" do
36
+ @unit.stubs(:max_health).returns(10)
37
+ @unit.take_damage(3)
38
+ @unit.health.should == 7
39
+ end
40
+
41
+ it "should do nothing when taking damage if health isn't set" do
42
+ lambda { @unit.take_damage(3) }.should_not raise_error
43
+ end
44
+
45
+ it "should set position to nil when running out of health" do
46
+ @unit.position = stub
47
+ @unit.stubs(:max_health).returns(10)
48
+ @unit.take_damage(10)
49
+ @unit.position.should be_nil
50
+ end
51
+
52
+ it "should print out line with name when speaking" do
53
+ RubyWarrior::UI.expects(:puts_with_delay).with("[base.name.capitalize] foo")
54
+ @unit.say "foo"
55
+ end
56
+
57
+ it "should return name in to_s" do
58
+ @unit.name.should match /base/
59
+ @unit.to_s.should match /base/
60
+ end
61
+
62
+ it "should prepare turn by calling play_turn with next turn object" do
63
+ @unit.stubs(:next_turn).returns('next_turn')
64
+ @unit.expects(:play_turn).with('next_turn')
65
+ @unit.prepare_turn
66
+ end
67
+
68
+ it "should perform action when calling perform on turn" do
69
+ @unit.position = stub
70
+ RubyWarrior::Abilities::Walk.any_instance.expects(:perform).with(:backward)
71
+ @unit.add_abilities(:walk!)
72
+ turn = stub(:action => [:walk!, :backward])
73
+ @unit.stubs(:next_turn).returns(turn)
74
+ @unit.prepare_turn
75
+ @unit.perform_turn
76
+ end
77
+
78
+ it "should not perform action when dead (no position)" do
79
+ @unit.position = nil
80
+ RubyWarrior::Abilities::Walk.any_instance.stubs(:perform).raises("action should not be called")
81
+ @unit.add_abilities(:walk!)
82
+ turn = stub(:action => [:walk!, :backward])
83
+ @unit.stubs(:next_turn).returns(turn)
84
+ @unit.prepare_turn
85
+ @unit.perform_turn
86
+ end
87
+
88
+ it "should not raise an exception when calling perform_turn when there's no action" do
89
+ @unit.prepare_turn
90
+ lambda { @unit.perform_turn }.should_not raise_error
91
+ end
92
+
93
+ it "should pass abilities to new turn when calling next_turn" do
94
+ RubyWarrior::Turn.expects(:new).with(:walk! => nil, :attack! => nil, :feel => nil).returns('turn')
95
+ @unit.stubs(:abilities).returns(:walk! => nil, :attack! => nil, :feel => nil)
96
+ @unit.next_turn.should == 'turn'
97
+ end
98
+
99
+ it "should add ability" do
100
+ RubyWarrior::Abilities::Walk.expects(:new).with(@unit).returns('walk')
101
+ @unit.add_abilities(:walk!)
102
+ @unit.abilities.should == { :walk! => 'walk' }
103
+ end
104
+
105
+ it "should appear as question mark on map" do
106
+ @unit.character.should == "?"
107
+ end
108
+
109
+ it "should be released from bonds when taking damage" do
110
+ @unit.stubs(:max_health).returns(10)
111
+ @unit.bind
112
+ @unit.should be_bound
113
+ @unit.take_damage(2)
114
+ @unit.should_not be_bound
115
+ end
116
+
117
+ it "should be released from bonds when calling release" do
118
+ @unit.bind
119
+ @unit.unbind
120
+ @unit.should_not be_bound
121
+ end
122
+
123
+ it "should not perform action when bound" do
124
+ @unit.position = stub
125
+ @unit.bind
126
+ RubyWarrior::Abilities::Walk.any_instance.stubs(:perform).raises("action should not be called")
127
+ @unit.add_abilities(:walk!)
128
+ turn = stub(:action => [:walk!, :backward])
129
+ @unit.stubs(:next_turn).returns(turn)
130
+ @unit.prepare_turn
131
+ @unit.perform_turn
132
+ end
133
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Units::Captive do
4
+ before(:each) do
5
+ @captive = RubyWarrior::Units::Captive.new
6
+ end
7
+
8
+ it "should have 1 max health" do
9
+ @captive.max_health.should == 1
10
+ end
11
+
12
+ it "should appear as C on map" do
13
+ @captive.character.should == "C"
14
+ end
15
+
16
+ it "should be bound by default" do
17
+ @captive.should be_bound
18
+ end
19
+
20
+ it "should not have explode ability by default (this should be added when needed)" do
21
+ @captive.abilities.should_not include(:explode!)
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Units::Golem do
4
+ before(:each) do
5
+ @golem = RubyWarrior::Units::Golem.new
6
+ end
7
+
8
+ it "should execute turn proc when playing turn" do
9
+ proc = Object.new
10
+ proc.expects(:call).with(:turn)
11
+ @golem.turn = proc
12
+ @golem.play_turn(:turn)
13
+ end
14
+
15
+ it "should set max health and update current health" do
16
+ @golem.max_health = 10
17
+ @golem.max_health.should == 10
18
+ @golem.health.should == 10
19
+ end
20
+
21
+ it "should have attack power of 3" do
22
+ @golem.attack_power.should == 3
23
+ end
24
+
25
+ it "should appear as G on map" do
26
+ @golem.character.should == "G"
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Units::Sludge do
4
+ before(:each) do
5
+ @sludge = RubyWarrior::Units::Sludge.new
6
+ end
7
+
8
+ it "should have attack action" do
9
+ @sludge.abilities.keys.should include(:attack!)
10
+ end
11
+
12
+ it "should have feel sense" do
13
+ @sludge.abilities.keys.should include(:feel)
14
+ end
15
+
16
+ it "should have attack power of 3" do
17
+ @sludge.attack_power.should == 3
18
+ end
19
+
20
+ it "should have 12 max health" do
21
+ @sludge.max_health.should == 12
22
+ end
23
+
24
+ it "should appear as s on map" do
25
+ @sludge.character.should == "s"
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyWarrior::Units::ThickSludge do
4
+ before(:each) do
5
+ @sludge = RubyWarrior::Units::ThickSludge.new
6
+ end
7
+
8
+ it "should have 24 max health" do
9
+ @sludge.max_health.should == 24
10
+ end
11
+
12
+ it "should appear as S on map" do
13
+ @sludge.character.should == "S"
14
+ end
15
+
16
+ it "should have the name of 'Thick Sludge'" do
17
+ @sludge.name.should == "Thick sludge"
18
+ end
19
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ class Player
4
+ def turn(warrior)
5
+ end
6
+ end
7
+
8
+ describe RubyWarrior::Units::Warrior do
9
+ before(:each) do
10
+ @warrior = RubyWarrior::Units::Warrior.new
11
+ end
12
+
13
+ it "should default name to warrior" do
14
+ @warrior.name.should == "Warrior"
15
+ @warrior.name = ''
16
+ @warrior.name.should == "Warrior"
17
+ end
18
+
19
+ it "should be able to set name" do
20
+ @warrior.name = "Joe"
21
+ @warrior.name.should == "Joe"
22
+ @warrior.to_s.should == "Joe"
23
+ end
24
+
25
+ it "should have 20 max health" do
26
+ @warrior.max_health.should == 20
27
+ end
28
+
29
+ it "should have 0 score at beginning and be able to earn points" do
30
+ @warrior.score.should be_zero
31
+ @warrior.earn_points(5)
32
+ @warrior.score.should == 5
33
+ end
34
+
35
+ it "should call player.play_turn and pass turn to player" do
36
+ player = stub
37
+ player.expects(:play_turn).with('turn')
38
+ @warrior.stubs(:player).returns(player)
39
+ @warrior.play_turn('turn')
40
+ end
41
+
42
+ it "should call Player.new the first time loading player, and return same object next time" do
43
+ Player.expects(:new).returns('player').times(1)
44
+ 2.times do
45
+ @warrior.player.should == 'player'
46
+ end
47
+ end
48
+
49
+ it "should have an attack power of 5" do
50
+ @warrior.attack_power.should == 5
51
+ end
52
+
53
+ it "should have an shoot power of 3" do
54
+ @warrior.shoot_power.should == 3
55
+ end
56
+
57
+ it "should appear as @ on map" do
58
+ @warrior.character.should == "@"
59
+ end
60
+
61
+ it "should be able to add golem abilities which are used on base golem" do
62
+ @warrior.add_golem_abilities :walk!
63
+ @warrior.base_golem.abilities.keys.should == [:walk!]
64
+ end
65
+ end