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.
@@ -1,42 +1,52 @@
1
- # lib/gemwarrior/game.rb
2
- # Main launching point for Gem Warrior
3
-
4
- require_relative 'constants'
5
- require_relative 'world'
6
- require_relative 'player'
7
-
8
- require_relative 'repl'
9
- require_relative 'evaluator'
10
-
11
- module Gemwarrior
12
- class Game
13
- include AttributePools
14
-
15
- def initialize
16
- # create new world and player
17
- @world = World.new
18
- @player = Player.new(
19
- PLYR_LEVEL_DEFAULT,
20
- PLYR_XP_DEFAULT,
21
- PLYR_HP_CUR_DEFAULT,
22
- PLYR_HP_MAX_DEFAULT,
23
- PLYR_STAM_CUR_DEFAULT,
24
- PLYR_STAM_MAX_DEFAULT,
25
- PLYR_ATK_LO_DEFAULT,
26
- PLYR_ATK_HI_DEFAULT,
27
- Inventory.new,
28
- PLYR_ROX_DEFAULT,
29
- @world.loc_by_id(0)
30
- )
31
- @world.player = @player
32
-
33
- # create the console
34
- @eval = Evaluator.new(@world)
35
- @repl = Repl.new(@world, @eval)
36
-
37
- # enter Jool!
38
- @repl.start('look')
39
- end
40
-
41
- end
42
- end
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
@@ -1,61 +1,65 @@
1
- # lib/gemwarrior/inventory.rb
2
- # Collection of items a creature possesses
3
-
4
- module Gemwarrior
5
- class Inventory
6
- include Errors
7
-
8
- def initialize(inventory = [])
9
- @inventory = inventory
10
- end
11
-
12
- def list_contents
13
- contents_text = "You check your inventory"
14
- if @inventory.empty?
15
- return contents_text << ERROR_INVENTORY_EMPTY
16
- else
17
- @item_names = []
18
- @inventory.each do |i|
19
- @item_names.push(i.name)
20
- end
21
- return contents_text << ": #{@inventory.map(&:name).join ', '}"
22
- end
23
- end
24
-
25
- def describe_item(item_name)
26
- if @inventory.map(&:name).include?(item_name)
27
- @inventory.each do |i|
28
- if i.name.eql?(item_name)
29
- return "#{i.description}"
30
- end
31
- end
32
- else
33
- ERROR_ITEM_INVENTORY_INVALID
34
- end
35
- end
36
-
37
- def add_item(cur_loc, item_name)
38
- cur_loc.items.each do |i|
39
- if i.name.eql?(item_name)
40
- if i.takeable
41
- @inventory.push(i)
42
- cur_loc.remove_item_from_location(item_name)
43
- return "Added #{item_name} to your increasing collection of bits of tid.\n"
44
- else
45
- ERROR_TAKE_ITEM_UNTAKEABLE
46
- end
47
- end
48
- end
49
- ERROR_TAKE_ITEM_INVALID
50
- end
51
-
52
- def remove_item(item_name)
53
- if @inventory.map(&:name).include?(item_name)
54
- @inventory.reject! { |item| item.name == item_name }
55
- 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"
56
- else
57
- puts ERROR_INVENTORY_REMOVE_INVALID
58
- end
59
- end
60
- end
61
- end
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
@@ -1,28 +1,24 @@
1
- # lib/gemwarrior/item.rb
2
- # Item base class
3
-
4
- require_relative 'constants'
5
-
6
- module Gemwarrior
7
- class Item
8
- include Entities::Items
9
-
10
- attr_reader :id, :name, :description, :takeable
11
-
12
- def initialize(
13
- id,
14
- name = ITEM_NAME_DEFAULT,
15
- description = ITEM_DESC_DEFAULT,
16
- takeable
17
- )
18
- @id = id
19
- @name = name
20
- @description = description
21
- @takeable = takeable
22
- end
23
-
24
- def is_takeable?
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
@@ -1,101 +1,110 @@
1
- # lib/gemwarrior/location.rb
2
- # Place in the game
3
-
4
- require 'matrext'
5
-
6
- require_relative 'constants'
7
-
8
- module Gemwarrior
9
- class Location
10
- include Errors
11
-
12
- attr_reader :id, :name, :description, :locs_connected, :items
13
-
14
- def initialize(id, name, description, locs_connected, danger_level, items, monsters_available)
15
- @id = id
16
- @name = name
17
- @description = description
18
- @locs_connected = locs_connected
19
- @danger_level = danger_level
20
- @items = items
21
- @monsters_available = monsters_available
22
- @monsters_abounding = []
23
- end
24
-
25
- def describe
26
- desc_text = ""
27
- desc_text << "[ #{@name} ]\n"
28
- desc_text << @description
29
- populate_monsters
30
- unless list_items.nil?
31
- desc_text << list_items
32
- end
33
- unless list_monsters.nil?
34
- desc_text << list_monsters
35
- end
36
- return desc_text
37
- end
38
-
39
- def describe_item(item_name)
40
- @item_names = []
41
- @items.each do |i|
42
- @item_names.push(i.name)
43
- end
44
-
45
- if @item_names.include?(item_name)
46
- @items.each do |i|
47
- if i.name.eql?(item_name)
48
- puts "#{i.description}"
49
- return
50
- end
51
- end
52
- else
53
- puts ERROR_ITEM_LOC_INVALID
54
- end
55
- end
56
-
57
- def list_items
58
- return "\n >> Shiny object(s): #{@items.map(&:name).join(', ')}" if @items.length > 0
59
- end
60
-
61
- def list_monsters
62
- return "\n >> Monster(s) abound: #{@monsters_abounding.map(&:name).join(', ')}" if @monsters_abounding.length > 0
63
- end
64
-
65
- def remove_item_from_location(item_name)
66
- @items.each do |i|
67
- if i.name.eql?(item_name)
68
- @items.delete_at(@items.find_index(item_name).to_i)
69
- end
70
- end
71
- end
72
-
73
- def has_monster?
74
- found = false
75
- unless @danger_level.eql?(:none)
76
- max = DANGER_LEVEL[@danger_level]
77
- trigger_values = 0..max
78
- actual_value = rand(1..100)
79
-
80
- if trigger_values.include?(actual_value)
81
- found = true
82
- end
83
- end
84
- return found
85
- end
86
-
87
- def populate_monsters
88
- if has_monster?
89
- @monsters_abounding = []
90
- return @monsters_abounding.push(@monsters_available[rand(0..@monsters_available.length-1)])
91
- else
92
- return nil
93
- end
94
- end
95
-
96
- def has_loc_to_the?(direction)
97
- @locs_connected[direction.to_sym]
98
- end
99
-
100
- end
101
- end
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