Class: LOTS::UI
- Inherits:
-
Object
- Object
- LOTS::UI
- Defined in:
- lib/ui.rb
Instance Method Summary collapse
-
#ask(question, filter = nil) ⇒ Object
Ask user a question.
- #cannot_travel_combat ⇒ Object
-
#clear ⇒ Object
Clear the screen.
- #display_map(args) ⇒ Object
- #display_name(args) ⇒ Object
- #display_version ⇒ Object
-
#draw_frame(args) ⇒ Object
Draw text surrounded in a nice frame.
- #enemy_greet(args) ⇒ Object
- #enemy_info(args) ⇒ Object
- #get_cmd ⇒ Object
- #help ⇒ Object
- #lines(args) ⇒ Object
-
#new_line(times = 1) ⇒ Object
Prints a new line.
- #not_found ⇒ Object
- #not_in_combat ⇒ Object
- #out_of_bounds ⇒ Object
- #player_dead(args) ⇒ Object
- #player_info(args) ⇒ Object
- #quit ⇒ Object
- #show_location(args) ⇒ Object
-
#welcome ⇒ Object
Display welcome.
Instance Method Details
#ask(question, filter = nil) ⇒ Object
Ask user a question. A regular expression filter can be applied.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ui.rb', line 86 def ask(question, filter = nil) if filter match = false answer = nil while match == false print UI_ARROW.red + question.light_white + " " answer = gets.chomp if answer.match(filter) return answer else print "Sorry, please try again.".red new_line new_line end end else print "\u2712 ".red + question.light_white + " " return gets.chomp end end |
#cannot_travel_combat ⇒ Object
168 169 170 |
# File 'lib/ui.rb', line 168 def cannot_travel_combat puts "You are in combat and cannot travel!" end |
#clear ⇒ Object
Clear the screen
27 28 29 |
# File 'lib/ui.rb', line 27 def clear print "\e[H\e[2J" end |
#display_map(args) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/ui.rb', line 31 def display_map(args) map = args[:map] new_line draw_frame({:text => map}) new_line end |
#display_name(args) ⇒ Object
193 194 195 196 197 |
# File 'lib/ui.rb', line 193 def display_name(args) player = args[:player] print "You are " + player.name.light_white + ". Have you forgotten your own name?" new_line end |
#display_version ⇒ Object
150 151 152 153 |
# File 'lib/ui.rb', line 150 def display_version puts "This is " + "Legend of the Sourcerer".light_red + " Version " + LOTS_VERSION.light_white new_line end |
#draw_frame(args) ⇒ Object
Draw text surrounded in a nice frame
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ui.rb', line 126 def draw_frame(args) # Figure out width automatically text = args[:text] width = get_max_size_from_array(text) draw_top_frame(width) text.each do |t| t_size = get_real_size(t) draw_vert_frame_begin if t.kind_of?(Array) t.each do |s| print s end else print t end (width - (t_size + 4)).times do print " " end draw_vert_frame_end new_line end draw_bottom_frame(width) end |
#enemy_greet(args) ⇒ Object
207 208 209 210 211 |
# File 'lib/ui.rb', line 207 def enemy_greet(args) enemy = args[:enemy] print enemy.name.light_white + " attacks!" new_line end |
#enemy_info(args) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/ui.rb', line 72 def enemy_info(args) player = args[:player] enemy = player.current_enemy print enemy.name.light_red + " has " + enemy.str.to_s.light_white + " strength and " + enemy.health.to_s.light_white + " health." new_line end |
#get_cmd ⇒ Object
182 183 184 185 186 |
# File 'lib/ui.rb', line 182 def get_cmd print "Type ".white + "help".light_white + " for possible commands.\n" print "\u2712 ".red + "Your command? ".light_white return gets.chomp.downcase end |
#help ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ui.rb', line 38 def help new_line print "Valid Commands".light_green new_line(2) print UI_ARROW.light_yellow + " " + "east, e, right, ".light_white + "or " + "r".light_white + " - Move east (right)" new_line print UI_ARROW.light_yellow + " " + "south, s, down, ".light_white + "or " + "d".light_white + " - Move south (down)" new_line print UI_ARROW.light_yellow + " " + "west, w, left, ".light_white + "or " + "l".light_white + " - Move west (left)" new_line print UI_ARROW.light_yellow + " " + "north, n, up, ".light_white + "or " + "u".light_white + " - Move north (up)" new_line print UI_ARROW.light_yellow + " " + "map".light_white + " - Display map" new_line print UI_ARROW.light_yellow + " " + "where".light_white + " - Describe current surroundings" new_line print UI_ARROW.light_yellow + " " + "attack".light_white + " - Attack (only in combat)" new_line print UI_ARROW.light_yellow + " " + "enemy".light_white + " - Display information about your enemy" new_line print UI_ARROW.light_yellow + " " + "lines, score, status, info".light_white + " - Display lines of code (score)" new_line print UI_ARROW.light_yellow + " " + "clear, cls".light_white + " - Clears the screen" new_line print UI_ARROW.light_yellow + " " + "quit, exit".light_white + " - Quits the game" new_line end |
#lines(args) ⇒ Object
66 67 68 69 70 |
# File 'lib/ui.rb', line 66 def lines(args) player = args[:player] print "You currently have " + player.lines.to_s.light_white + " lines of code." new_line end |
#new_line(times = 1) ⇒ Object
Prints a new line. Optinally can print multiple lines.
119 120 121 122 123 |
# File 'lib/ui.rb', line 119 def new_line(times = 1) times.times do print "\n" end end |
#not_found ⇒ Object
155 156 157 158 |
# File 'lib/ui.rb', line 155 def not_found print "Command not understood. Please try again.".red new_line end |
#not_in_combat ⇒ Object
172 173 174 |
# File 'lib/ui.rb', line 172 def not_in_combat puts "You are not in combat." end |
#out_of_bounds ⇒ Object
188 189 190 191 |
# File 'lib/ui.rb', line 188 def out_of_bounds print "x".red + " Requested move out of bounds." new_line end |
#player_dead(args) ⇒ Object
199 200 201 202 203 204 205 |
# File 'lib/ui.rb', line 199 def player_dead(args) story = args[:story] new_line text = story.player_dead draw_frame(:text => text) new_line end |
#player_info(args) ⇒ Object
79 80 81 82 83 |
# File 'lib/ui.rb', line 79 def player_info(args) player = args[:player] print "You have " + player.health.to_s.light_white + " health and have " + player.lines.to_s.light_white + " lines of code." new_line end |
#quit ⇒ Object
176 177 178 179 180 |
# File 'lib/ui.rb', line 176 def quit new_line print "You abandoned your journey.".red new_line(2) end |
#show_location(args) ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/ui.rb', line 160 def show_location(args) player = args[:player] print "You are currently on row " + player.y.to_s.light_white + ", column " + player.x.to_s.light_white new_line print "Use the " + "map".light_white + " command to see the map." new_line end |
#welcome ⇒ Object
Display welcome
108 109 110 111 112 113 114 115 116 |
# File 'lib/ui.rb', line 108 def welcome text = Array.new text << "Legend of the Sourcerer".light_green text << "Written by Robert W. Oliver II ".white + UI_EMAIL.light_white + " [email protected]".white text << "Copyright " + UI_COPYRIGHT + " Sourcerer, All Rights Reserved.".white text << "Licensed under GPLv3.".white draw_frame({:text => text}) new_line end |