gemwarrior 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d182cac6acd35cbe8ac4da399355ee9d412ee6e8
4
- data.tar.gz: 2624b5ee0c3aa9d425c7f13d76a7086d96beb29c
3
+ metadata.gz: 9d9fbe46192891851f0b80f4be5c0488423ac649
4
+ data.tar.gz: 0ed5b2c8a5056a4e7ad7e384da03128f5584d5c7
5
5
  SHA512:
6
- metadata.gz: 319d3b0825eabaa628f72d4d38c4116232c3f5bc2c5439be735cfbbfdab20714d1267383fbe2bed92eab1402b73878e4134a6269ee55a9e8fc35c4316c270308
7
- data.tar.gz: fbc3ccbf92e0fbad399bc85945285dce57573267a67ea92d2c92f47e9429ec9e6c51e9d42b1f9a0810dc8415520bd2947dca3dc05e88fd1ae9874f3e83aa1d8d
6
+ metadata.gz: b881e6754a51e72f2f76ceb7504841fb3284cb4fc7699292b830d3309e45978c6391a1b8ac46181306b618b441e97fffaaffae9d8fd6b511c863b95485d04ecf
7
+ data.tar.gz: f413966728db827f7afda8102a065e1d05726830902a0876e32f0384ab68a358c0be25b9eff172aa187d17e8e8f74d36a73879c0c6c9d950c601b8e742770d6a
data/bin/gemwarrior CHANGED
File without changes
@@ -1,47 +1,53 @@
1
- # lib/gemwarrior/creature.rb
2
- # Creature base class
3
-
4
- require_relative 'constants'
5
- require_relative 'inventory'
6
-
7
- module Gemwarrior
8
- class Creature
9
- attr_reader :name, :description
10
-
11
- def initialize(
12
- id,
13
- name = 'Creature',
14
- face = 'calm',
15
- hands = 'smooth',
16
- mood = 'happy',
17
- level = 1,
18
- hp_cur = 10,
19
- hp_max = 10,
20
- atk_lo = 1,
21
- atk_hi = 3,
22
- inventory = Inventory.new,
23
- rox = 1
24
- )
25
- @id = id
26
- @name = name
27
- @face = face
28
- @hands = hands
29
- @mood = mood
30
-
31
- @level = level
32
- @hp_cur = hp_cur
33
- @hp_max = hp_max
34
-
35
- @atk_lo = atk_lo
36
- @atk_hi = atk_hi
37
-
38
- @inventory = inventory
39
- @rox = rox
40
- end
41
-
42
- def status
43
- puts "The #{name}'s face is #{@face}, hands are #{@hands}, and general mood is #{@mood}."
44
- end
45
-
46
- end
47
- end
1
+ # lib/gemwarrior/creature.rb
2
+ # Creature base class
3
+
4
+ require_relative 'inventory'
5
+
6
+ module Gemwarrior
7
+ class Creature
8
+ # CONSTANTS
9
+ CREATURE_NAME_DEFAULT = 'Creature'
10
+ CREATURE_DESCRIPTION_DEFAULT = 'A creature of some sort.'
11
+ CREATURE_FACE_DEFAULT = 'calm'
12
+ CREATURE_HANDS_DEFAULT = 'smooth'
13
+ CREATURE_MOOD_DEFAULT = 'happy'
14
+
15
+ attr_accessor :id, :name, :description, :face, :hands, :mood,
16
+ :level, :hp_cur, :hp_max, :inventory
17
+
18
+ def initialize(
19
+ id,
20
+ name = CREATURE_NAME_DEFAULT,
21
+ description = CREATURE_DESCRIPTION_DEFAULT,
22
+ face = CREATURE_FACE_DEFAULT,
23
+ hands = CREATURE_HANDS_DEFAULT,
24
+ mood = CREATURE_MOOD_DEFAULT,
25
+ level = 1,
26
+ hp_cur = 10,
27
+ hp_max = 10,
28
+ inventory = Inventory.new
29
+ )
30
+ self.id = id
31
+ self.name = name
32
+ self.description = description
33
+ self.face = face
34
+ self.hands = hands
35
+ self.mood = mood
36
+
37
+ self.level = level
38
+ self.hp_cur = hp_cur
39
+ self.hp_max = hp_max
40
+
41
+ self.inventory = inventory
42
+ end
43
+
44
+ def describe
45
+ self.description
46
+ end
47
+
48
+ def status
49
+ status_text = "[#{name}][LVL: #{level}][HP:#{hp_cur}|#{hp_max}]\n"
50
+ status_text << "Its face is #{face}, hands are #{hands}, and general mood is #{mood}."
51
+ end
52
+ end
53
+ end
@@ -1,158 +1,103 @@
1
- # lib/gemwarrior/constants.rb
2
- # List of constant values
3
-
4
- module Gemwarrior
5
- PROGRAM_NAME = 'Gem Warrior'
6
- SPLASH_MESSAGE = 'Welcome to Gem Warrior, where randomized fortune is just as likely as mayhem.'
7
- QUIT_MESSAGE = 'Thanks for playing the game. Until next time...'
8
- RESUME_MESSAGE = 'Back to adventuring!'
9
- SEPARATOR = '==========================================================='
10
- CHANGE_PARAMS = 'Options: name'
11
-
12
- DANGER_LEVEL = {:none => 0, :low => 15, :moderate => 30, :high => 55, :assured => 100}
13
-
14
- module Errors
15
- ERROR_COMMAND_INVALID = 'That\'s not something the game yet understands.'
16
- ERROR_INVENTORY_EMPTY = '...and find you currently have diddly-squat, which is nothing.'
17
- ERROR_INVENTORY_REMOVE_INVALID = 'Your inventory does not contain that item, so you can\'t drop it.'
18
- ERROR_ITEM_LOC_INVALID = 'You don\'t see that there.'
19
- ERROR_ITEM_INVENTORY_INVALID = 'You don\'t possess that.'
20
- ERROR_TAKE_PARAM_MISSING = 'You can\'t just take. You gotta choose something.'
21
- ERROR_TAKE_ITEM_UNTAKEABLE = 'That would be great if you could take that thing, wouldn\'t it? Well, it\'s not so great for you right now.'
22
- ERROR_TAKE_ITEM_INVALID = 'That item doesn\'t exist here.'
23
- ERROR_DROP_PARAM_MISSING = 'You can\'t just drop indiscriminately. You gotta choose something.'
24
- ERROR_GO_DIR_MISSING = 'Just wander aimlessly? A direction would be nice.'
25
- ERROR_GO_DIR_INVALID = 'The place in that direction is far, far, FAR too dangerous. You should try a different way.'
26
- ERROR_CHANGE_PARAM_MISSING = 'Ch-ch-changes...aren\'t happening because you didn\'t specify what to change.'
27
- ERROR_CHANGE_PARAM_INVALID = 'You can\'t change that...yet.'
28
- end
29
-
30
- module AttributePools
31
- # character pools
32
- CHAR_UPPER_POOL = (65..90).map{ |i| i.chr }
33
- CHAR_LOWER_POOL = (97..122).map{ |i| i.chr }
34
- CHAR_LOWER_VOWEL_POOL = ['a','e','i','o','u','y']
35
-
36
- # attribute pools
37
- FACE_DESC = ['smooth', 'tired', 'ruddy', 'moist', 'shocked']
38
- HANDS_DESC = ['worn', 'balled into fists', 'relaxed', 'cracked', 'tingly', 'mom\'s spaghetti']
39
- MOOD_DESC = ['calm', 'excited', 'depressed', 'tense', 'lackadaisical', 'angry', 'positive']
40
-
41
- PLYR_DESC_DEFAULT = 'Picked to do battle against a wizened madman for a shiny something or other for world-saving purposes, you\'re actually fairly able, as long as you\'ve had breakfast first.'
42
-
43
- PLYR_LEVEL_DEFAULT = 1
44
- PLYR_XP_DEFAULT = 0
45
- PLYR_HP_CUR_DEFAULT = 10
46
- PLYR_HP_MAX_DEFAULT = 10
47
- PLYR_STAM_CUR_DEFAULT = 20
48
- PLYR_STAM_MAX_DEFAULT = 20
49
- PLYR_ATK_LO_DEFAULT = 1
50
- PLYR_ATK_HI_DEFAULT = 2
51
- PLYR_ROX_DEFAULT = 0
52
- end
53
-
54
- module Entities
55
- module Locations
56
- LOC_ID_HOME = 0
57
- LOC_NAME_HOME = 'Home'
58
- LOC_DESC_HOME = 'The little, unimportant, decrepit hut that you live in.'
59
- LOC_CONNECTIONS_HOME = {:north => 4, :east => 1, :south => nil, :west => 3}
60
-
61
- LOC_ID_CAVE_ENTRANCE = 1
62
- LOC_NAME_CAVE_ENTRANCE = 'Cave (Entrance)'
63
- LOC_DESC_CAVE_ENTRANCE = 'A nearby, dank cavern\'s entrance, surely filled with stacktites, stonemites, and rocksites.'
64
- LOC_CONNECTIONS_CAVE_ENTRANCE = {:north => nil, :east => 2, :south => nil, :west => 0}
65
-
66
- LOC_ID_CAVE_ROOM1 = 2
67
- LOC_NAME_CAVE_ROOM1 = 'Cave (Room1)'
68
- LOC_DESC_CAVE_ROOM1 = 'Now inside the first cavernous room, you confirm that there are stacktites, stonemites, rocksites, and even one or two pebblejites.'
69
- LOC_CONNECTIONS_CAVE_ROOM1 = {:north => nil, :east => nil, :south => nil, :west => 1}
70
-
71
- LOC_ID_FOREST = 3
72
- LOC_NAME_FOREST = 'Forest'
73
- LOC_DESC_FOREST = 'Trees exist here, in droves.'
74
- LOC_CONNECTIONS_FOREST = {:north => nil, :east => 0, :south => nil, :west => nil}
75
-
76
- LOC_ID_SKYTOWER = 4
77
- LOC_NAME_SKYTOWER = 'Emerald\'s Sky Tower'
78
- LOC_DESC_SKYTOWER = 'The craziest guy that ever existed is around here somewhere amongst the cloud floors, snow walls, and ethereal vibe.'
79
- LOC_CONNECTIONS_SKYTOWER = {:north => nil, :east => nil, :south => 0, :west => nil}
80
- end
81
-
82
- module Monsters
83
- MOB_ID_ALEXANDRAT = 0
84
- MOB_NAME_ALEXANDRAT = 'Alexandrat'
85
- MOB_DESC_ALEXANDRAT = 'Tiny, but fierce, color-changing rodent.'
86
- MOB_LEVEL_ALEXANDRAT = 1..2
87
-
88
- MOB_ID_AMBEROO = 1
89
- MOB_NAME_AMBEROO = 'Amberoo'
90
- MOB_DESC_AMBEROO = 'Fossilized and jumping around like an adorably dangerous threat from the past.'
91
- MOB_LEVEL_AMBEROO = 1..2
92
-
93
- MOB_ID_AMETHYSTLE = 2
94
- MOB_NAME_AMETHYSTLE = 'Amethystle'
95
- MOB_DESC_AMETHYSTLE = 'Sober and contemplative, it moves with purplish tentacles swaying in the breeze.'
96
- MOB_LEVEL_AMETHYSTLE = 1..3
97
-
98
- MOB_ID_AQUAMARINE = 3
99
- MOB_NAME_AQUAMARINE = 'Aquamarine'
100
- MOB_DESC_AQUAMARINE = 'It is but one of the few, the proud, the underwater.'
101
- MOB_LEVEL_AQUAMARINE = 2..4
102
-
103
- MOB_ID_APATIGER = 4
104
- MOB_NAME_APATIGER = 'Apatiger'
105
- MOB_DESC_APATIGER = 'Apathetic about most everything as it lazes around, save for eating you.'
106
- MOB_LEVEL_APATIGER = 3..5
107
-
108
- MOB_ID_BLOODSTORM = 5
109
- MOB_NAME_BLOODSTORM = 'Bloodstorm'
110
- MOB_DESC_BLOODSTORM = 'A literal swirling, maniacal vortex of human hemoglobin.'
111
- MOB_LEVEL_BLOODSTORM = 5..6
112
-
113
- MOB_ID_CITRINAGA = 6
114
- MOB_NAME_CITRINAGA = 'Citrinaga'
115
- MOB_DESC_CITRINAGA = 'Refreshing in its shiny, gleaming effectiveness at ending your life.'
116
- MOB_LEVEL_CITRINAGA = 3..4
117
-
118
- MOB_ID_CORALIZ = 7
119
- MOB_NAME_CORALIZ = 'Coraliz'
120
- MOB_DESC_CORALIZ = 'Small blue lizard that slithers around, nipping at your ankles.'
121
- MOB_LEVEL_CORALIZ = 2..3
122
-
123
- MOB_ID_CUBICAT = 8
124
- MOB_NAME_CUBICAT = 'Cubicat'
125
- MOB_DESC_CUBICAT = 'Perfectly geometrically cubed feline, fresh from its woven enclosure, claws at the ready.'
126
- MOB_LEVEL_CUBICAT = 4..5
127
-
128
- MOB_ID_DIAMAN = 9
129
- MOB_NAME_DIAMAN = 'Diaman'
130
- MOB_DESC_DIAMAN = 'Crystalline structure in the form of a man, lumbering toward you, with outstretched, edged pincers.'
131
- MOB_LEVEL_DIAMAN = 6..7
132
-
133
- MOB_NAME_DEFAULT = 'Rocky'
134
- MOB_DESC_DEFAULT = 'It\'s a monster, and it\'s not happy.'
135
- end
136
-
137
- module Items
138
- ITEM_ID_STONE = 0
139
- ITEM_NAME_STONE = 'stone'
140
- ITEM_DESC_STONE = 'A small, sharp mega pebble, suitable for tossing in amusement, and perhaps combat.'
141
- ITEM_ID_BED = 1
142
- ITEM_NAME_BED = 'bed'
143
- ITEM_DESC_BED = 'The place where you sleep when you\'re not adventuring.'
144
- ITEM_ID_STALACTITE = 2
145
- ITEM_NAME_STALACTITE = 'stalactite'
146
- ITEM_DESC_STALACTITE = 'Long protrusion of cave adornment, broken off and fallen to the ground, where the stalagmites sneer at it from.'
147
- ITEM_ID_FEATHER = 3
148
- ITEM_NAME_FEATHER = 'feather'
149
- ITEM_DESC_FEATHER = 'Soft and tender, unlike the craven bird that probably shed it.'
150
- ITEM_ID_GUN = 4
151
- ITEM_NAME_GUN = 'gun'
152
- ITEM_DESC_GUN = 'Pew pew goes this firearm you wield, ifn\'t it weren\'t unloaded.'
153
-
154
- ITEM_NAME_DEFAULT = 'thing'
155
- ITEM_DESC_DEFAULt = 'Something truly interesting and worth your time to look at and possess.'
156
- end
157
- end
158
- end
1
+ # lib/gemwarrior/defaults.rb
2
+ # List of default values for world entities
3
+
4
+ module Gemwarrior
5
+ module Entities
6
+ module Monsters
7
+ MOB_ID_ALEXANDRAT = 0
8
+ MOB_NAME_ALEXANDRAT = 'Alexandrat'
9
+ MOB_DESC_ALEXANDRAT = 'Tiny, but fierce, color-changing rodent.'
10
+ MOB_LEVEL_ALEXANDRAT = 1
11
+
12
+ MOB_ID_AMBEROO = 1
13
+ MOB_NAME_AMBEROO = 'Amberoo'
14
+ MOB_DESC_AMBEROO = 'Fossilized and jumping around like an adorably dangerous threat from the past.'
15
+ MOB_LEVEL_AMBEROO = 1
16
+
17
+ MOB_ID_AMETHYSTLE = 2
18
+ MOB_NAME_AMETHYSTLE = 'Amethystle'
19
+ MOB_DESC_AMETHYSTLE = 'Sober and contemplative, it moves with purplish tentacles swaying in the breeze.'
20
+ MOB_LEVEL_AMETHYSTLE = 2
21
+
22
+ MOB_ID_AQUAMARINE = 3
23
+ MOB_NAME_AQUAMARINE = 'Aquamarine'
24
+ MOB_DESC_AQUAMARINE = 'It is but one of the few, the proud, the underwater.'
25
+ MOB_LEVEL_AQUAMARINE = 3
26
+
27
+ MOB_ID_APATIGER = 4
28
+ MOB_NAME_APATIGER = 'Apatiger'
29
+ MOB_DESC_APATIGER = 'Apathetic about most everything as it lazes around, save for eating you.'
30
+ MOB_LEVEL_APATIGER = 4
31
+
32
+ MOB_ID_BLOODSTORM = 5
33
+ MOB_NAME_BLOODSTORM = 'Bloodstorm'
34
+ MOB_DESC_BLOODSTORM = 'A literal swirling, maniacal vortex of human hemoglobin.'
35
+ MOB_LEVEL_BLOODSTORM = 5
36
+
37
+ MOB_ID_CITRINAGA = 6
38
+ MOB_NAME_CITRINAGA = 'Citrinaga'
39
+ MOB_DESC_CITRINAGA = 'Refreshing in its shiny, gleaming effectiveness at ending your life.'
40
+ MOB_LEVEL_CITRINAGA = 4
41
+
42
+ MOB_ID_CORALIZ = 7
43
+ MOB_NAME_CORALIZ = 'Coraliz'
44
+ MOB_DESC_CORALIZ = 'Small blue lizard that slithers around, nipping at your ankles.'
45
+ MOB_LEVEL_CORALIZ = 3
46
+
47
+ MOB_ID_CUBICAT = 8
48
+ MOB_NAME_CUBICAT = 'Cubicat'
49
+ MOB_DESC_CUBICAT = 'Perfectly geometrically cubed feline, fresh from its woven enclosure, claws at the ready.'
50
+ MOB_LEVEL_CUBICAT = 4
51
+
52
+ MOB_ID_DIAMAN = 9
53
+ MOB_NAME_DIAMAN = 'Diaman'
54
+ MOB_DESC_DIAMAN = 'Crystalline structure in the form of a man, lumbering toward you, with outstretched, edged pincers.'
55
+ MOB_LEVEL_DIAMAN = 6
56
+ end
57
+
58
+ module Items
59
+ ITEM_ID_STONE = 0
60
+ ITEM_NAME_STONE = 'stone'
61
+ ITEM_DESC_STONE = 'A small, sharp mega pebble, suitable for tossing in amusement, and perhaps combat.'
62
+ ITEM_ID_BED = 1
63
+ ITEM_NAME_BED = 'bed'
64
+ ITEM_DESC_BED = 'The place where you sleep when you\'re not adventuring.'
65
+ ITEM_ID_STALACTITE = 2
66
+ ITEM_NAME_STALACTITE = 'stalactite'
67
+ ITEM_DESC_STALACTITE = 'Long protrusion of cave adornment, broken off and fallen to the ground, where the stalagmites sneer at it from.'
68
+ ITEM_ID_FEATHER = 3
69
+ ITEM_NAME_FEATHER = 'feather'
70
+ ITEM_DESC_FEATHER = 'Soft and tender, unlike the craven bird that probably shed it.'
71
+ ITEM_ID_GUN = 4
72
+ ITEM_NAME_GUN = 'gun'
73
+ ITEM_DESC_GUN = 'Pew pew goes this firearm you wield, ifn\'t it weren\'t unloaded.'
74
+ end
75
+
76
+ module Locations
77
+ LOC_ID_HOME = 0
78
+ LOC_NAME_HOME = 'Home'
79
+ LOC_DESC_HOME = 'The little, unimportant, decrepit hut that you live in.'
80
+ LOC_CONNECTIONS_HOME = {:north => 4, :east => 1, :south => nil, :west => 3}
81
+
82
+ LOC_ID_CAVE_ENTRANCE = 1
83
+ LOC_NAME_CAVE_ENTRANCE = 'Cave (Entrance)'
84
+ LOC_DESC_CAVE_ENTRANCE = 'A nearby, dank cavern\'s entrance, surely filled with stacktites, stonemites, and rocksites.'
85
+ LOC_CONNECTIONS_CAVE_ENTRANCE = {:north => nil, :east => 2, :south => nil, :west => 0}
86
+
87
+ LOC_ID_CAVE_ROOM1 = 2
88
+ LOC_NAME_CAVE_ROOM1 = 'Cave (Room1)'
89
+ LOC_DESC_CAVE_ROOM1 = 'Now inside the first cavernous room, you confirm that there are stacktites, stonemites, rocksites, and even one or two pebblejites.'
90
+ LOC_CONNECTIONS_CAVE_ROOM1 = {:north => nil, :east => nil, :south => nil, :west => 1}
91
+
92
+ LOC_ID_FOREST = 3
93
+ LOC_NAME_FOREST = 'Forest'
94
+ LOC_DESC_FOREST = 'Trees exist here, in droves.'
95
+ LOC_CONNECTIONS_FOREST = {:north => nil, :east => 0, :south => nil, :west => nil}
96
+
97
+ LOC_ID_SKYTOWER = 4
98
+ LOC_NAME_SKYTOWER = 'Emerald\'s Sky Tower'
99
+ LOC_DESC_SKYTOWER = 'The craziest guy that ever existed is around here somewhere amongst the cloud floors, snow walls, and ethereal vibe.'
100
+ LOC_CONNECTIONS_SKYTOWER = {:north => nil, :east => nil, :south => 0, :west => nil}
101
+ end
102
+ end
103
+ end
@@ -1,151 +1,165 @@
1
- # lib/gemwarrior/evaluator.rb
2
- # Evaluates prompt input
3
-
4
- require 'pry'
5
-
6
- require_relative 'constants'
7
-
8
- module Gemwarrior
9
- class Evaluator
10
- private
11
-
12
- def print_separator
13
- puts SEPARATOR
14
- end
15
-
16
- def list_commands
17
- i = 0
18
- print_separator
19
- @commands.each do |cmd|
20
- puts " #{cmd}, #{@aliases[i]}\n -- #{@descriptions[i]}"
21
- i = i + 1
22
- end
23
- print_separator
24
- end
25
-
26
- public
27
-
28
- include Errors
29
-
30
- def initialize(world)
31
- @world = world
32
- @commands = %w(character inventory rest look take drop world monsters go change help quit exit quit! exit!)
33
- @aliases = %w(c i r l t d w m g ch h q x qq xx)
34
- @descriptions = [
35
- 'Display character information',
36
- 'Look in your inventory',
37
- 'Take a load off and regain stamina',
38
- 'Look around your current location',
39
- 'Take item',
40
- 'Drop item',
41
- 'List all locations in the world',
42
- 'List all the monsters in the world',
43
- 'Go in a direction',
44
- 'Change something',
45
- 'This help menu',
46
- 'Quit w/ confirmation',
47
- 'Exit w/ confirmation (very different, of course)',
48
- 'Quit w/o confirmation',
49
- 'Exit w/o confirmation (very, very different, of course)'
50
- ]
51
- end
52
-
53
- def evaluate(input)
54
- if input.nil?
55
- return
56
- end
57
-
58
- tokens = input.split
59
-
60
- unless valid?(input)
61
- return ERROR_COMMAND_INVALID
62
- end
63
-
64
- command = tokens.first
65
- param = tokens[1]
66
-
67
- case command
68
- when 'character', 'c'
69
- @world.player.check_self
70
- when 'inventory', 'i'
71
- if param
72
- @world.player.inventory.describe_item(param)
73
- else
74
- @world.player.list_inventory
75
- end
76
- when 'rest', 'r'
77
- @world.player.rest
78
- when 'look', 'l'
79
- if param
80
- @world.player.cur_loc.describe_item(param)
81
- else
82
- @world.player.cur_loc.describe
83
- end
84
- when 'take', 't'
85
- if param.nil?
86
- ERROR_TAKE_PARAM_MISSING
87
- else
88
- @world.player.inventory.add_item(@world.player.cur_loc, param)
89
- end
90
- when 'drop', 'd'
91
- if param.nil?
92
- ERROR_DROP_PARAM_MISSING
93
- else
94
- @world.player.inventory.remove_item(param)
95
- end
96
- when 'world', 'world'
97
- @world.list_locations
98
- when 'monsters', 'm'
99
- @world.list_monsters
100
- when 'go', 'g'
101
- if param.nil?
102
- ERROR_GO_DIR_MISSING
103
- else
104
- @world.player.go(@world.locations, param)
105
- end
106
- when 'change', 'ch'
107
- if param.nil?
108
- puts ERROR_CHANGE_PARAM_MISSING
109
- puts CHANGE_PARAMS
110
- else
111
- case param
112
- when 'name'
113
- @world.player.modify_name
114
- else
115
- ERROR_CHANGE_PARAM_INVALID
116
- end
117
- end
118
- when 'help', 'h'
119
- list_commands
120
- when 'quit', 'exit', 'q', 'x'
121
- puts "You sure you want to quit? (y/n): "
122
- response = gets.chomp
123
- if (response.downcase.eql?("y") || response.downcase.eql?("yes"))
124
- puts QUIT_MESSAGE
125
- exit(0)
126
- else
127
- puts RESUME_MESSAGE
128
- end
129
- when 'qq', 'xx'
130
- puts QUIT_MESSAGE
131
- exit(0)
132
- else
133
- return
134
- end
135
- end
136
-
137
- def valid?(input)
138
- tokens = input.split
139
- commands_and_aliases = @commands | @aliases
140
- if commands_and_aliases.include?(tokens.first)
141
- if tokens.size.between?(1,2)
142
- return true
143
- end
144
- elsif tokens.empty?
145
- return true
146
- end
147
- return false
148
- end
149
-
150
- end
151
- end
1
+ # lib/gemwarrior/evaluator.rb
2
+ # Evaluates prompt input
3
+
4
+ require 'pry'
5
+
6
+ module Gemwarrior
7
+ class Evaluator
8
+ # CONSTANTS
9
+ ## MESSAGES
10
+ PROGRAM_NAME = 'Gem Warrior'
11
+ QUIT_MESSAGE = 'Thanks for playing the game. Until next time...'
12
+ RESUME_MESSAGE = 'Back to adventuring!'
13
+ SEPARATOR = '================================================================'
14
+ CHANGE_PARAMS = 'Options: name'
15
+
16
+ ## ERRORS
17
+ ERROR_COMMAND_INVALID = 'That\'s not something the game yet understands.'
18
+ ERROR_LIST_PARAM_MISSING = 'You can\'t just "list". You gotta choose something to list.'
19
+ ERROR_CHANGE_PARAM_MISSING = 'Ch-ch-changes...aren\'t happening because you didn\'t specify what to change.'
20
+ ERROR_CHANGE_PARAM_INVALID = 'You can\'t change that...yet.'
21
+ ERROR_GO_PARAM_MISSING = 'Just wander aimlessly? A direction would be nice.'
22
+ ERROR_TAKE_PARAM_MISSING = 'You can\'t just "take". You gotta choose something to take.'
23
+ ERROR_DROP_PARAM_MISSING = 'You can\'t just "drop". You gotta choose something to drop.'
24
+
25
+ attr_accessor :world, :commands, :aliases, :descriptions
26
+
27
+ def initialize(world)
28
+ self.world = world
29
+ self.commands = %w(character inventory list rest look take drop go change help quit exit quit! exit!)
30
+ self.aliases = %w(c i ls r l t d g ch h q x qq xx)
31
+ self.descriptions = [
32
+ 'Display character information',
33
+ 'Look in your inventory',
34
+ 'List all the objects of a type that exist in the world',
35
+ 'Take a load off and regain stamina',
36
+ 'Look around your current location',
37
+ 'Take item',
38
+ 'Drop item',
39
+ 'Go in a direction',
40
+ 'Change something',
41
+ 'This help menu',
42
+ 'Quit w/ confirmation',
43
+ 'Exit w/ confirmation (very different, of course)',
44
+ 'Quit w/o confirmation',
45
+ 'Exit w/o confirmation (very, very different, of course)'
46
+ ]
47
+ end
48
+
49
+ def evaluate(input)
50
+ if input.nil?
51
+ return
52
+ end
53
+
54
+ tokens = input.split
55
+
56
+ unless input_valid?(input)
57
+ return ERROR_COMMAND_INVALID
58
+ end
59
+
60
+ command = tokens.first
61
+ param = tokens[1]
62
+
63
+ case command
64
+ when 'character', 'c'
65
+ world.player.check_self
66
+ when 'inventory', 'i'
67
+ if param
68
+ world.player.inventory.describe_item(param)
69
+ else
70
+ world.player.list_inventory
71
+ end
72
+ when 'list', 'ls'
73
+ if param.nil?
74
+ ERROR_LIST_PARAM_MISSING
75
+ else
76
+ world.list(param)
77
+ end
78
+ when 'rest', 'r'
79
+ world.player.rest
80
+ when 'look', 'l'
81
+ if param
82
+ world.player.cur_loc.describe_item(param)
83
+ else
84
+ world.player.cur_loc.describe
85
+ end
86
+ when 'take', 't'
87
+ if param.nil?
88
+ ERROR_TAKE_PARAM_MISSING
89
+ else
90
+ world.player.inventory.add_item(world.player.cur_loc, param)
91
+ end
92
+ when 'drop', 'd'
93
+ if param.nil?
94
+ ERROR_DROP_PARAM_MISSING
95
+ else
96
+ world.player.inventory.remove_item(param)
97
+ end
98
+ when 'go', 'g'
99
+ if param.nil?
100
+ ERROR_GO_PARAM_MISSING
101
+ else
102
+ world.player.go(world.locations, param)
103
+ end
104
+ when 'change', 'ch'
105
+ if param.nil?
106
+ puts ERROR_CHANGE_PARAM_MISSING
107
+ puts CHANGE_PARAMS
108
+ else
109
+ case param
110
+ when 'name'
111
+ world.player.modify_name
112
+ else
113
+ ERROR_CHANGE_PARAM_INVALID
114
+ end
115
+ end
116
+ when 'help', 'h'
117
+ list_commands
118
+ when 'quit', 'exit', 'q', 'x'
119
+ puts "You sure you want to quit? (y/n): "
120
+ response = gets.chomp
121
+ if (response.downcase.eql?("y") || response.downcase.eql?("yes"))
122
+ puts QUIT_MESSAGE
123
+ exit(0)
124
+ else
125
+ puts RESUME_MESSAGE
126
+ end
127
+ when 'quit!', 'exit!', 'qq', 'xx'
128
+ puts QUIT_MESSAGE
129
+ exit(0)
130
+ else
131
+ return
132
+ end
133
+ end
134
+
135
+ private
136
+
137
+ def print_separator
138
+ puts SEPARATOR
139
+ end
140
+
141
+ def list_commands
142
+ i = 0
143
+ print_separator
144
+ commands.each do |cmd|
145
+ puts " #{cmd}, #{aliases[i]}\n -- #{descriptions[i]}"
146
+ i = i + 1
147
+ end
148
+ print_separator
149
+ end
150
+
151
+ def input_valid?(input)
152
+ tokens = input.split
153
+ commands_and_aliases = commands | aliases
154
+ if commands_and_aliases.include?(tokens.first)
155
+ if tokens.size.between?(1,2)
156
+ return true
157
+ end
158
+ elsif tokens.empty?
159
+ return true
160
+ end
161
+ return false
162
+ end
163
+
164
+ end
165
+ end