gemwarrior 0.3.1 → 0.3.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 +0 -0
- data/lib/gemwarrior/creature.rb +53 -47
- data/lib/gemwarrior/{constants.rb → defaults.rb} +103 -158
- data/lib/gemwarrior/evaluator.rb +165 -151
- data/lib/gemwarrior/game.rb +52 -42
- data/lib/gemwarrior/inventory.rb +65 -61
- data/lib/gemwarrior/item.rb +24 -28
- data/lib/gemwarrior/location.rb +110 -101
- data/lib/gemwarrior/monster.rb +44 -48
- data/lib/gemwarrior/player.rb +193 -185
- data/lib/gemwarrior/repl.rb +95 -92
- data/lib/gemwarrior/version.rb +1 -1
- data/lib/gemwarrior/world.rb +328 -269
- metadata +4 -6
data/lib/gemwarrior/game.rb
CHANGED
@@ -1,42 +1,52 @@
|
|
1
|
-
# lib/gemwarrior/game.rb
|
2
|
-
# Main launching point for Gem Warrior
|
3
|
-
|
4
|
-
require_relative '
|
5
|
-
require_relative '
|
6
|
-
|
7
|
-
|
8
|
-
require_relative '
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
1
|
+
# lib/gemwarrior/game.rb
|
2
|
+
# Main launching point for Gem Warrior
|
3
|
+
|
4
|
+
require_relative 'world'
|
5
|
+
require_relative 'player'
|
6
|
+
|
7
|
+
require_relative 'repl'
|
8
|
+
require_relative 'evaluator'
|
9
|
+
|
10
|
+
module Gemwarrior
|
11
|
+
class Game
|
12
|
+
# CONSTANTS
|
13
|
+
## PLAYER DEFAULTS
|
14
|
+
PLYR_LEVEL_DEFAULT = 1
|
15
|
+
PLYR_XP_DEFAULT = 0
|
16
|
+
PLYR_HP_CUR_DEFAULT = 10
|
17
|
+
PLYR_HP_MAX_DEFAULT = 10
|
18
|
+
PLYR_STAM_CUR_DEFAULT = 20
|
19
|
+
PLYR_STAM_MAX_DEFAULT = 20
|
20
|
+
PLYR_ATK_LO_DEFAULT = 1
|
21
|
+
PLYR_ATK_HI_DEFAULT = 2
|
22
|
+
PLYR_ROX_DEFAULT = 0
|
23
|
+
|
24
|
+
attr_accessor :world, :eval, :repl
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
# create new world and player
|
28
|
+
self.world = World.new
|
29
|
+
world.player = Player.new(
|
30
|
+
PLYR_LEVEL_DEFAULT,
|
31
|
+
PLYR_XP_DEFAULT,
|
32
|
+
PLYR_HP_CUR_DEFAULT,
|
33
|
+
PLYR_HP_MAX_DEFAULT,
|
34
|
+
PLYR_STAM_CUR_DEFAULT,
|
35
|
+
PLYR_STAM_MAX_DEFAULT,
|
36
|
+
PLYR_ATK_LO_DEFAULT,
|
37
|
+
PLYR_ATK_HI_DEFAULT,
|
38
|
+
Inventory.new,
|
39
|
+
PLYR_ROX_DEFAULT,
|
40
|
+
world.loc_by_id(0)
|
41
|
+
)
|
42
|
+
|
43
|
+
# create the console
|
44
|
+
self.eval = Evaluator.new(world)
|
45
|
+
self.repl = Repl.new(world, eval)
|
46
|
+
|
47
|
+
# enter Jool!
|
48
|
+
repl.start('look')
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/lib/gemwarrior/inventory.rb
CHANGED
@@ -1,61 +1,65 @@
|
|
1
|
-
# lib/gemwarrior/inventory.rb
|
2
|
-
# Collection of items a creature possesses
|
3
|
-
|
4
|
-
module Gemwarrior
|
5
|
-
class Inventory
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
1
|
+
# lib/gemwarrior/inventory.rb
|
2
|
+
# Collection of items a creature possesses
|
3
|
+
|
4
|
+
module Gemwarrior
|
5
|
+
class Inventory
|
6
|
+
# CONSTANTS
|
7
|
+
## ERRORS
|
8
|
+
ERROR_INVENTORY_EMPTY = '...and find you currently have diddly-squat, which is nothing.'
|
9
|
+
ERROR_ITEM_REMOVE_INVALID = 'Your inventory does not contain that item, so you can\'t drop it.'
|
10
|
+
ERROR_ITEM_ADD_UNTAKEABLE = 'That would be great if you could take that thing, wouldn\'t it? Well, it\'s not so great for you right now.'
|
11
|
+
ERROR_ITEM_ADD_INVALID = 'That item doesn\'t exist here.'
|
12
|
+
ERROR_ITEM_DESCRIBE_INVALID = 'You don\'t possess that.'
|
13
|
+
|
14
|
+
attr_accessor :inventory
|
15
|
+
|
16
|
+
def initialize(inventory = [])
|
17
|
+
self.inventory = inventory
|
18
|
+
end
|
19
|
+
|
20
|
+
def list_contents
|
21
|
+
contents_text = "You check your inventory"
|
22
|
+
if inventory.empty?
|
23
|
+
return contents_text << ERROR_INVENTORY_EMPTY
|
24
|
+
else
|
25
|
+
return contents_text << ": #{inventory.map(&:name).join ', '}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def describe_item(item_name)
|
30
|
+
if inventory.map(&:name).include?(item_name)
|
31
|
+
inventory.each do |i|
|
32
|
+
if i.name.eql?(item_name)
|
33
|
+
return "#{i.description}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else
|
37
|
+
ERROR_ITEM_DESCRIBE_INVALID
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_item(cur_loc, item_name)
|
42
|
+
cur_loc.items.each do |i|
|
43
|
+
if i.name.eql?(item_name)
|
44
|
+
if i.takeable
|
45
|
+
inventory.push(i)
|
46
|
+
cur_loc.remove_item(item_name)
|
47
|
+
return "Added #{item_name} to your increasing collection of bits of tid.\n"
|
48
|
+
else
|
49
|
+
return ERROR_ITEM_ADD_UNTAKEABLE
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
ERROR_ITEM_ADD_INVALID
|
54
|
+
end
|
55
|
+
|
56
|
+
def remove_item(item_name)
|
57
|
+
if inventory.map(&:name).include?(item_name)
|
58
|
+
inventory.reject! { |item| item.name == item_name }
|
59
|
+
puts "The #{item_name} has been thrown on the ground, but far out of reach, and you're much too lazy to go get it now, so it's as good as gone.\n"
|
60
|
+
else
|
61
|
+
ERROR_ITEM_REMOVE_INVALID
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/gemwarrior/item.rb
CHANGED
@@ -1,28 +1,24 @@
|
|
1
|
-
# lib/gemwarrior/item.rb
|
2
|
-
# Item base class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
@takeable
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
# lib/gemwarrior/item.rb
|
2
|
+
# Item base class
|
3
|
+
|
4
|
+
module Gemwarrior
|
5
|
+
class Item
|
6
|
+
attr_accessor :id, :name, :description, :takeable
|
7
|
+
|
8
|
+
def initialize(
|
9
|
+
id,
|
10
|
+
name,
|
11
|
+
description,
|
12
|
+
takeable
|
13
|
+
)
|
14
|
+
self.id = id
|
15
|
+
self.name = name
|
16
|
+
self.description = description
|
17
|
+
self.takeable = takeable
|
18
|
+
end
|
19
|
+
|
20
|
+
def is_takeable?
|
21
|
+
takeable
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/gemwarrior/location.rb
CHANGED
@@ -1,101 +1,110 @@
|
|
1
|
-
# lib/gemwarrior/location.rb
|
2
|
-
# Place in the game
|
3
|
-
|
4
|
-
require 'matrext'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
|
1
|
+
# lib/gemwarrior/location.rb
|
2
|
+
# Place in the game
|
3
|
+
|
4
|
+
require 'matrext'
|
5
|
+
|
6
|
+
module Gemwarrior
|
7
|
+
class Location
|
8
|
+
# CONSTANTS
|
9
|
+
## HASHES
|
10
|
+
DANGER_LEVEL = {:none => 0, :low => 15, :moderate => 30, :high => 55, :assured => 100}
|
11
|
+
|
12
|
+
## ERRORS
|
13
|
+
ERROR_LOCATION_ITEM_REMOVE_INVALID = 'That item cannot be removed as it doesn\'t exist here.'
|
14
|
+
ERROR_LOCATION_DESCRIBE_ITEM_INVALID = 'You don\'t see that here.'
|
15
|
+
|
16
|
+
attr_accessor :id, :name, :description, :locs_connected, :danger_level,
|
17
|
+
:items, :monsters_available, :monsters_abounding, :checked_for_monsters
|
18
|
+
|
19
|
+
def initialize(id, name, description, locs_connected, danger_level, items, monsters_available)
|
20
|
+
self.id = id
|
21
|
+
self.name = name
|
22
|
+
self.description = description
|
23
|
+
self.locs_connected = locs_connected
|
24
|
+
self.danger_level = danger_level
|
25
|
+
self.items = items
|
26
|
+
self.monsters_available = monsters_available
|
27
|
+
self.monsters_abounding = []
|
28
|
+
self.checked_for_monsters = false
|
29
|
+
end
|
30
|
+
|
31
|
+
def describe
|
32
|
+
desc_text = ""
|
33
|
+
desc_text << "[ #{name} ]\n"
|
34
|
+
desc_text << description
|
35
|
+
unless checked_for_monsters?
|
36
|
+
populate_monsters
|
37
|
+
end
|
38
|
+
unless list_items.nil?
|
39
|
+
desc_text << list_items
|
40
|
+
end
|
41
|
+
unless list_monsters.nil?
|
42
|
+
desc_text << list_monsters
|
43
|
+
end
|
44
|
+
|
45
|
+
return desc_text
|
46
|
+
end
|
47
|
+
|
48
|
+
def describe_item(item_name)
|
49
|
+
if items.map(&:name).include?(item_name)
|
50
|
+
items.each do |i|
|
51
|
+
if i.name.eql?(item_name)
|
52
|
+
return "#{i.description}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
else
|
56
|
+
ERROR_LOCATION_DESCRIBE_ITEM_INVALID
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def remove_item(item_name)
|
61
|
+
if items.map(&:name).include?(item_name)
|
62
|
+
items.reject! { |item| item.name == item_name }
|
63
|
+
else
|
64
|
+
ERROR_LOCATION_ITEM_REMOVE_INVALID
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def has_loc_to_the?(direction)
|
69
|
+
locs_connected[direction.to_sym]
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def checked_for_monsters?
|
75
|
+
checked_for_monsters
|
76
|
+
end
|
77
|
+
|
78
|
+
def list_items
|
79
|
+
return "\n >> Shiny object(s): #{items.map(&:name).join(', ')}" if items.length > 0
|
80
|
+
end
|
81
|
+
|
82
|
+
def list_monsters
|
83
|
+
return "\n >> Monster(s) abound: #{monsters_abounding.map(&:name).join(', ')}" if monsters_abounding.length > 0
|
84
|
+
end
|
85
|
+
|
86
|
+
def has_monster?
|
87
|
+
found = false
|
88
|
+
unless danger_level.eql?(:none)
|
89
|
+
max = DANGER_LEVEL[danger_level]
|
90
|
+
trigger_values = 0..max
|
91
|
+
actual_value = rand(1..100)
|
92
|
+
|
93
|
+
if trigger_values.include?(actual_value)
|
94
|
+
found = true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
return found
|
98
|
+
end
|
99
|
+
|
100
|
+
def populate_monsters
|
101
|
+
checked_for_monsters = true
|
102
|
+
if has_monster?
|
103
|
+
self.monsters_abounding = []
|
104
|
+
return monsters_abounding.push(monsters_available[rand(0..monsters_available.length-1)])
|
105
|
+
else
|
106
|
+
return nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|