Skip to content

Commit

Permalink
adding level 4 with thick sludge
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jul 16, 2008
1 parent a5b9dbd commit ded61e4
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 7 deletions.
4 changes: 1 addition & 3 deletions TODO
@@ -1,12 +1,10 @@
Primary
- fill level readme adding more info about available abilities and units on level
- make sure profile only receives abilities from warrior on current level, not when building next level


Abilities
- add captives
- add light & look abilities
- add shoot ability
- add light ability
- add listen ability
- add throw ability

Expand Down
1 change: 1 addition & 0 deletions lib/ruby_warrior.rb
Expand Up @@ -16,6 +16,7 @@
require 'ruby_warrior/units/warrior'
require 'ruby_warrior/units/sludge'
require 'ruby_warrior/units/archer'
require 'ruby_warrior/units/thick_sludge'

require 'ruby_warrior/abilities/base'
require 'ruby_warrior/abilities/walk'
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_warrior/abilities/base.rb
Expand Up @@ -20,8 +20,8 @@ def space(direction, amount = 1)
@unit.position.relative_space(*offset(direction, amount))
end

def unit(direction)
space(direction).unit
def unit(direction, amount = 1)
space(direction, amount).unit
end

def damage(receiver, amount)
Expand Down
9 changes: 8 additions & 1 deletion lib/ruby_warrior/level_loader.rb
Expand Up @@ -28,7 +28,7 @@ def stairs(x, y)
end

def unit(unit, x, y, facing = :north)
unit = eval("Units::#{unit.to_s.capitalize}").new unless unit.kind_of? Units::Base
unit = unit_to_constant(unit).new unless unit.kind_of? Units::Base
@floor.add(unit, x, y, facing)
yield unit if block_given?
unit
Expand All @@ -37,5 +37,12 @@ def unit(unit, x, y, facing = :north)
def warrior(*args, &block)
@level.setup_warrior unit(Units::Warrior.new, *args, &block)
end

private

def unit_to_constant(name)
camel = name.to_s.split('_').map { |s| s.capitalize }.join
eval("Units::#{camel}")
end
end
end
2 changes: 1 addition & 1 deletion lib/ruby_warrior/units/archer.rb
Expand Up @@ -7,7 +7,7 @@ def initialize

def play_turn(turn)
[:forward, :left, :right].each do |direction|
look(direction).each do |space|
turn.look(direction).each do |space|
if space.warrior?
turn.shoot!(direction)
return
Expand Down
9 changes: 9 additions & 0 deletions lib/ruby_warrior/units/thick_sludge.rb
@@ -0,0 +1,9 @@
module RubyWarrior
module Units
class ThickSludge < Sludge
def max_health
24
end
end
end
end
5 changes: 5 additions & 0 deletions spec/ruby_warrior/abilities/base_spec.rb
Expand Up @@ -12,4 +12,9 @@
@ability.offset(:back).should == [-1, 0]
@ability.offset(:left).should == [0, -1]
end

it "should fetch unit at given direction with distance" do
@ability.expects(:space).with(:right, 3).returns(stub(:unit => 'unit'))
@ability.unit(:right, 3).should == 'unit'
end
end
4 changes: 4 additions & 0 deletions spec/ruby_warrior/level_loader_spec.rb
Expand Up @@ -33,6 +33,10 @@
end
end

it "should be able to add multi-word units" do
lambda { @loader.unit :thick_sludge, 1, 2 }.should_not raise_error
end

it "should build warrior from profile" do
@loader.warrior 1, 2 do |unit|
unit.should be_kind_of(RubyWarrior::Units::Warrior)
Expand Down
11 changes: 11 additions & 0 deletions spec/ruby_warrior/units/thick_sludge_spec.rb
@@ -0,0 +1,11 @@
require File.dirname(__FILE__) + '/../../spec_helper'

describe RubyWarrior::Units::ThickSludge do
before(:each) do
@sludge = RubyWarrior::Units::ThickSludge.new
end

it "should have 24 max health" do
@sludge.max_health.should == 24
end
end
16 changes: 16 additions & 0 deletions towers/beginner/level_004.rb
@@ -0,0 +1,16 @@
# +----------+
# |@ T A S ^|
# +----------+

description "You can hear bow strings being stretched."
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."

time_bonus 45
size 7, 1
stairs 6, 0

warrior 0, 0, :east

unit :thick_sludge, 2, 0, :west
unit :archer, 3, 0, :west
unit :thick_sludge, 5, 0, :west

0 comments on commit ded61e4

Please sign in to comment.