diff options
| -rw-r--r-- | hex_engine.rb | 20 | ||||
| -rw-r--r-- | rooms.rb | 53 | 
2 files changed, 46 insertions, 27 deletions
diff --git a/hex_engine.rb b/hex_engine.rb index 3f3dbbc..34b80b6 100644 --- a/hex_engine.rb +++ b/hex_engine.rb @@ -118,25 +118,9 @@ class Hex < Engine      @messages.push(message)    end -  def update_with_bonus current, update, bonus -    if update < 0 -      current + [update + bonus, 0].min -    else -      current + update -    end -  end - -  def update_health health -    @health = update_with_bonus @health, health, @magic_armor -  end - -  def update_endurance endurance -    @endurance = update_with_bonus @endurance, endurance, @magic_weapon -  end -    def update_hex health, endurance, xp -    update_health health -    update_endurance endurance +    @health += health +    @endurance += endurance      @xp += xp    end @@ -4,6 +4,18 @@ module Rooms        @engine = engine      end +    def damage_with_bonus damage, bonus +      [damage - bonus, 0].max +    end + +    def health_damage damage +      damage_with_bonus damage, @engine.magic_armor +    end + +    def endurance_damage damage +      damage_with_bonus damage, @engine.magic_weapon +    end +      def resolve command        @command = command        if @engine.state == 'invalid' @@ -161,6 +173,11 @@ module Rooms    end    class Empty < Room +    def initialize engine +      super engine +      @endurance_damage = endurance_damage 1 +    end +      def instant_resolve        false      end @@ -170,7 +187,7 @@ module Rooms        when 'r'          @engine.update_hex 1, 3, 0        when 's' -        @engine.update_hex 3, -1, 0 +        @engine.update_hex 3, -@endurance_damage, 0        when 'm'        else          do_invalid @@ -195,7 +212,7 @@ module Rooms      def options        [          'rest (+1 H, +3 E)', -        'scavenge for food (+3 H, -1 E)' +        "scavenge for food (+3 H, #{-@endurance_damage} E)"        ]      end @@ -205,6 +222,12 @@ module Rooms    end    class Trap < Room +    def initialize engine +      super engine +      @health_damage = health_damage @engine.level +      @endurance_damage = endurance_damage @engine.level +    end +      def instant_resolve        false      end @@ -212,9 +235,9 @@ module Rooms      def do_resolve        case @command        when 't' -        @engine.update_hex -@engine.level, 0, 0 +        @engine.update_hex -@health_damage, 0, 0        when 'd' -        @engine.update_hex 0, -@engine.level, 0 +        @engine.update_hex 0, -@endurance_damage, 0        else          do_invalid        end @@ -235,8 +258,8 @@ module Rooms      def options        [ -        "trigger trap (-#{@engine.level} H)", -        "disable trap (-#{@engine.level} E)" +        "trigger trap (#{-@health_damage} H)", +        "disable trap (#{-@endurance_damage} E)"        ]      end @@ -246,6 +269,12 @@ module Rooms    end    class Monster < Room +    def initialize engine +      super engine +      @health_damage = health_damage @engine.level +      @endurance_damage = endurance_damage @engine.level +    end +      def instant_resolve        false      end @@ -254,7 +283,7 @@ module Rooms        case @command        when 'r'        when 'f' -        @engine.update_hex -@engine.level, -@engine.level, @engine.level +        @engine.update_hex -@health_damage, -@endurance_damage, @engine.level        else          do_invalid        end @@ -276,7 +305,7 @@ module Rooms      def options        [          "run away", -        "fight (-#{@engine.level} H, -#{@engine.level} E, #{@engine.level} X)" +        "fight (#{-@health_damage} H, #{-@endurance_damage} E, #{@engine.level} X)"        ]      end @@ -343,12 +372,18 @@ module Rooms    end    class Boss < Room +    def initialize engine +      super engine +      @health_damage = health_damage(2 * @engine.level) +      @endurance_damage = endurance_damage(2 * @engine.level) +    end +      def instant_resolve        true      end      def do_instant_resolve -      @engine.update_hex -2 * @engine.level, -2 * @engine.level, 2 * @engine.level +      @engine.update_hex -@health_damage, -@endurance_damage, 2 * @engine.level      end      def enter_message  |