Class: MISSIONGAME::UI
- Inherits:
-
Object
- Object
- MISSIONGAME::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
-
#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
- #points(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.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ui.rb', line 81 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 + " " input = gets.chomp return input end end |
#cannot_travel_combat ⇒ Object
165 166 167 |
# File 'lib/ui.rb', line 165 def cannot_travel_combat puts "You're in a war with the vampires! Fight for your life to proceed or else your're being feasted on!" end |
#clear ⇒ Object
Clear the screen
22 23 24 |
# File 'lib/ui.rb', line 22 def clear print "\e[H\e[2J" end |
#display_map(args) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ui.rb', line 26 def display_map(args) map = args[:map] new_line draw_frame({:text => map}) new_line end |
#display_name(args) ⇒ Object
190 191 192 193 194 |
# File 'lib/ui.rb', line 190 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
147 148 149 150 |
# File 'lib/ui.rb', line 147 def display_version puts " Version " + MISSIONMISSIONGAME_VERSION.light_white new_line end |
#draw_frame(args) ⇒ Object
Draw text surrounded in a nice frame
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ui.rb', line 123 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
204 205 206 207 208 |
# File 'lib/ui.rb', line 204 def enemy_greet(args) enemy = args[:enemy] print enemy.name.light_white + " attacks!" new_line end |
#enemy_info(args) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/ui.rb', line 67 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.lives.to_s.light_white + " lives." new_line end |
#get_cmd ⇒ Object
179 180 181 182 183 |
# File 'lib/ui.rb', line 179 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ui.rb', line 33 def help new_line print "Valid Commands".light_green new_line(2) print UI_ARROW.light_yellow + " " + "right, r, ".light_white + + + " - Move right/east" new_line print UI_ARROW.light_yellow + " " + "backward, b, ".light_white + + + " - Move backward/south" new_line print UI_ARROW.light_yellow + " " + "left, l, ".light_white + + + " - Move left/west" new_line print UI_ARROW.light_yellow + " " + "forward, f, ".light_white + + + " - Move forward, f" 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 + " " + "a, 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 + " " + "points, score, status, info".light_white + " - Display points (score)" new_line print UI_ARROW.light_yellow + " " + "clear, cls".light_white + " - Clears the screen" new_line print UI_ARROW.light_yellow + " " + "q, quit, exit".light_white + " - Quits the MISSIONGAME" new_line end |
#new_line(times = 1) ⇒ Object
Prints a new line. Optinally can print multiple lines.
116 117 118 119 120 |
# File 'lib/ui.rb', line 116 def new_line(times = 1) times.times do print "\n" end end |
#not_found ⇒ Object
152 153 154 155 |
# File 'lib/ui.rb', line 152 def not_found print "Command not understood. Use the " + "help or h".red + " to see available commands.".light_white new_line end |
#not_in_combat ⇒ Object
169 170 171 |
# File 'lib/ui.rb', line 169 def not_in_combat puts "No vampire has attacked you just yet." end |
#out_of_bounds ⇒ Object
185 186 187 188 |
# File 'lib/ui.rb', line 185 def out_of_bounds print "x".red + " Requested move out of bounds." new_line end |
#player_dead(args) ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/ui.rb', line 196 def player_dead(args) story = args[:story] new_line text = story.player_dead draw_frame(:text => text) new_line end |
#player_info(args) ⇒ Object
74 75 76 77 78 |
# File 'lib/ui.rb', line 74 def player_info(args) player = args[:player] print "You have " + player.lives.to_s.light_white + " lives and have " + player.points.to_s.light_white + " points." new_line end |
#points(args) ⇒ Object
61 62 63 64 65 |
# File 'lib/ui.rb', line 61 def points(args) player = args[:player] print "You currently have " + player.points.to_s.light_white + " points." new_line end |
#quit ⇒ Object
173 174 175 176 177 |
# File 'lib/ui.rb', line 173 def quit new_line print "You abandoned your journey to getting answers to all of your many unaswered questions.".red new_line(2) end |
#show_location(args) ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/ui.rb', line 157 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
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ui.rb', line 104 def welcome text = Array.new text << "This is a text adventure game inspired by the movie series ".white + "The Originals".light_green text << "Written by Webster Avosa as a ".white + UI_EMAIL.light_white + "Livestorm Back-End Hiring Test".light_green text << "Copyright " + UI_COPYRIGHT + " Webster Avosa, All Rights Reserved.".white text << "Licensed under MIT.".white text << "Contact me ".white + UI_EMAIL.light_white + " [email protected]".white draw_frame({:text => text}) new_line end |