Class: TextAdventure::World

Inherits:
Object
  • Object
show all
Defined in:
lib/text_adventure.rb

Instance Method Summary collapse

Instance Method Details

#read_questionsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/text_adventure.rb', line 5

def read_questions
  questions = {}
  Dir.glob(
    File.join(
      File.dirname(__FILE__),
      '..',
      'questions',
      '*.yml'
    )
  ).each do |file|
    key = File.basename(file, '.yml')
    questions[key] = Question.new YAML.load_file(file)
  end
  @questions = questions
end

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/text_adventure.rb', line 21

def run
  read_questions
  key = 'ground_floor'
  while true do
    if key == 'win'
      puts @questions[key].question
      break
    end
    if key == 'death'
      puts @questions[key].question
      break
    end
    key = @questions[key].ask
  end
end