gemwarrior 0.5.1 → 0.5.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.
- checksums.yaml +4 -4
- data/bin/gemwarrior +7 -3
- data/gemwarrior.gemspec +1 -0
- data/lib/gemwarrior/battle.rb +58 -29
- data/lib/gemwarrior/entities/location.rb +0 -2
- data/lib/gemwarrior/entities/player.rb +8 -4
- data/lib/gemwarrior/evaluator.rb +15 -13
- data/lib/gemwarrior/game.rb +7 -2
- data/lib/gemwarrior/misc/version.rb +1 -1
- data/lib/gemwarrior/repl.rb +10 -7
- data/lib/gemwarrior/world.rb +10 -3
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 853ee5c247a788f9c35ce812d79224390703382c
|
4
|
+
data.tar.gz: 8065711862b62cbaa590ae68a6f380ea75ab276b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9f881a6cea35e551d232c84893f1a12b9203c5111337c4c428c5a55672e351139a0eeb7f858f7d2f7f37bc2ce7bc8b17dc1456ddbdaabab90637cdb99cc0d3a
|
7
|
+
data.tar.gz: 4c6d94b62e1dc8c93eb3d84b5be202210772320ca89b4da000a81844d6a92db1ad2f4c140495e4c7bce8caa014c82cc4a0aa60d437fe6ccb16e0a60882ef8122
|
data/bin/gemwarrior
CHANGED
@@ -8,15 +8,19 @@ require_relative '../lib/gemwarrior/game'
|
|
8
8
|
GAME_NAME = "Gem Warrior"
|
9
9
|
|
10
10
|
def parse_options
|
11
|
-
options = {}
|
11
|
+
options = {:god_mode => false}
|
12
12
|
|
13
13
|
optparse = OptionParser.new do |opts|
|
14
14
|
opts.on('-v', '--version', 'Display version number and exit') do
|
15
15
|
puts "#{GAME_NAME} v#{Gemwarrior::VERSION}"
|
16
16
|
exit
|
17
17
|
end
|
18
|
+
|
19
|
+
opts.on('-g', '--god', 'Set godmode to true on load') do
|
20
|
+
options[:god_mode] = true
|
21
|
+
end
|
18
22
|
end
|
19
|
-
|
23
|
+
|
20
24
|
optparse.parse!()
|
21
25
|
|
22
26
|
return options
|
@@ -35,7 +39,7 @@ end
|
|
35
39
|
begin
|
36
40
|
options = parse_options
|
37
41
|
|
38
|
-
Gemwarrior::Game.new
|
42
|
+
Gemwarrior::Game.new(options)
|
39
43
|
rescue => error
|
40
44
|
print_error(error)
|
41
45
|
exit(false)
|
data/gemwarrior.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency 'matrext', '~> 0.2'
|
24
24
|
spec.add_runtime_dependency 'http', '~> 0.8.10'
|
25
25
|
spec.add_runtime_dependency 'json', '~> 1.8.2'
|
26
|
+
spec.add_runtime_dependency 'colorize', '~> 0.7.7'
|
26
27
|
|
27
28
|
#spec.add_runtime_dependency 'feep', '~> 0.0.9'
|
28
29
|
#spec.add_runtime_dependency 'wordnik', '~> 4.12'
|
data/lib/gemwarrior/battle.rb
CHANGED
@@ -18,33 +18,33 @@ module Gemwarrior
|
|
18
18
|
def start
|
19
19
|
print_battle_line
|
20
20
|
puts "You decide to attack the #{monster.name}!"
|
21
|
-
puts "#{monster.name} cries out: #{monster.battlecry}"
|
21
|
+
puts "#{monster.name} cries out: \"#{monster.battlecry}\"".colorize(:yellow)
|
22
22
|
|
23
23
|
# first strike!
|
24
24
|
if monster_strikes_first?
|
25
|
-
puts "#{monster.name} strikes first!"
|
25
|
+
puts "#{monster.name} strikes first!".colorize(:yellow)
|
26
26
|
monster_attacks_player
|
27
27
|
end
|
28
28
|
|
29
29
|
# main battle loop
|
30
30
|
loop do
|
31
|
-
if
|
31
|
+
if monster_dead?
|
32
32
|
monster_death
|
33
33
|
return
|
34
|
-
elsif
|
34
|
+
elsif player_dead?
|
35
35
|
player_death
|
36
36
|
end
|
37
37
|
|
38
38
|
puts
|
39
|
-
puts "[Fight/Attack][Look][Run]"
|
40
|
-
puts "P :: #{player.hp_cur} HP\n"
|
41
|
-
puts "M :: #{monster.hp_cur} HP\n"
|
39
|
+
puts "[Fight/Attack][Look][Run]".colorize(:color => :white, :background => :green)
|
40
|
+
puts "P :: #{player.hp_cur.to_s.rjust(3)} HP\n"
|
41
|
+
puts "M :: #{monster.hp_cur.to_s.rjust(3)} HP\n"
|
42
42
|
|
43
|
-
if
|
44
|
-
puts "You are almost dead!\n"
|
43
|
+
if player_near_death?
|
44
|
+
puts "You are almost dead!\n".colorize(:yellow)
|
45
45
|
end
|
46
|
-
if
|
47
|
-
puts "#{monster.name} is almost dead!\n"
|
46
|
+
if monster_near_death?
|
47
|
+
puts "#{monster.name} is almost dead!\n".colorize(:yellow)
|
48
48
|
end
|
49
49
|
|
50
50
|
puts 'What do you do?'
|
@@ -56,14 +56,14 @@ module Gemwarrior
|
|
56
56
|
puts "You attack #{monster.name}#{player.cur_weapon_name}!"
|
57
57
|
dmg = calculate_damage_to(monster)
|
58
58
|
if dmg > 0
|
59
|
-
puts "You wound it for #{dmg} point(s)!"
|
59
|
+
puts "> You wound it for #{dmg} point(s)!".colorize(:yellow)
|
60
60
|
take_damage(monster, dmg)
|
61
|
-
if
|
61
|
+
if monster_dead?
|
62
62
|
monster_death
|
63
63
|
return
|
64
64
|
end
|
65
65
|
else
|
66
|
-
puts "You miss entirely!"
|
66
|
+
puts "You miss entirely!".colorize(:yellow)
|
67
67
|
end
|
68
68
|
when 'look', 'l'
|
69
69
|
puts "#{monster.name}: #{monster.description}"
|
@@ -71,10 +71,11 @@ module Gemwarrior
|
|
71
71
|
when 'run', 'r'
|
72
72
|
if player_escape?
|
73
73
|
monster.hp_cur = monster.hp_max
|
74
|
-
puts "You successfully elude #{monster.name}!"
|
74
|
+
puts "You successfully elude #{monster.name}!".colorize(:green)
|
75
|
+
print_escape_text
|
75
76
|
return
|
76
77
|
else
|
77
|
-
puts "You were not able to run away! :-("
|
78
|
+
puts "You were not able to run away! :-(".colorize(:yellow)
|
78
79
|
end
|
79
80
|
else
|
80
81
|
puts ERROR_ATTACK_OPTION_INVALID
|
@@ -123,13 +124,13 @@ module Gemwarrior
|
|
123
124
|
puts "#{monster.name} attacks you!"
|
124
125
|
dmg = calculate_damage_to(player)
|
125
126
|
if dmg > 0
|
126
|
-
puts "You are wounded for #{dmg} point(s)!"
|
127
|
+
puts "> You are wounded for #{dmg} point(s)!".colorize(:yellow)
|
127
128
|
take_damage(player, dmg)
|
128
|
-
if
|
129
|
+
if player_dead?
|
129
130
|
player_death
|
130
131
|
end
|
131
132
|
else
|
132
|
-
puts "#{monster.name} misses entirely!"
|
133
|
+
puts "#{monster.name} misses entirely!".colorize(:yellow)
|
133
134
|
end
|
134
135
|
end
|
135
136
|
|
@@ -142,27 +143,44 @@ module Gemwarrior
|
|
142
143
|
end
|
143
144
|
end
|
144
145
|
|
146
|
+
def monster_near_death?
|
147
|
+
((monster.hp_cur.to_f / monster.hp_max.to_f) < 0.10)
|
148
|
+
end
|
149
|
+
|
150
|
+
def monster_dead?
|
151
|
+
monster.hp_cur <= 0
|
152
|
+
end
|
153
|
+
|
145
154
|
def monster_death
|
146
|
-
puts "You have defeated #{monster.name}!"
|
147
|
-
puts
|
148
|
-
puts "
|
155
|
+
puts "You have defeated #{monster.name}!".colorize(:green)
|
156
|
+
puts 'You get the following spoils of war:'
|
157
|
+
puts " XP : #{monster.xp}".colorize(:green)
|
158
|
+
puts " ROX: #{monster.rox}".colorize(:green)
|
149
159
|
print_battle_line
|
150
160
|
update_player_stats
|
151
161
|
world.location_by_coords(player.cur_coords).remove_monster(monster.name)
|
152
162
|
end
|
153
163
|
|
154
|
-
def player_death
|
155
|
-
puts "You are dead, slain by the #{monster.name}!"
|
156
|
-
puts 'Your adventure ends here. Try again next time!'
|
157
|
-
print_battle_line
|
158
|
-
exit(0)
|
159
|
-
end
|
160
|
-
|
161
164
|
def update_player_stats
|
162
165
|
player.xp = player.xp + monster.xp
|
163
166
|
player.rox = player.rox + monster.rox
|
164
167
|
end
|
165
168
|
|
169
|
+
def player_near_death?
|
170
|
+
((player.hp_cur.to_f / player.hp_max.to_f) < 0.10 && !player.god_mode)
|
171
|
+
end
|
172
|
+
|
173
|
+
def player_dead?
|
174
|
+
(player.hp_cur <= 0 && !player.god_mode)
|
175
|
+
end
|
176
|
+
|
177
|
+
def player_death
|
178
|
+
puts "You are dead, slain by the #{monster.name}!".colorize(:red)
|
179
|
+
puts 'Your adventure ends here. Try again next time!'.colorize(:red)
|
180
|
+
print_battle_line
|
181
|
+
exit(0)
|
182
|
+
end
|
183
|
+
|
166
184
|
def player_escape?
|
167
185
|
if (player.dexterity > monster.dexterity)
|
168
186
|
return true
|
@@ -177,6 +195,17 @@ module Gemwarrior
|
|
177
195
|
end
|
178
196
|
end
|
179
197
|
|
198
|
+
# STATUS TEXT
|
199
|
+
|
200
|
+
def print_escape_text
|
201
|
+
escape = Thread.new do
|
202
|
+
print "* "
|
203
|
+
print "#{Matrext::process({ :phrase => 'POOF', :sl => true })}"
|
204
|
+
print " *\n"
|
205
|
+
end
|
206
|
+
return escape.join
|
207
|
+
end
|
208
|
+
|
180
209
|
def print_battle_line
|
181
210
|
puts '**************************************'
|
182
211
|
end
|
@@ -43,7 +43,7 @@ module Gemwarrior
|
|
43
43
|
self.stam_max = options.fetch(:stam_max)
|
44
44
|
self.cur_coords = options.fetch(:cur_coords)
|
45
45
|
|
46
|
-
self.god_mode =
|
46
|
+
self.god_mode = options.fetch(:god_mode)
|
47
47
|
end
|
48
48
|
|
49
49
|
def check_self(show_pic = true)
|
@@ -117,14 +117,18 @@ module Gemwarrior
|
|
117
117
|
case direction
|
118
118
|
when 'north', 'n'
|
119
119
|
self.cur_coords = {:x => cur_coords[:x], :y => cur_coords[:y]+1}
|
120
|
+
direction_text = '^^^'
|
120
121
|
when 'east', 'e'
|
121
122
|
self.cur_coords = {:x => cur_coords[:x]+1, :y => cur_coords[:y]}
|
123
|
+
direction_text = '>>>'
|
122
124
|
when 'south', 's'
|
123
125
|
self.cur_coords = {:x => cur_coords[:x], :y => cur_coords[:y]-1}
|
126
|
+
direction_text = 'vvv'
|
124
127
|
when 'west', 'w'
|
125
128
|
self.cur_coords = {:x => cur_coords[:x]-1, :y => cur_coords[:y]}
|
129
|
+
direction_text = '<<<'
|
126
130
|
end
|
127
|
-
print_traveling_text
|
131
|
+
print_traveling_text(direction_text)
|
128
132
|
end
|
129
133
|
|
130
134
|
def attack(world, monster)
|
@@ -141,10 +145,10 @@ module Gemwarrior
|
|
141
145
|
private
|
142
146
|
|
143
147
|
# TRAVEL
|
144
|
-
def print_traveling_text
|
148
|
+
def print_traveling_text(direction_text)
|
145
149
|
loc = Thread.new do
|
146
150
|
print "* "
|
147
|
-
print "#{Matrext::process({ :phrase =>
|
151
|
+
print "#{Matrext::process({ :phrase => direction_text, :sl => true })}"
|
148
152
|
print " *\n"
|
149
153
|
end
|
150
154
|
return loc.join
|
data/lib/gemwarrior/evaluator.rb
CHANGED
@@ -8,8 +8,8 @@ module Gemwarrior
|
|
8
8
|
# CONSTANTS
|
9
9
|
## MESSAGES
|
10
10
|
PROGRAM_NAME = 'Gem Warrior'
|
11
|
-
QUIT_MESSAGE = 'Thanks for playing the game. Until next time...'
|
12
|
-
RESUME_MESSAGE = 'Back to adventuring!'
|
11
|
+
QUIT_MESSAGE = 'Thanks for playing the game. Until next time...'.colorize(:yellow)
|
12
|
+
RESUME_MESSAGE = 'Back to adventuring!'.colorize(:green)
|
13
13
|
SEPARATOR = '=========================================================================='
|
14
14
|
CHANGE_PARAMS = 'Options: name'
|
15
15
|
LIST_PARAMS = 'Options: monsters, items, locations'
|
@@ -59,16 +59,18 @@ module Gemwarrior
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def evaluate(input)
|
62
|
-
|
62
|
+
case input
|
63
|
+
# Ctrl-D or empty command
|
64
|
+
when nil, ""
|
63
65
|
return
|
66
|
+
# real command
|
67
|
+
else
|
68
|
+
tokens = input.split
|
69
|
+
unless input_valid?(input)
|
70
|
+
return ERROR_COMMAND_INVALID
|
71
|
+
end
|
64
72
|
end
|
65
|
-
|
66
|
-
tokens = input.split
|
67
|
-
|
68
|
-
unless input_valid?(input)
|
69
|
-
return ERROR_COMMAND_INVALID
|
70
|
-
end
|
71
|
-
|
73
|
+
|
72
74
|
command = tokens.first.downcase
|
73
75
|
param = tokens[1]
|
74
76
|
|
@@ -216,16 +218,16 @@ module Gemwarrior
|
|
216
218
|
|
217
219
|
def input_valid?(input)
|
218
220
|
tokens = input.split
|
221
|
+
command = tokens[0]
|
219
222
|
commands_and_aliases = commands | aliases | devcmds | devaliases
|
220
|
-
|
223
|
+
|
224
|
+
if commands_and_aliases.include?(command.downcase)
|
221
225
|
if tokens.size.between?(1,2)
|
222
226
|
return true
|
223
227
|
end
|
224
228
|
elsif tokens.empty?
|
225
229
|
return true
|
226
230
|
end
|
227
|
-
return false
|
228
231
|
end
|
229
|
-
|
230
232
|
end
|
231
233
|
end
|
data/lib/gemwarrior/game.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# lib/gemwarrior/game.rb
|
2
2
|
# Main launching point for Gem Warrior
|
3
3
|
|
4
|
+
require 'colorize'
|
5
|
+
require 'matrext'
|
6
|
+
|
4
7
|
require_relative 'entities/player'
|
5
8
|
require_relative 'world'
|
6
9
|
require_relative 'evaluator'
|
@@ -27,9 +30,10 @@ module Gemwarrior
|
|
27
30
|
|
28
31
|
attr_accessor :world, :eval, :repl
|
29
32
|
|
30
|
-
def initialize
|
33
|
+
def initialize(options)
|
31
34
|
# create new world and player
|
32
35
|
self.world = World.new
|
36
|
+
|
33
37
|
world.player = Player.new({
|
34
38
|
:description => PLAYER_DESC_DEFAULT,
|
35
39
|
:level => PLAYER_LEVEL_DEFAULT,
|
@@ -44,7 +48,8 @@ module Gemwarrior
|
|
44
48
|
:dexterity => PLAYER_DEXTERITY_DEFAULT,
|
45
49
|
:inventory => PLAYER_INVENTORY_DEFAULT,
|
46
50
|
:rox => PLAYER_ROX_DEFAULT,
|
47
|
-
:cur_coords => world.location_coords_by_name('Home')
|
51
|
+
:cur_coords => world.location_coords_by_name('Home'),
|
52
|
+
:god_mode => options.fetch(:god_mode)
|
48
53
|
})
|
49
54
|
|
50
55
|
# create the console
|
data/lib/gemwarrior/repl.rb
CHANGED
@@ -12,8 +12,8 @@ module Gemwarrior
|
|
12
12
|
class Repl
|
13
13
|
# CONSTANTS
|
14
14
|
## MESSAGES
|
15
|
-
QUIT_MESSAGE = 'Temporal flux detected. Shutting down...'
|
16
|
-
SPLASH_MESSAGE = 'Welcome to
|
15
|
+
QUIT_MESSAGE = 'Temporal flux detected. Shutting down...'.colorize(:red)
|
16
|
+
SPLASH_MESSAGE = 'Welcome to the land of *Jool*, where randomized fortune is just as likely as mayhem.'
|
17
17
|
|
18
18
|
attr_accessor :world, :eval
|
19
19
|
|
@@ -50,11 +50,14 @@ module Gemwarrior
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def print_splash_message
|
53
|
-
|
54
|
-
|
53
|
+
puts "/-+-+-+ +-+-+-+-+-+-+-\\".colorize(:yellow)
|
54
|
+
puts '|G|E|M| |W|A|R|R|I|O|R|'.colorize(:yellow)
|
55
|
+
puts "\\-+-+-+ +-+-+-+-+-+-+-/".colorize(:yellow)
|
56
|
+
0.upto(SPLASH_MESSAGE.length-1) do print '=' end
|
57
|
+
puts
|
55
58
|
puts SPLASH_MESSAGE
|
56
|
-
0.upto(SPLASH_MESSAGE.length-1) do print
|
57
|
-
|
59
|
+
0.upto(SPLASH_MESSAGE.length-1) do print '=' end
|
60
|
+
puts
|
58
61
|
end
|
59
62
|
|
60
63
|
def print_fortune
|
@@ -88,7 +91,7 @@ module Gemwarrior
|
|
88
91
|
world.player.name,
|
89
92
|
world.location_by_coords(world.player.cur_coords).name
|
90
93
|
]
|
91
|
-
puts (prompt_template % prompt_vars_arr)
|
94
|
+
puts (prompt_template % prompt_vars_arr).colorize(:color => :white, :background => :green)
|
92
95
|
end
|
93
96
|
|
94
97
|
def read_line
|
data/lib/gemwarrior/world.rb
CHANGED
@@ -36,19 +36,26 @@ module Gemwarrior
|
|
36
36
|
0.upto(WORLD_DIM_HEIGHT-1) do |count_y|
|
37
37
|
print ' '
|
38
38
|
0.upto(WORLD_DIM_WIDTH-1) do
|
39
|
-
print '
|
39
|
+
print '---'
|
40
40
|
end
|
41
41
|
print "\n"
|
42
42
|
print "#{(WORLD_DIM_HEIGHT-1) - count_y} "
|
43
43
|
0.upto(WORLD_DIM_WIDTH-1) do |count_x|
|
44
|
-
|
44
|
+
cur_map_coords = {:x => count_x, :y => (WORLD_DIM_HEIGHT-1) - count_y}
|
45
|
+
if self.player.cur_coords.eql?(cur_map_coords)
|
46
|
+
print '|O|'
|
47
|
+
elsif location_by_coords(cur_map_coords)
|
45
48
|
print '|X|'
|
46
49
|
else
|
47
|
-
print '|
|
50
|
+
print '| |'
|
48
51
|
end
|
49
52
|
end
|
50
53
|
print "\n"
|
51
54
|
end
|
55
|
+
print ' '
|
56
|
+
0.upto(WORLD_DIM_WIDTH-1) do
|
57
|
+
print '---'
|
58
|
+
end
|
52
59
|
puts
|
53
60
|
print ' '
|
54
61
|
0.upto(WORLD_DIM_WIDTH-1) do |count_x|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemwarrior
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Chadwick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: os
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 1.8.2
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: colorize
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.7.7
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.7.7
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: pry-byebug
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|