Permalink
Browse files

Finished level 4

  • Loading branch information...
gabebw committed Sep 23, 2010
1 parent 4e04b8c commit 3122e4fa26051d1f32dc9de53645b7abe99bca5b
Showing with 41 additions and 18 deletions.
  1. +5 −5 .profile
  2. +9 −5 README
  3. +27 −8 player.rb
View
@@ -1,8 +1,8 @@
BAhvOhlSdWJ5V2Fycmlvcjo6UHJvZmlsZRA6EEB0b3dlcl9wYXRoSSJPL1Vz
ZXJzL2dhYmUvLnJ2bS9nZW1zL3J1YnktMS45LjItcDAvZ2Vtcy9ydWJ5d2Fy
cmlvci0wLjEuMS90b3dlcnMvYmVnaW5uZXIGOgZFVDoSQHdhcnJpb3JfbmFt
-ZUkiCWdhYmUGOwdUOgtAc2NvcmVpcToYQGN1cnJlbnRfZXBpY19zY29yZWkA
-OhlAY3VycmVudF9lcGljX2dyYWRlc3sAOhBAZXBpY19zY29yZWkAOhNAYXZl
-cmFnZV9ncmFkZTA6D0BhYmlsaXRpZXNbCjoLaGVhbHRoOgpyZXN0IToJZmVl
-bDoMYXR0YWNrIToKd2FsayE6EkBsZXZlbF9udW1iZXJpCToXQGxhc3RfbGV2
-ZWxfbnVtYmVyMDoRQHBsYXllcl9wYXRoSSIGLgY7B0Y=
+ZUkiCWdhYmUGOwdUOgtAc2NvcmVpAb86GEBjdXJyZW50X2VwaWNfc2NvcmVp
+ADoZQGN1cnJlbnRfZXBpY19ncmFkZXN7ADoQQGVwaWNfc2NvcmVpADoTQGF2
+ZXJhZ2VfZ3JhZGUwOg9AYWJpbGl0aWVzWwo6C2hlYWx0aDoKcmVzdCE6CWZl
+ZWw6DGF0dGFjayE6CndhbGshOhJAbGV2ZWxfbnVtYmVyaQo6F0BsYXN0X2xl
+dmVsX251bWJlcjA6EUBwbGF5ZXJfcGF0aEkiBi4GOwdG
View
14 README
@@ -1,21 +1,25 @@
-Level 4
+Level 5
-You can hear bow strings being stretched.
+You hear cries for help. Captives must need rescuing.
-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.
+Tip: Use warrior.feel.captive? to see if there's a captive, and warrior.rescue! to rescue him. Don't attack captives.
-------
-|@ Sa S>|
+|@ CaaSC|
-------
> = Stairs
@ = gabe (20 HP)
- S = Thick Sludge (24 HP)
+ C = Captive (1 HP)
a = Archer (7 HP)
+ S = Thick Sludge (24 HP)
Available Abilities:
+ warrior.rescue!
+ Rescue a captive from his chains (earning 20 points) in given direction (forward by default).
+
warrior.health
Returns an integer representing your health.
View
@@ -1,19 +1,38 @@
class Player
+ MAX_HEALTH = 20
def play_turn(warrior)
- @turn_number ||= 1
- @turn_number += 1
- percent_health = (warrior.health / 20.0) * 100
- if warrior.feel.empty?
- # @turn_number is a total hack to get more points - I know the way is clear
- # after turn 20, so no resting there.
- if percent_health <= 35 and @turn_number < 20
+ current_health = warrior.health
+ @previous_health ||= current_health
+ percent_health = (current_health.to_f / MAX_HEALTH) * 100
+ taking_damage = (current_health < @previous_health)
+ space = warrior.feel
+ if space.stairs?
+ warrior.walk!
+ elsif space.empty?
+ # warrior might be attacked even if space ahead is empty
+ # So if we're low on health and not taking damage, rest a bit.
+ if percent_health < 60 and not taking_damage and not space.stairs?
# Regain some health
warrior.rest!
else
warrior.walk!
end
else
- warrior.attack!
+ if space.enemy?
+ warrior.attack!
+ end
end
+ # available methods for a Space (returned by warrior.feel)
+ # stairs?
+ # empty?
+ # enemy?
+ # captive?
+ # wall?
+ # ticking? (OMINOUS!)
+ # Note that the stairs space is empty, i.e.
+ # if warrior.feel.stairs? is true, then warrior.feel.empty? is true too
+ #
+ # Set @previous_health for next turn
+ @previous_health = current_health
end
end

0 comments on commit 3122e4f

Please sign in to comment.