Class: MISSIONGAME::UI

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

Instance Method Summary collapse

Instance Method Details

#ask(question, filter = nil) ⇒ Object

Ask user a question. A regular expression filter can be applied.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ui.rb', line 95

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 + " "
    gets.chomp

  end
end

#cannot_travel_combatObject



183
184
185
# File 'lib/ui.rb', line 183

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

#clearObject

Clear the screen



20
21
22
# File 'lib/ui.rb', line 20

def clear
  print "\e[H\e[2J"
end

#display_map(args) ⇒ Object



24
25
26
27
28
29
# File 'lib/ui.rb', line 24

def display_map(args)
  map = args[:map]
  new_line
  draw_frame({text: map})
  new_line
end

#display_name(args) ⇒ Object



209
210
211
212
213
214
# File 'lib/ui.rb', line 209

def display_name(args)
  player = args[:player]
  print "You are " + player.name.light_white +
    ". Have you forgotten your own name?"
  new_line
end

#display_versionObject



163
164
165
166
# File 'lib/ui.rb', line 163

def display_version
  puts " Version " + MISSIONMISSIONGAME_VERSION.light_white
  new_line
end

#draw_frame(args) ⇒ Object

Draw text surrounded in a nice frame



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/ui.rb', line 143

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.is_a?(Array)
      t.each { |s| print s }
    else
      print t
    end
    (width - (t_size + 4)).times { print " " }
    draw_vert_frame_end
    new_line
  end
  draw_bottom_frame(width)
end

#enemy_greet(args) ⇒ Object



224
225
226
227
228
# File 'lib/ui.rb', line 224

def enemy_greet(args)
  enemy = args[:enemy]
  print enemy.name.light_white + " attacks!"
  new_line
end

#enemy_info(args) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/ui.rb', line 79

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_cmdObject



198
199
200
201
202
# File 'lib/ui.rb', line 198

def get_cmd
  print "Type ".white + "help".light_white + " for possible commands.\n"
  print "\u2712 ".red + "Your command? ".light_white
  gets.chomp.downcase
end

#helpObject



31
32
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
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ui.rb', line 31

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/north"
  new_line
  print UI_ARROW.light_yellow + " " + "map, m".light_white + " - Display map"
  new_line
  print UI_ARROW.light_yellow + " " + "where".light_white +
    " - Describe current surroundings"
  new_line
  print UI_ARROW.light_yellow + " " + "name".light_white +
    " - Reminds player their name"
  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.



138
139
140
# File 'lib/ui.rb', line 138

def new_line(times = 1)
  times.times { print "\n" }
end

#not_foundObject



168
169
170
171
172
# File 'lib/ui.rb', line 168

def not_found
  print "Command not understood. Use the " + "help or h".red +
    " to see available commands.".light_white
  new_line
end

#not_in_combatObject



187
188
189
# File 'lib/ui.rb', line 187

def not_in_combat
  puts "No vampire has attacked you just yet."
end

#out_of_boundsObject



204
205
206
207
# File 'lib/ui.rb', line 204

def out_of_bounds
  print "x".red + " Requested move out of bounds."
  new_line
end

#player_dead(args) ⇒ Object



216
217
218
219
220
221
222
# File 'lib/ui.rb', line 216

def player_dead(args)
  story = args[:story]
  new_line
  text = story.player_dead
  draw_frame(text: text)
  new_line
end

#player_info(args) ⇒ Object



87
88
89
90
91
92
# File 'lib/ui.rb', line 87

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



73
74
75
76
77
# File 'lib/ui.rb', line 73

def points(args)
  player = args[:player]
  print "You currently have " + player.points.to_s.light_white + " points."
  new_line
end

#quitObject



191
192
193
194
195
196
# File 'lib/ui.rb', line 191

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



174
175
176
177
178
179
180
181
# File 'lib/ui.rb', line 174

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

#welcomeObject

Display welcome



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/ui.rb', line 118

def welcome
  text = []
  text <<
    "This is a text adventure game inspired by the movie series ".white +
      "The Originals".light_green
  text <<
    "Written by: ".white +
      "Webster Avosa".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