mission_game 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (9) hide show
  1. checksums.yaml +4 -4
  2. data/lib/enemy.rb +49 -53
  3. data/lib/main.rb +148 -142
  4. data/lib/neworleans.rb +144 -149
  5. data/lib/player.rb +122 -121
  6. data/lib/story.rb +41 -45
  7. data/lib/ui.rb +269 -259
  8. data/mission_game.rb +41 -43
  9. metadata +1 -1
data/lib/ui.rb CHANGED
@@ -1,259 +1,269 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Written by Webster Avosa
4
- #
5
-
6
- module MISSIONGAME
7
-
8
- UI_FRAME_HORIZONTAL = "\u2501"
9
- UI_FRAME_VERTICAL = "\u2503"
10
- UI_FRAME_UPPER_LEFT = "\u250F"
11
- UI_FRAME_LOWER_LEFT = "\u2517"
12
- UI_FRAME_UPPER_RIGHT = "\u2513"
13
- UI_FRAME_LOWER_RIGHT = "\u251B"
14
-
15
- UI_COPYRIGHT = "\u00A9"
16
- UI_EMAIL = "\u2709"
17
- UI_ARROW = "\u2712"
18
-
19
- class UI
20
-
21
- # Clear the screen
22
- def clear
23
- print "\e[H\e[2J"
24
- end
25
-
26
- def display_map(args)
27
- map = args[:map]
28
- new_line
29
- draw_frame({:text => map})
30
- new_line
31
- end
32
-
33
- def help
34
- new_line
35
- print "Valid Commands".light_green
36
- new_line(2)
37
- print UI_ARROW.light_yellow + " " + "right, r, ".light_white + + + " - Move right/east"
38
- new_line
39
- print UI_ARROW.light_yellow + " " + "backward, b, ".light_white + + + " - Move backward/south"
40
- new_line
41
- print UI_ARROW.light_yellow + " " + "left, l, ".light_white + + + " - Move left/west"
42
- new_line
43
- print UI_ARROW.light_yellow + " " + "forward, f, ".light_white + + + " - Move forward, f"
44
- new_line
45
- print UI_ARROW.light_yellow + " " + "map".light_white + " - Display map"
46
- new_line
47
- print UI_ARROW.light_yellow + " " + "where".light_white + " - Describe current surroundings"
48
- new_line
49
- print UI_ARROW.light_yellow + " " + "a, attack".light_white + " - Attack (only in combat)"
50
- new_line
51
- print UI_ARROW.light_yellow + " " + "enemy".light_white + " - Display information about your enemy"
52
- new_line
53
- print UI_ARROW.light_yellow + " " + "points, score, status, info".light_white + " - Display points (score)"
54
- new_line
55
- print UI_ARROW.light_yellow + " " + "clear, cls".light_white + " - Clears the screen"
56
- new_line
57
- print UI_ARROW.light_yellow + " " + "q, quit, exit".light_white + " - Quits the MISSIONGAME"
58
- new_line
59
- end
60
-
61
- def points(args)
62
- player = args[:player]
63
- print "You currently have " + player.points.to_s.light_white + " points."
64
- new_line
65
- end
66
-
67
- def enemy_info(args)
68
- player = args[:player]
69
- enemy = player.current_enemy
70
- print enemy.name.light_red + " has " + enemy.str.to_s.light_white + " strength and " + enemy.lives.to_s.light_white + " lives."
71
- new_line
72
- end
73
-
74
- def player_info(args)
75
- player = args[:player]
76
- print "You have " + player.lives.to_s.light_white + " lives and have " + player.points.to_s.light_white + " points."
77
- new_line
78
- end
79
-
80
- # Ask user a question. A regular expression filter can be applied.
81
- def ask(question, filter = nil)
82
- if filter
83
- match = false
84
- answer = nil
85
- while match == false
86
- print UI_ARROW.red + question.light_white + " "
87
- answer = gets.chomp
88
- if answer.match(filter)
89
- return answer
90
- else
91
- print "Sorry, please try again.".red
92
- new_line
93
- new_line
94
- end
95
- end
96
- else
97
- print "\u2712 ".red + question.light_white + " "
98
- input = gets.chomp
99
- return input
100
- end
101
- end
102
-
103
- # Display welcome
104
- def welcome
105
- text = Array.new
106
- text << "This is a text adventure game inspired by the movie series ".white + "The Originals".light_green
107
- text << "Written by Webster Avosa as a ".white + UI_EMAIL.light_white + "Livestorm Back-End Hiring Test".light_green
108
- text << "Copyright " + UI_COPYRIGHT + " Webster Avosa, All Rights Reserved.".white
109
- text << "Licensed under MIT.".white
110
- text << "Contact me ".white + UI_EMAIL.light_white + " websterb17@gmail.com".white
111
- draw_frame({:text => text})
112
- new_line
113
- end
114
-
115
- # Prints a new line. Optinally can print multiple lines.
116
- def new_line(times = 1)
117
- times.times do
118
- print "\n"
119
- end
120
- end
121
-
122
- # Draw text surrounded in a nice frame
123
- def draw_frame(args)
124
- # Figure out width automatically
125
- text = args[:text]
126
- width = get_max_size_from_array(text)
127
- draw_top_frame(width)
128
- text.each do |t|
129
- t_size = get_real_size(t)
130
- draw_vert_frame_begin
131
- if t.kind_of?(Array)
132
- t.each do |s|
133
- print s
134
- end
135
- else
136
- print t
137
- end
138
- (width - (t_size + 4)).times do
139
- print " "
140
- end
141
- draw_vert_frame_end
142
- new_line
143
- end
144
- draw_bottom_frame(width)
145
- end
146
-
147
- def display_version
148
- puts " Version " + MISSIONMISSIONGAME_VERSION.light_white
149
- new_line
150
- end
151
-
152
- def not_found
153
- print "Command not understood. Use the " + "help or h".red + " to see available commands.".light_white
154
- new_line
155
- end
156
-
157
- def show_location(args)
158
- player = args[:player]
159
- print "You are currently on row " + player.y.to_s.light_white + ", column " + player.x.to_s.light_white
160
- new_line
161
- print "Use the " + "map".light_white + " command to see the map."
162
- new_line
163
- end
164
-
165
- def cannot_travel_combat
166
- puts "You're in a war with the vampires! Fight for your life to proceed or else your're being feasted on!"
167
- end
168
-
169
- def not_in_combat
170
- puts "No vampire has attacked you just yet."
171
- end
172
-
173
- def quit
174
- new_line
175
- print "You abandoned your journey to getting answers to all of your many unaswered questions.".red
176
- new_line(2)
177
- end
178
-
179
- def get_cmd
180
- print "Type ".white + "help".light_white + " for possible commands.\n"
181
- print "\u2712 ".red + "Your command? ".light_white
182
- return gets.chomp.downcase
183
- end
184
-
185
- def out_of_bounds
186
- print "x".red + " Requested move out of bounds."
187
- new_line
188
- end
189
-
190
- def display_name(args)
191
- player = args[:player]
192
- print "You are " + player.name.light_white + ". Have you forgotten your own name?"
193
- new_line
194
- end
195
-
196
- def player_dead(args)
197
- story = args[:story]
198
- new_line
199
- text = story.player_dead
200
- draw_frame(:text => text)
201
- new_line
202
- end
203
-
204
- def enemy_greet(args)
205
- enemy = args[:enemy]
206
- print enemy.name.light_white + " attacks!"
207
- new_line
208
- end
209
-
210
- private
211
-
212
- def draw_vert_frame_begin
213
- print UI_FRAME_VERTICAL.yellow + " "
214
- end
215
-
216
- def draw_vert_frame_end
217
- print " " + UI_FRAME_VERTICAL.yellow
218
- end
219
-
220
- def draw_top_frame(width)
221
- print UI_FRAME_UPPER_LEFT.yellow
222
- (width - 2).times do
223
- print UI_FRAME_HORIZONTAL.yellow
224
- end
225
- print UI_FRAME_UPPER_RIGHT.yellow
226
- new_line
227
- end
228
-
229
- def draw_bottom_frame(width)
230
- print UI_FRAME_LOWER_LEFT.yellow
231
- (width - 2).times do
232
- print UI_FRAME_HORIZONTAL.yellow
233
- end
234
- print UI_FRAME_LOWER_RIGHT.yellow
235
- new_line
236
- end
237
-
238
- # Returns actual length of text accounting for UTF-8 and ANSI
239
- def get_real_size(text)
240
- if text.kind_of?(Array)
241
- text.size
242
- else
243
- text.uncolorize.size
244
- end
245
- end
246
-
247
- # Returns size of longest string in array
248
- def get_max_size_from_array(array)
249
- max = 0
250
- array.each do |s|
251
- s_size = get_real_size(s)
252
- max = s_size if s_size >= max
253
- end
254
- max + 4
255
- end
256
-
257
- end
258
-
259
- end
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Written by Webster Avosa
4
+ #
5
+
6
+ module MISSIONGAME
7
+ UI_FRAME_HORIZONTAL = "\u2501"
8
+ UI_FRAME_VERTICAL = "\u2503"
9
+ UI_FRAME_UPPER_LEFT = "\u250F"
10
+ UI_FRAME_LOWER_LEFT = "\u2517"
11
+ UI_FRAME_UPPER_RIGHT = "\u2513"
12
+ UI_FRAME_LOWER_RIGHT = "\u251B"
13
+
14
+ UI_COPYRIGHT = "\u00A9"
15
+ UI_EMAIL = "\u2709"
16
+ UI_ARROW = "\u2712"
17
+
18
+ class UI
19
+ # Clear the screen
20
+ def clear
21
+ print "\e[H\e[2J"
22
+ end
23
+
24
+ def display_map(args)
25
+ map = args[:map]
26
+ new_line
27
+ draw_frame({ text: map })
28
+ new_line
29
+ end
30
+
31
+ def help
32
+ new_line
33
+ print 'Valid Commands'.light_green
34
+ new_line(2)
35
+ print UI_ARROW.light_yellow + ' ' + 'right, r, '.light_white +
36
+ ++' - Move right/east'
37
+ new_line
38
+ print UI_ARROW.light_yellow + ' ' + 'backward, b, '.light_white +
39
+ ++' - Move backward/south'
40
+ new_line
41
+ print UI_ARROW.light_yellow + ' ' + 'left, l, '.light_white +
42
+ ++' - Move left/west'
43
+ new_line
44
+ print UI_ARROW.light_yellow + ' ' + 'forward, f, '.light_white +
45
+ ++' - Move forward/north'
46
+ new_line
47
+ print UI_ARROW.light_yellow + ' ' + 'map, m'.light_white + ' - Display map'
48
+ new_line
49
+ print UI_ARROW.light_yellow + ' ' + 'where'.light_white +
50
+ ' - Describe current surroundings'
51
+ new_line
52
+ print UI_ARROW.light_yellow + ' ' + 'name'.light_white +
53
+ ' - Reminds player their name'
54
+ new_line
55
+ print UI_ARROW.light_yellow + ' ' + 'a, attack'.light_white +
56
+ ' - Attack (only in combat)'
57
+ new_line
58
+ print UI_ARROW.light_yellow + ' ' + 'enemy'.light_white +
59
+ ' - Display information about your enemy'
60
+ new_line
61
+ print UI_ARROW.light_yellow + ' ' +
62
+ 'points, score, status, info'.light_white +
63
+ ' - Display points (score)'
64
+ new_line
65
+ print UI_ARROW.light_yellow + ' ' + 'clear, cls'.light_white +
66
+ ' - Clears the screen'
67
+ new_line
68
+ print UI_ARROW.light_yellow + ' ' + 'q, quit, exit'.light_white +
69
+ ' - Quits the MISSIONGAME'
70
+ new_line
71
+ end
72
+
73
+ def points(args)
74
+ player = args[:player]
75
+ print 'You currently have ' + player.points.to_s.light_white + ' points.'
76
+ new_line
77
+ end
78
+
79
+ def enemy_info(args)
80
+ player = args[:player]
81
+ enemy = player.current_enemy
82
+ print enemy.name.light_red + ' has ' + enemy.str.to_s.light_white +
83
+ ' strength and ' + enemy.lives.to_s.light_white + ' lives.'
84
+ new_line
85
+ end
86
+
87
+ def player_info(args)
88
+ player = args[:player]
89
+ print 'You have ' + player.lives.to_s.light_white + ' lives and have ' +
90
+ player.points.to_s.light_white + ' points.'
91
+ new_line
92
+ end
93
+
94
+ # Ask user a question. A regular expression filter can be applied.
95
+ def ask(question, filter = nil)
96
+ if filter
97
+ match = false
98
+ answer = nil
99
+ while match == false
100
+ print UI_ARROW.red + question.light_white + ' '
101
+ answer = gets.chomp
102
+ if answer.match(filter)
103
+ return answer
104
+ else
105
+ print 'Sorry, please try again.'.red
106
+ new_line
107
+ new_line
108
+ end
109
+ end
110
+ else
111
+ print "\u2712 ".red + question.light_white + ' '
112
+ input = gets.chomp
113
+ return input
114
+ end
115
+ end
116
+
117
+ # Display welcome
118
+ def welcome
119
+ text = Array.new
120
+ text <<
121
+ 'This is a text adventure game inspired by the movie series '.white +
122
+ 'The Originals'.light_green
123
+ text <<
124
+ 'Written by Webster Avosa as a '.white + UI_EMAIL.light_white +
125
+ 'Livestorm Back-End Hiring Test'.light_green
126
+ text <<
127
+ 'Copyright ' + UI_COPYRIGHT +
128
+ ' Webster Avosa, All Rights Reserved.'.white
129
+ text << 'Licensed under MIT.'.white
130
+ text <<
131
+ 'Contact me '.white + UI_EMAIL.light_white +
132
+ ' websterb17@gmail.com'.white
133
+ draw_frame({ text: text })
134
+ new_line
135
+ end
136
+
137
+ # Prints a new line. Optinally can print multiple lines.
138
+ def new_line(times = 1)
139
+ times.times { print "\n" }
140
+ end
141
+
142
+ # Draw text surrounded in a nice frame
143
+ def draw_frame(args)
144
+ # Figure out width automatically
145
+ text = args[:text]
146
+ width = get_max_size_from_array(text)
147
+ draw_top_frame(width)
148
+ text.each do |t|
149
+ t_size = get_real_size(t)
150
+ draw_vert_frame_begin
151
+ if t.kind_of?(Array)
152
+ t.each { |s| print s }
153
+ else
154
+ print t
155
+ end
156
+ (width - (t_size + 4)).times { print ' ' }
157
+ draw_vert_frame_end
158
+ new_line
159
+ end
160
+ draw_bottom_frame(width)
161
+ end
162
+
163
+ def display_version
164
+ puts ' Version ' + MISSIONMISSIONGAME_VERSION.light_white
165
+ new_line
166
+ end
167
+
168
+ def not_found
169
+ print 'Command not understood. Use the ' + 'help or h'.red +
170
+ ' to see available commands.'.light_white
171
+ new_line
172
+ end
173
+
174
+ def show_location(args)
175
+ player = args[:player]
176
+ print 'You are currently on row ' + player.y.to_s.light_white +
177
+ ', column ' + player.x.to_s.light_white
178
+ new_line
179
+ print 'Use the ' + 'map'.light_white + ' command to see the map.'
180
+ new_line
181
+ end
182
+
183
+ def cannot_travel_combat
184
+ puts "You're in a war with the vampires! Fight for your life to proceed or else your're being feasted on!"
185
+ end
186
+
187
+ def not_in_combat
188
+ puts 'No vampire has attacked you just yet.'
189
+ end
190
+
191
+ def quit
192
+ new_line
193
+ print 'You abandoned your journey to getting answers to all of your many unaswered questions.'
194
+ .red
195
+ new_line(2)
196
+ end
197
+
198
+ def get_cmd
199
+ print 'Type '.white + 'help'.light_white + " for possible commands.\n"
200
+ print "\u2712 ".red + 'Your command? '.light_white
201
+ return gets.chomp.downcase
202
+ end
203
+
204
+ def out_of_bounds
205
+ print 'x'.red + ' Requested move out of bounds.'
206
+ new_line
207
+ end
208
+
209
+ def display_name(args)
210
+ player = args[:player]
211
+ print 'You are ' + player.name.light_white +
212
+ '. Have you forgotten your own name?'
213
+ new_line
214
+ end
215
+
216
+ def player_dead(args)
217
+ story = args[:story]
218
+ new_line
219
+ text = story.player_dead
220
+ draw_frame(text: text)
221
+ new_line
222
+ end
223
+
224
+ def enemy_greet(args)
225
+ enemy = args[:enemy]
226
+ print enemy.name.light_white + ' attacks!'
227
+ new_line
228
+ end
229
+
230
+ private
231
+
232
+ def draw_vert_frame_begin
233
+ print UI_FRAME_VERTICAL.yellow + ' '
234
+ end
235
+
236
+ def draw_vert_frame_end
237
+ print ' ' + UI_FRAME_VERTICAL.yellow
238
+ end
239
+
240
+ def draw_top_frame(width)
241
+ print UI_FRAME_UPPER_LEFT.yellow
242
+ (width - 2).times { print UI_FRAME_HORIZONTAL.yellow }
243
+ print UI_FRAME_UPPER_RIGHT.yellow
244
+ new_line
245
+ end
246
+
247
+ def draw_bottom_frame(width)
248
+ print UI_FRAME_LOWER_LEFT.yellow
249
+ (width - 2).times { print UI_FRAME_HORIZONTAL.yellow }
250
+ print UI_FRAME_LOWER_RIGHT.yellow
251
+ new_line
252
+ end
253
+
254
+ # Returns actual length of text accounting for UTF-8 and ANSI
255
+ def get_real_size(text)
256
+ text.kind_of?(Array) ? text.size : text.uncolorize.size
257
+ end
258
+
259
+ # Returns size of longest string in array
260
+ def get_max_size_from_array(array)
261
+ max = 0
262
+ array.each do |s|
263
+ s_size = get_real_size(s)
264
+ max = s_size if s_size >= max
265
+ end
266
+ max + 4
267
+ end
268
+ end
269
+ end
data/mission_game.rb CHANGED
@@ -1,43 +1,41 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Written by Webster Avosa
4
-
5
- GAME_VERSION = "1.00"
6
-
7
- begin
8
- require 'colorize'
9
- require 'pry'
10
- rescue LoadError
11
- puts
12
- puts "This game requires the 'colorize' and 'pry' gem to run."
13
- puts
14
- puts "Installation Instructions"
15
- puts "-------------------------"
16
- puts
17
- puts "Debian/Ubuntu Linux:"
18
- puts " sudo apt install ruby-colorize && sudo apt install pry"
19
- puts
20
- puts "Other Linux Distros:"
21
- puts " gem install colorize && gem install pry"
22
- puts
23
- puts "Windows:"
24
- puts " gem install colorize && gem install pry"
25
- puts
26
- puts "macOS:"
27
- puts " gem install colorize && gem install pry"
28
- puts
29
- puts
30
- exit
31
- end
32
-
33
-
34
-
35
- # Require libraries
36
- load "lib/ui.rb"
37
- load "lib/neworleans.rb"
38
- load "lib/player.rb"
39
- load "lib/story.rb"
40
- load "lib/enemy.rb"
41
-
42
- # Start
43
- load "lib/main.rb"
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Written by Webster Avosa
4
+
5
+ GAME_VERSION = '1.00'
6
+
7
+ begin
8
+ require 'colorize'
9
+ require 'pry'
10
+ rescue LoadError
11
+ puts
12
+ puts "This game requires the 'colorize' and 'pry' gem to run."
13
+ puts
14
+ puts 'Installation Instructions'
15
+ puts '-------------------------'
16
+ puts
17
+ puts 'Debian/Ubuntu Linux:'
18
+ puts ' sudo apt install ruby-colorize && sudo apt install pry'
19
+ puts
20
+ puts 'Other Linux Distros:'
21
+ puts ' gem install colorize && gem install pry'
22
+ puts
23
+ puts 'Windows:'
24
+ puts ' gem install colorize && gem install pry'
25
+ puts
26
+ puts 'macOS:'
27
+ puts ' gem install colorize && gem install pry'
28
+ puts
29
+ puts
30
+ exit
31
+ end
32
+
33
+ # Require libraries
34
+ load 'lib/ui.rb'
35
+ load 'lib/neworleans.rb'
36
+ load 'lib/player.rb'
37
+ load 'lib/story.rb'
38
+ load 'lib/enemy.rb'
39
+
40
+ # Start
41
+ load 'lib/main.rb'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mission_game
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Webster Avosa