class RollForInitiative::CLI

CLI controller

Attributes

klasses[RW]
player_name[RW]

Public Instance Methods

adventure() click to toggle source
# File lib/roll_for_initiative/cli.rb, line 82
def adventure
    RollForInitiative::Scraper.new.who_you_fight
    puts "Let's see who you fight:\n#{RollForInitiative::Scraper.fight} Will you 'Fight' or 'Run'?"
    sleep(1)
    while input = gets.strip.downcase
        case input
        when "fight"
            puts "you strike down your opponent. You win!"
            sleep(1)
            fight_again
        when "run"
            puts "Your enemy strikes you while your back is turned. You Lose"
            sleep(1)
            fight_again
        when "exit"
            goodbye
        else 
            puts "I don't understand your command only enter 'Fight' or 'run'"
        end
    end
end
call() click to toggle source
# File lib/roll_for_initiative/cli.rb, line 11
def call
    RollForInitiative::Scraper.new.klasses(@@site)
    RollForInitiative::Klass.get_klass_names
    welcome_msg
    klass_list
end
fight_again() click to toggle source
# File lib/roll_for_initiative/cli.rb, line 104
def fight_again
    puts "would you like to fight again?(y/n)"
    while input = gets.strip.downcase
        case input
        when 'y'
            adventure
        when 'n'
            goodbye
        when 'exit'
            goodbye
        else
            puts "I don't understand the command only enter 'y' or 'n'."
        end
    end
end
goodbye() click to toggle source
# File lib/roll_for_initiative/cli.rb, line 121
def goodbye
    puts "Goodbye...for now."
    exit
end
klass_choose() click to toggle source
# File lib/roll_for_initiative/cli.rb, line 43
def klass_choose    
    puts "I'm a very particular god the class must be spelled right. OR ELSE!!!"
    @klass_picked = nil
    @klass_picked = gets.strip.downcase

    if RollForInitiative::Klass.klass_name_list.include?(@klass_picked)
        RollForInitiative::Klass.all.each do |type|
            if type.name == @klass_picked.split.map(&:capitalize).join(' ')
                RollForInitiative::Scraper.new.grab_encounter(@@site.gsub('/classes', type.klass_url))
                puts "#{RollForInitiative::Scraper.encounter}"
                sleep(2)
                puts "Does this sound like you? (y/n)"
                input = gets.strip.downcase
                case input
                    when "y"
                        @chosen_klass = type
                        picked
                    when "n"
                        klass_list
                    when "exit"
                        goodbye
                end
            end
        end
    elsif @klass_picked == 'exit'
            goodbye    
    else
        puts "You are trying my patience. Check your spelling!"
        sleep(2)
        klass_list
    end
end
klass_list() click to toggle source
# File lib/roll_for_initiative/cli.rb, line 32
def klass_list
    puts "Choose your class mortal:"
    sleep(1)
    @klasses = RollForInitiative::Klass.all
    @klasses.each do |klass|
        puts "#{klass.name} - #{klass.short}"
    end
    sleep(1)
    klass_choose
end
picked() click to toggle source
# File lib/roll_for_initiative/cli.rb, line 76
def picked
    puts "Time for adventure #{@player_name} the #{@chosen_klass.name}."
    sleep(1)
    adventure
end
welcome_msg() click to toggle source
# File lib/roll_for_initiative/cli.rb, line 18
def welcome_msg
    puts "Welcome to The Dragon Province!"
    puts "'exit' can be entered at any time to leave"
    sleep(1)
    puts "Please, enter your name:"
    @player_name = gets.strip
    if @player_name.downcase == 'exit'
        goodbye
    end
    sleep(2)
    puts "What a curious name..."
    sleep(2)
end