Class: Degica::Game
- Inherits:
-
Object
- Object
- Degica::Game
- Defined in:
- lib/degica/game.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #start ⇒ Object
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/degica/game.rb', line 3 def initialize # setup rooms rooms = RoomLoader.load # spawn actor in random room starting_room = rooms.sample @actor = Actor.new(starting_room) # game objects @@objects = OpenStruct.new(rooms: rooms, actor: @actor) # generate starting room starting_room.generate! end |
Class Method Details
.objects ⇒ Object
18 19 20 |
# File 'lib/degica/game.rb', line 18 def self.objects @@objects end |
Instance Method Details
#start ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/degica/game.rb', line 22 def start ANSI.clear_screen puts "Welcome to" puts ANSI.highlight(File.read(Degica.root + '/data/images/degica_quest.txt'), :yellow) puts "Type (actions) to see what actions you can perform.".highlight puts "\n" + @@objects.actor.describe + "\n\n" loop do input = Readline.readline("#{prompt}> ", true) exit if input == "exit" begin context = Context.new(@actor) case output = context.instance_eval(input) when String # remove quotes in console i.e. > "string" puts output when Actionable @actor.focus = output = output.describe puts unless .nil? when NilClass puts @actor.describe else puts CodeRay.scan(output.inspect, :ruby).terminal end rescue Exception => e puts e. end puts end end |