rubywarrior 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/CHANGELOG.rdoc +3 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +170 -0
  4. data/Rakefile +21 -0
  5. data/bin/rubywarrior +5 -0
  6. data/features/command_options.feature +46 -0
  7. data/features/levels.feature +51 -0
  8. data/features/profiles.feature +56 -0
  9. data/features/step_definitions/common_steps.rb +19 -0
  10. data/features/step_definitions/interaction_steps.rb +65 -0
  11. data/features/support/env.rb +12 -0
  12. data/features/support/mockio.rb +57 -0
  13. data/features/towers.feature +14 -0
  14. data/lib/ruby_warrior.rb +44 -0
  15. data/lib/ruby_warrior/abilities/attack.rb +24 -0
  16. data/lib/ruby_warrior/abilities/base.rb +36 -0
  17. data/lib/ruby_warrior/abilities/bind.rb +19 -0
  18. data/lib/ruby_warrior/abilities/direction_of.rb +13 -0
  19. data/lib/ruby_warrior/abilities/direction_of_stairs.rb +13 -0
  20. data/lib/ruby_warrior/abilities/distance.rb +13 -0
  21. data/lib/ruby_warrior/abilities/explode.rb +16 -0
  22. data/lib/ruby_warrior/abilities/feel.rb +13 -0
  23. data/lib/ruby_warrior/abilities/health.rb +13 -0
  24. data/lib/ruby_warrior/abilities/listen.rb +15 -0
  25. data/lib/ruby_warrior/abilities/look.rb +15 -0
  26. data/lib/ruby_warrior/abilities/pivot.rb +16 -0
  27. data/lib/ruby_warrior/abilities/rescue.rb +23 -0
  28. data/lib/ruby_warrior/abilities/rest.rb +20 -0
  29. data/lib/ruby_warrior/abilities/shoot.rb +23 -0
  30. data/lib/ruby_warrior/abilities/walk.rb +20 -0
  31. data/lib/ruby_warrior/config.rb +22 -0
  32. data/lib/ruby_warrior/core_additions.rb +25 -0
  33. data/lib/ruby_warrior/floor.rb +71 -0
  34. data/lib/ruby_warrior/game.rb +193 -0
  35. data/lib/ruby_warrior/level.rb +119 -0
  36. data/lib/ruby_warrior/level_loader.rb +56 -0
  37. data/lib/ruby_warrior/player_generator.rb +41 -0
  38. data/lib/ruby_warrior/position.rb +80 -0
  39. data/lib/ruby_warrior/profile.rb +104 -0
  40. data/lib/ruby_warrior/runner.rb +33 -0
  41. data/lib/ruby_warrior/space.rb +63 -0
  42. data/lib/ruby_warrior/tower.rb +14 -0
  43. data/lib/ruby_warrior/turn.rb +38 -0
  44. data/lib/ruby_warrior/ui.rb +54 -0
  45. data/lib/ruby_warrior/units/archer.rb +34 -0
  46. data/lib/ruby_warrior/units/base.rb +95 -0
  47. data/lib/ruby_warrior/units/captive.rb +30 -0
  48. data/lib/ruby_warrior/units/sludge.rb +30 -0
  49. data/lib/ruby_warrior/units/thick_sludge.rb +13 -0
  50. data/lib/ruby_warrior/units/warrior.rb +58 -0
  51. data/lib/ruby_warrior/units/wizard.rb +34 -0
  52. data/spec/fixtures/short-tower/level_001.rb +15 -0
  53. data/spec/fixtures/short-tower/level_002.rb +15 -0
  54. data/spec/fixtures/walking_player.rb +5 -0
  55. data/spec/ruby_warrior/abilities/attack_spec.rb +51 -0
  56. data/spec/ruby_warrior/abilities/base_spec.rb +24 -0
  57. data/spec/ruby_warrior/abilities/bind_spec.rb +19 -0
  58. data/spec/ruby_warrior/abilities/direction_of_spec.rb +13 -0
  59. data/spec/ruby_warrior/abilities/direction_of_stairs_spec.rb +13 -0
  60. data/spec/ruby_warrior/abilities/distance_spec.rb +13 -0
  61. data/spec/ruby_warrior/abilities/explode_spec.rb +21 -0
  62. data/spec/ruby_warrior/abilities/feel_spec.rb +13 -0
  63. data/spec/ruby_warrior/abilities/health_spec.rb +13 -0
  64. data/spec/ruby_warrior/abilities/listen_spec.rb +17 -0
  65. data/spec/ruby_warrior/abilities/look_spec.rb +15 -0
  66. data/spec/ruby_warrior/abilities/pivot_spec.rb +18 -0
  67. data/spec/ruby_warrior/abilities/rescue_spec.rb +40 -0
  68. data/spec/ruby_warrior/abilities/rest_spec.rb +29 -0
  69. data/spec/ruby_warrior/abilities/shoot_spec.rb +22 -0
  70. data/spec/ruby_warrior/abilities/walk_spec.rb +25 -0
  71. data/spec/ruby_warrior/floor_spec.rb +81 -0
  72. data/spec/ruby_warrior/game_spec.rb +119 -0
  73. data/spec/ruby_warrior/level_loader_spec.rb +54 -0
  74. data/spec/ruby_warrior/level_spec.rb +203 -0
  75. data/spec/ruby_warrior/player_generator_spec.rb +12 -0
  76. data/spec/ruby_warrior/position_spec.rb +103 -0
  77. data/spec/ruby_warrior/profile_spec.rb +144 -0
  78. data/spec/ruby_warrior/space_spec.rb +165 -0
  79. data/spec/ruby_warrior/tower_spec.rb +15 -0
  80. data/spec/ruby_warrior/turn_spec.rb +42 -0
  81. data/spec/ruby_warrior/ui_spec.rb +93 -0
  82. data/spec/ruby_warrior/units/archer_spec.rb +23 -0
  83. data/spec/ruby_warrior/units/base_spec.rb +133 -0
  84. data/spec/ruby_warrior/units/captive_spec.rb +34 -0
  85. data/spec/ruby_warrior/units/sludge_spec.rb +27 -0
  86. data/spec/ruby_warrior/units/thick_sludge_spec.rb +19 -0
  87. data/spec/ruby_warrior/units/warrior_spec.rb +60 -0
  88. data/spec/ruby_warrior/units/wizard_spec.rb +23 -0
  89. data/spec/spec_helper.rb +10 -0
  90. data/templates/README.erb +20 -0
  91. data/templates/player.rb +5 -0
  92. data/towers/beginner/level_001.rb +16 -0
  93. data/towers/beginner/level_002.rb +18 -0
  94. data/towers/beginner/level_003.rb +21 -0
  95. data/towers/beginner/level_004.rb +18 -0
  96. data/towers/beginner/level_005.rb +22 -0
  97. data/towers/beginner/level_006.rb +19 -0
  98. data/towers/beginner/level_007.rb +18 -0
  99. data/towers/beginner/level_008.rb +21 -0
  100. data/towers/beginner/level_009.rb +20 -0
  101. data/towers/intermediate/level_001.rb +18 -0
  102. data/towers/intermediate/level_002.rb +20 -0
  103. data/towers/intermediate/level_003.rb +23 -0
  104. data/towers/intermediate/level_004.rb +24 -0
  105. data/towers/intermediate/level_005.rb +19 -0
  106. data/towers/intermediate/level_006.rb +24 -0
  107. metadata +167 -0
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RubyWarrior::Units::ThickSludge 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 explode when bomb time reaches 0 and unbind itself" do
21
+ @captive.bomb_time = 3
22
+ @captive.play_turn(stub)
23
+ @captive.play_turn(stub)
24
+ @captive.should be_bound
25
+ turn = stub
26
+ turn.expects(:explode!)
27
+ @captive.play_turn(turn)
28
+ @captive.should_not be_bound
29
+ end
30
+
31
+ it "should have explode ability" do
32
+ @captive.abilities.keys.should include(:explode!)
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../../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 File.dirname(__FILE__) + '/../../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,60 @@
1
+ require File.dirname(__FILE__) + '/../../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
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RubyWarrior::Units::Wizard do
4
+ before(:each) do
5
+ @wizard = RubyWarrior::Units::Wizard.new
6
+ end
7
+
8
+ it "should have look and shoot abilities" do
9
+ @wizard.abilities.keys.to_set.should == [:shoot!, :look].to_set
10
+ end
11
+
12
+ it "should have shoot power of 11" do
13
+ @wizard.shoot_power.should == 11
14
+ end
15
+
16
+ it "should have 3 max health" do
17
+ @wizard.max_health.should == 3
18
+ end
19
+
20
+ it "should appear as w on map" do
21
+ @wizard.character.should == "w"
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.dirname(__FILE__) + '/../lib/ruby_warrior'
4
+
5
+ Spec::Runner.configure do |config|
6
+ config.mock_with :mocha
7
+ config.before(:each) do
8
+ RubyWarrior::Config.reset
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ Level <%= level.number %>
2
+
3
+ <%= level.description %>
4
+
5
+ Tip: <%= level.tip %>
6
+
7
+ <%= level.floor.character -%>
8
+
9
+ > = Stairs
10
+ <%- for unit in level.floor.unique_units -%>
11
+ <%= unit.character %> = <%= unit.name %> (<%= unit.max_health %> HP)
12
+ <%- end -%>
13
+
14
+
15
+ Available Abilities:
16
+ <%- level.warrior.abilities.each do |name, ability| -%>
17
+
18
+ warrior.<%= name %>
19
+ <%= ability.description %>
20
+ <%- end -%>
@@ -0,0 +1,5 @@
1
+ class Player
2
+ def play_turn(warrior)
3
+ # add your code here
4
+ end
5
+ end
@@ -0,0 +1,16 @@
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
+
9
+ time_bonus 15
10
+ ace_score 10
11
+ size 8, 1
12
+ stairs 7, 0
13
+
14
+ warrior 0, 0, :east do |u|
15
+ u.add_abilities :walk!
16
+ end
@@ -0,0 +1,18 @@
1
+ # --------
2
+ # |@ s >|
3
+ # --------
4
+
5
+ description "It is too dark to see anything, but you smell sludge nearby."
6
+ tip "Use warrior.feel.empty? to see if there's anything in front of you, and warrior.attack! to fight it. Remember, you can only do one action (ending in !) per turn."
7
+ clue "Add an if/else condition using warrior.feel.empty? to decide whether to warrior.attack! or warrior.walk!."
8
+
9
+ time_bonus 20
10
+ ace_score 26
11
+ size 8, 1
12
+ stairs 7, 0
13
+
14
+ warrior 0, 0, :east do |u|
15
+ u.add_abilities :feel, :attack!
16
+ end
17
+
18
+ unit :sludge, 4, 0, :west
@@ -0,0 +1,21 @@
1
+ # ---------
2
+ # |@ s ss s>|
3
+ # ---------
4
+
5
+ description "The air feels thicker than before. There must be a horde of sludge."
6
+ tip "Be careful not to die! Use warrior.health to keep an eye on your health, and warrior.rest! to earn 10% of max health back."
7
+ clue "When there's no enemy ahead of you, call warrior.rest! until health is full before walking forward."
8
+
9
+ time_bonus 35
10
+ ace_score 71
11
+ size 9, 1
12
+ stairs 8, 0
13
+
14
+ warrior 0, 0, :east do |u|
15
+ u.add_abilities :health, :rest!
16
+ end
17
+
18
+ unit :sludge, 2, 0, :west
19
+ unit :sludge, 4, 0, :west
20
+ unit :sludge, 5, 0, :west
21
+ unit :sludge, 7, 0, :west
@@ -0,0 +1,18 @@
1
+ # -------
2
+ # |@ Sa S>|
3
+ # -------
4
+
5
+ description "You can hear bow strings being stretched."
6
+ tip "No new abilities this time, but you must be careful not to rest while taking damage. Save a @health instance variable and compare it on each turn to see if you're taking damage."
7
+ clue "Set @health to your current health at the end of the turn. If this is greater than your current health next turn then you know you're taking damage and shouldn't rest."
8
+
9
+ time_bonus 45
10
+ ace_score 90
11
+ size 7, 1
12
+ stairs 6, 0
13
+
14
+ warrior 0, 0, :east
15
+
16
+ unit :thick_sludge, 2, 0, :west
17
+ unit :archer, 3, 0, :west
18
+ unit :thick_sludge, 5, 0, :west
@@ -0,0 +1,22 @@
1
+ # -------
2
+ # |@ CaaSC|
3
+ # -------
4
+
5
+ description "You hear cries for help. Captives must need rescuing."
6
+ tip "Use warrior.feel.captive? to see if there's a captive, and warrior.rescue! to rescue him. Don't attack captives."
7
+ clue "Don't forget to constantly check if you're taking damage and rest until your health is full if you aren't taking damage."
8
+
9
+ time_bonus 45
10
+ ace_score 123
11
+ size 7, 1
12
+ stairs 6, 0
13
+
14
+ warrior 0, 0, :east do |u|
15
+ u.add_abilities :rescue!
16
+ end
17
+
18
+ unit :captive, 2, 0, :west
19
+ unit :archer, 3, 0, :west
20
+ unit :archer, 4, 0, :west
21
+ unit :thick_sludge, 5, 0, :west
22
+ unit :captive, 6, 0, :west
@@ -0,0 +1,19 @@
1
+ # --------
2
+ # |C @ S aa|
3
+ # --------
4
+
5
+ description "The wall behind you feels a bit further away in this room. And you hear more cries for help."
6
+ tip "You can walk backward by passing ':backward' as an argument to walk!. Same goes for feel, rescue! and attack!."
7
+ clue "Walk backward if you are taking damage from afar and do not have enough health to attack. You may also want to consider walking backward until warrior.feel(:backward).wall?."
8
+
9
+ time_bonus 55
10
+ ace_score 110
11
+ size 8, 1
12
+ stairs 7, 0
13
+
14
+ warrior 2, 0, :east
15
+
16
+ unit :captive, 0, 0, :east
17
+ unit :thick_sludge, 4, 0, :west
18
+ unit :archer, 6, 0, :west
19
+ unit :archer, 7, 0, :west
@@ -0,0 +1,18 @@
1
+ # ------
2
+ # |>a S @|
3
+ # ------
4
+
5
+ description "You feel a wall right in front of you and an opening behind you."
6
+ tip "You are not as effective at attacking backward. Use warrior.feel.wall? and warrior.pivot! to turn around."
7
+
8
+ time_bonus 30
9
+ ace_score 50
10
+ size 6, 1
11
+ stairs 0, 0
12
+
13
+ warrior 5, 0, :east do |u|
14
+ u.add_abilities :pivot!
15
+ end
16
+
17
+ unit :archer, 1, 0, :east
18
+ unit :thick_sludge, 3, 0, :east
@@ -0,0 +1,21 @@
1
+ # -------
2
+ # |@ Cww>|
3
+ # -------
4
+
5
+ description "You hear the mumbling of wizards. Beware of their deadly wands! Good thing you found a bow."
6
+ tip "Use warrior.look to determine your surroundings, and warrior.shoot! to fire an arrow."
7
+ clue "Wizards are deadly but low in health. Kill them before they have time to attack."
8
+
9
+ time_bonus 20
10
+ ace_score 46
11
+ size 6, 1
12
+ stairs 5, 0
13
+
14
+ warrior 0, 0, :east do |u|
15
+ u.add_abilities :look
16
+ u.add_abilities :shoot!
17
+ end
18
+
19
+ unit :captive, 2, 0, :west
20
+ unit :wizard, 3, 0, :west
21
+ unit :wizard, 4, 0, :west
@@ -0,0 +1,20 @@
1
+ # -----------
2
+ # |>Ca @ S wC|
3
+ # -----------
4
+
5
+ description "Time to hone your skills and apply all of the abilities that you have learned."
6
+ tip "Watch your back."
7
+ clue "Don't just keep shooting the bow while you are being attacked from behind."
8
+
9
+ time_bonus 40
10
+ ace_score 100
11
+ size 11, 1
12
+ stairs 0, 0
13
+
14
+ warrior 5, 0, :east
15
+
16
+ unit :captive, 1, 0, :east
17
+ unit :archer, 2, 0, :east
18
+ unit :thick_sludge, 7, 0, :west
19
+ unit :wizard, 9, 0, :west
20
+ unit :captive, 10, 0, :west
@@ -0,0 +1,18 @@
1
+ # ------
2
+ # | |
3
+ # |@ |
4
+ # | |
5
+ # | > |
6
+ # ------
7
+
8
+ description "Silence. The room feels large, but empty. Luckily you have a map of this tower to help find the stairs."
9
+ tip "Use warrior.direction_of_stairs to determine which direction stairs are located. Pass this to warrior.walk! to walk in that direction."
10
+
11
+ time_bonus 20
12
+ ace_score 19
13
+ size 6, 4
14
+ stairs 2, 3
15
+
16
+ warrior 0, 1, :east do |u|
17
+ u.add_abilities :walk!, :feel, :direction_of_stairs
18
+ end
@@ -0,0 +1,20 @@
1
+ # ----
2
+ # |@s |
3
+ # | sS>|
4
+ # ----
5
+
6
+ description "Another large room, but with several enemies blocking your way to the stairs."
7
+ tip "Just like walking, you can attack! and feel in multiple directions (:forward, :left, :right, :backward)."
8
+ clue "Call warrior.feel(direction).enemy? in each direction to make sure there isn't an enemy beside you (attack if there is). Call warrior.rest! if you're low and health when there's no enemies around."
9
+
10
+ time_bonus 40
11
+ ace_score 84
12
+ size 4, 2
13
+ stairs 3, 1
14
+
15
+ warrior 0, 0, :east do |u|
16
+ u.add_abilities :attack!, :health, :rest!
17
+ end
18
+ unit :sludge, 1, 0, :west
19
+ unit :thick_sludge, 2, 1, :west
20
+ unit :sludge, 1, 1, :north