Class: RollForInitiative::CLI
- Inherits:
-
Object
- Object
- RollForInitiative::CLI
- Defined in:
- lib/roll_for_initiative/cli.rb
Overview
CLI controller
Constant Summary collapse
- @@site =
"https://www.dndbeyond.com/classes"
Instance Attribute Summary collapse
-
#klasses ⇒ Object
Returns the value of attribute klasses.
-
#player_name ⇒ Object
Returns the value of attribute player_name.
Instance Method Summary collapse
- #adventure ⇒ Object
- #call ⇒ Object
- #fight_again ⇒ Object
- #goodbye ⇒ Object
- #klass_choose ⇒ Object
- #klass_list ⇒ Object
- #picked ⇒ Object
- #welcome_msg ⇒ Object
Instance Attribute Details
#klasses ⇒ Object
Returns the value of attribute klasses.
3 4 5 |
# File 'lib/roll_for_initiative/cli.rb', line 3 def klasses @klasses end |
#player_name ⇒ Object
Returns the value of attribute player_name.
3 4 5 |
# File 'lib/roll_for_initiative/cli.rb', line 3 def player_name @player_name end |
Instance Method Details
#adventure ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# 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 ⇒ Object
11 12 13 14 15 16 |
# 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 ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# 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 ⇒ Object
121 122 123 124 |
# File 'lib/roll_for_initiative/cli.rb', line 121 def goodbye puts "Goodbye...for now." exit end |
#klass_choose ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# 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 ⇒ Object
76 77 78 79 80 |
# 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 ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 |