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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d9fbe46192891851f0b80f4be5c0488423ac649
|
4
|
+
data.tar.gz: 0ed5b2c8a5056a4e7ad7e384da03128f5584d5c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b881e6754a51e72f2f76ceb7504841fb3284cb4fc7699292b830d3309e45978c6391a1b8ac46181306b618b441e97fffaaffae9d8fd6b511c863b95485d04ecf
|
7
|
+
data.tar.gz: f413966728db827f7afda8102a065e1d05726830902a0876e32f0384ab68a358c0be25b9eff172aa187d17e8e8f74d36a73879c0c6c9d950c601b8e742770d6a
|
data/bin/gemwarrior
CHANGED
File without changes
|
data/lib/gemwarrior/creature.rb
CHANGED
@@ -1,47 +1,53 @@
|
|
1
|
-
# lib/gemwarrior/creature.rb
|
2
|
-
# Creature base class
|
3
|
-
|
4
|
-
require_relative '
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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/
|
2
|
-
# List of
|
3
|
-
|
4
|
-
module Gemwarrior
|
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
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
data/lib/gemwarrior/evaluator.rb
CHANGED
@@ -1,151 +1,165 @@
|
|
1
|
-
# lib/gemwarrior/evaluator.rb
|
2
|
-
# Evaluates prompt input
|
3
|
-
|
4
|
-
require 'pry'
|
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
|
-
'Look
|
37
|
-
'Take
|
38
|
-
'
|
39
|
-
'
|
40
|
-
'
|
41
|
-
'
|
42
|
-
'
|
43
|
-
'
|
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
|
-
when '
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
when '
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
when '
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
def
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
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
|