Class: SRSGame::Game
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#room ⇒ Object
Returns the value of attribute room.
Instance Method Summary collapse
- #go!(*directions) ⇒ Object
-
#initialize(mod = SRSGame::Basic, options = {}) ⇒ Game
constructor
A new instance of Game.
- #play ⇒ Object
-
#prompt ⇒ Object
def same_room? current_room.eql? last_room end.
- #send(input) ⇒ Object
Constructor Details
#initialize(mod = SRSGame::Basic, options = {}) ⇒ Game
Returns a new instance of Game.
339 340 341 342 343 344 345 346 347 |
# File 'lib/srs_game.rb', line 339 def initialize(mod = SRSGame::Basic, = {}) raise ArgumentError, "Can't use #{mod} for SRSGame module" unless mod.is_a? Module extend mod @options = @room = main_room #@travel_path = [@room] @command = mod.const_get(:Commands).new end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
337 338 339 |
# File 'lib/srs_game.rb', line 337 def command @command end |
#room ⇒ Object
Returns the value of attribute room.
337 338 339 |
# File 'lib/srs_game.rb', line 337 def room @room end |
Instance Method Details
#go!(*directions) ⇒ Object
349 350 351 352 353 354 355 356 |
# File 'lib/srs_game.rb', line 349 def go!(*directions) if directions.size >= 2 directions.each { |dir| go! dir } else new_room = @room.go(directions[0]) @room = new_room end end |
#play ⇒ Object
380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/srs_game.rb', line 380 def play Readline.completion_append_character = " " begin loop do Readline.completion_proc = proc { |match| @command.matching_methods(match).map(&:command_pp) } input = Readline.readline(prompt, true) puts send(input) unless input.blank? end rescue DONE_WITH_SRS_GAME puts "\nHave a nice day!" end end |
#prompt ⇒ Object
def same_room?
current_room.eql? last_room
end
370 371 372 373 |
# File 'lib/srs_game.rb', line 370 def prompt pr = "$ ".bold.blue @options[:color] ? pr : pr.uncolored end |
#send(input) ⇒ Object
375 376 377 378 |
# File 'lib/srs_game.rb', line 375 def send(input) output = @command.parse(input, self) @options[:color] ? output : output.uncolored end |