m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rooms.rb135
1 files changed, 135 insertions, 0 deletions
diff --git a/rooms.rb b/rooms.rb
index 2e0bc01..3115022 100644
--- a/rooms.rb
+++ b/rooms.rb
@@ -5,6 +5,141 @@ module Rooms
end
def resolve command
+ @command = command
+ if @engine.state == 'invalid'
+ @engine.state = 'play'
+ end
+
+ if @engine.state == 'play'
+ _do_resolve
+ end
+ end
+
+ def check_death
+ if @engine.health <= 0
+ @engine.state = 'dead'
+ elsif @engine.endurance <= 0
+ @engine.state = 'dead'
+ end
+ end
+
+ def _do_resolve
+ do_resolve
+ check_death
+ if !instant_resolve
+ @engine.add_message resolve_message
+ end
+ end
+
+ # TODO: limit weapon/armor levels
+ def do_resolve
+ case @command
+ when 'c'
+ else
+ do_invalid
+ end
+ end
+
+ def do_invalid
+ @engine.state = 'invalid'
+ @engine.add_message "Invalid command: #{@command}"
+
+ if !instant_resolve
+ enter
+ else
+ list_options
+ end
+ end
+
+ def resolve_message
+ if @engine.state == 'dead'
+ if @engine.health <= 0
+ death_message
+ elsif @engine.endurance <= 0
+ exhaust_message
+ end
+ else
+ success_message
+ end
+ end
+
+ def enter_message
+ ''
+ end
+
+ def death_message
+ 'You die'
+ end
+
+ def exhaust_message
+ 'You fall over exhausted'
+ end
+
+ def success_message
+ ''
+ end
+
+ def options
+ [
+ 'continue',
+ ]
+ end
+
+ def list_options
+ options.each do |option|
+ @engine.add_message ">[#{option[0]}]#{option[1..]}"
+ end
+ end
+
+ def enter
+ @engine.add_message enter_message
+ if instant_resolve
+ do_instant_resolve
+ @engine.add_message resolve_message
+ end
+
+ list_options
+ end
+ end
+
+ class Welcome < Room
+ def instant_resolve
+ false
+ end
+
+ def do_resolve
+ end
+
+ def success_message
+ <<~MSG.chomp
+ A curse has infested an ancient keep near your town.
+ The evil magic has filled the keep with monsters.
+ Can you save your home from this Hex?
+ MSG
+ end
+
+ def to_s
+ 'welcome'
+ end
+ end
+
+ class Store < Room
+ def instant_resolve
+ false
+ end
+
+ def enter_message
+ 'You have enough XP to upgrade your equipment!'
+ end
+
+ def options
+ [
+ 'weapon upgrade',
+ 'armor upgrade'
+ ]
+ end
+
+ def do_resolve
case @command
when 'a'
@engine.xp -= 50