gemwarrior 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,48 +1,44 @@
1
- # lib/gemwarrior/monster.rb
2
- # Monster creature
3
-
4
- require_relative 'constants'
5
- require_relative 'inventory'
6
- require_relative 'creature'
7
-
8
- module Gemwarrior
9
- class Monster < Creature
10
- include Entities::Monsters
11
-
12
- attr_reader :name
13
-
14
- def initialize(
15
- id,
16
- name = MOB_NAME_DEFAULT,
17
- description = MOB_DESC_FAULT,
18
- face = '',
19
- hands ='',
20
- mood = '',
21
- level = '',
22
- hp_cur = 5,
23
- hp_max = 5,
24
- atk_lo = 1,
25
- atk_hi = 2,
26
- inventory = Inventory.new,
27
- rox = 1
28
- )
29
- @id = id
30
- @name = name
31
- @description = description
32
- @face = face
33
- @hands = hands
34
- @mood = mood
35
-
36
- @level = rand(level)
37
- @hp_cur = hp_cur
38
- @hp_max = hp_max
39
-
40
- @atk_lo = atk_lo
41
- @atk_hi = atk_hi
42
-
43
- @inventory = inventory
44
- @rox = rox
45
- end
46
-
47
- end
48
- end
1
+ # lib/gemwarrior/monster.rb
2
+ # Monster creature
3
+
4
+ require_relative 'creature'
5
+
6
+ module Gemwarrior
7
+ class Monster < Creature
8
+ attr_accessor :xp, :atk_hi, :atk_lo, :rox
9
+
10
+ def initialize(
11
+ id,
12
+ name,
13
+ description,
14
+ face,
15
+ hands,
16
+ mood,
17
+ level,
18
+ hp_cur,
19
+ hp_max,
20
+ atk_lo,
21
+ atk_hi,
22
+ inventory,
23
+ rox
24
+ )
25
+ self.id = id
26
+ self.name = name
27
+ self.description = description
28
+ self.face = face
29
+ self.hands = hands
30
+ self.mood = mood
31
+
32
+ self.level = level
33
+ self.hp_cur = hp_cur
34
+ self.hp_max = hp_max
35
+
36
+ self.atk_lo = atk_lo
37
+ self.atk_hi = atk_hi
38
+
39
+ self.inventory = inventory
40
+ self.rox = rox
41
+ end
42
+
43
+ end
44
+ end
@@ -1,185 +1,193 @@
1
- # lib/gemwarrior/player.rb
2
- # Player creature
3
-
4
- require_relative 'constants'
5
- require_relative 'inventory'
6
- require_relative 'creature'
7
-
8
- module Gemwarrior
9
- class Player < Creature
10
- private
11
-
12
- def print_traveling_text
13
- loc = Thread.new do
14
- print "*** "
15
- print "#{Matrext::process({ :phrase => "traveling...", :sl => true, :speed => :fast })}"
16
- print " ***\n"
17
- end
18
- loc.join
19
- end
20
-
21
- def print_char_pic
22
- char_pic = ""
23
- char_pic << "**********\n"
24
- char_pic << "* () *\n"
25
- char_pic << "* \\-||-/ *\n"
26
- char_pic << "* -- *\n"
27
- char_pic << "* || *\n"
28
- char_pic << "* _||_ *\n"
29
- char_pic << "**********\n"
30
- puts char_pic
31
- end
32
-
33
- include AttributePools
34
- include Errors
35
-
36
- def generate_name
37
- name = []
38
- letter_max = rand(5..10)
39
- name[0] = CHAR_UPPER_POOL[rand(0..25)]
40
- name[1] = CHAR_LOWER_VOWEL_POOL[rand(0..5)]
41
- 2.upto(letter_max) do |i|
42
- name[i] = CHAR_LOWER_POOL[rand(0..25)]
43
- end
44
- return name.join
45
- end
46
-
47
- def generate_desc
48
- PLYR_DESC_DEFAULT
49
- end
50
-
51
- def generate_face
52
- FACE_DESC[rand(0..FACE_DESC.length-1)]
53
- end
54
-
55
- def generate_hands
56
- HANDS_DESC[rand(0..HANDS_DESC.length-1)]
57
- end
58
-
59
- def generate_mood
60
- MOOD_DESC[rand(0..MOOD_DESC.length-1)]
61
- end
62
-
63
- def generate_player_identity
64
- @name = generate_name
65
- @description = generate_desc
66
- @face = generate_face
67
- @hands = generate_hands
68
- @mood = generate_mood
69
- end
70
-
71
- public
72
-
73
- attr_reader :level, :xp, :cur_loc, :hp_cur, :hp_max, :stam_cur, :stam_max, :inventory
74
- attr_accessor :name
75
-
76
- def initialize(
77
- level = PLYR_LEVEL_DEFAULT,
78
- xp = PLYR_XP_DEFAULT,
79
- hp_cur = PLYR_HP_CUR_DEFAULT,
80
- hp_max = PLYR_HP_MAX_DEFAULT,
81
- stam_cur = PLYR_STAM_CUR_DEFAULT,
82
- stam_max = PLYR_STAM_MAX_DEFAULT,
83
- atk_lo = PLYR_ATK_LO_DEFAULT,
84
- atk_hi = PLYR_ATK_HI_DEFAULT,
85
- inventory = Inventory.new,
86
- rox = PLYR_ROX_DEFAULT,
87
- cur_loc
88
- )
89
- # generates name, desc, face, hands, mood text
90
- generate_player_identity
91
-
92
- @level = level
93
- @xp = xp
94
-
95
- @hp_cur = hp_cur
96
- @hp_max = hp_max
97
- @stam_cur = stam_cur
98
- @stam_max = stam_max
99
-
100
- @atk_lo = atk_lo
101
- @atk_hi = atk_hi
102
-
103
- @inventory = inventory
104
- @rox = rox
105
-
106
- @cur_loc = cur_loc
107
- end
108
-
109
- def check_self
110
- print_char_pic
111
- return "You check yourself. Currently breathing, wearing clothing, and with a few specific characteristics: face is #{@face}, hands are #{@hands}, and general mood is #{@mood}.\n"
112
- end
113
-
114
- def rest
115
- hours = rand(1..23)
116
- minutes = rand(1..59)
117
- seconds = rand(1..59)
118
-
119
- hours_text = hours == 1 ? "hour" : "hours"
120
- mins_text = minutes == 1 ? "minute" : "minutes"
121
- secs_text = seconds == 1 ? "second" : "seconds"
122
-
123
- return "You lie down somewhere quasi-flat and after a few moments, due to extreme exhaustion, you fall into a deep slumber. Approximately #{hours} #{hours_text}, #{minutes} #{mins_text}, and #{seconds} #{secs_text} later, you wake up with a start, look around you, notice nothing in particular, and get back up, ready to go again."
124
- end
125
-
126
- def stamina_dec
127
- @stam_cur = @stam_cur - 1
128
- end
129
-
130
- def modify_name
131
- print "Enter new name: "
132
- name = gets.chomp!
133
- if name.length < 3 || name.length > 10
134
- return "'#{name}' is an invalid length. Make it between 3 and 10 characters, please."
135
- else
136
- new_name = ""
137
- new_name << name[0].upcase
138
- new_name << name[1..name.length-1].downcase
139
- @name = new_name
140
- return "New name, '#{new_name}', accepted."
141
- end
142
- return nil
143
- end
144
-
145
- def list_inventory
146
- @inventory.list_contents
147
- end
148
-
149
- def loc_by_id(locations, id)
150
- locations.each do |loc|
151
- if loc.id.to_i.equal? id
152
- return loc
153
- end
154
- end
155
- return nil
156
- end
157
-
158
- def can_move?(direction)
159
- @cur_loc.has_loc_to_the?(direction)
160
- end
161
-
162
- def go(locations, direction)
163
- case direction
164
- when "n"
165
- direction = "north"
166
- when "e"
167
- direction = "east"
168
- when "s"
169
- direction = "south"
170
- when "w"
171
- direction = "west"
172
- end
173
- unless direction.nil?
174
- if can_move?(direction)
175
- new_loc_id = @cur_loc.locs_connected[direction.to_sym]
176
- @cur_loc = loc_by_id(locations, new_loc_id)
177
- print_traveling_text
178
- @cur_loc.describe
179
- else
180
- ERROR_GO_DIR_INVALID
181
- end
182
- end
183
- end
184
- end
185
- end
1
+ # lib/gemwarrior/player.rb
2
+ # Player creature
3
+
4
+ require_relative 'creature'
5
+
6
+ module Gemwarrior
7
+ class Player < Creature
8
+ # CONSTANTS
9
+ ## ATTRIBUTE POOLS
10
+ CHAR_UPPER_POOL = (65..90).map{ |i| i.chr }
11
+ CHAR_LOWER_POOL = (97..122).map{ |i| i.chr }
12
+ CHAR_LOWER_VOWEL_POOL = ['a','e','i','o','u','y']
13
+
14
+ FACE_DESC = ['smooth', 'tired', 'ruddy', 'moist', 'shocked', 'handsome', '5 o\'clock-shadowed']
15
+ HANDS_DESC = ['worn', 'balled into fists', 'relaxed', 'cracked', 'tingly', 'mom\'s spaghetti']
16
+ MOOD_DESC = ['calm', 'excited', 'depressed', 'tense', 'lackadaisical', 'angry', 'positive']
17
+
18
+ ## PLAYER DEFAULTS
19
+ 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.'
20
+
21
+ ## ERRORS
22
+ ERROR_GO_PARAM_INVALID = 'The place in that direction is far, far, FAR too dangerous. You should try a different way.'
23
+
24
+ attr_accessor :xp, :stam_cur, :stam_max, :atk_hi, :atk_lo, :rox, :cur_loc
25
+
26
+ def initialize(
27
+ level,
28
+ xp,
29
+ hp_cur,
30
+ hp_max,
31
+ stam_cur,
32
+ stam_max,
33
+ atk_lo,
34
+ atk_hi,
35
+ inventory,
36
+ rox,
37
+ cur_loc
38
+ )
39
+ generate_player_identity
40
+
41
+ self.level = level
42
+ self.xp = xp
43
+
44
+ self.hp_cur = hp_cur
45
+ self.hp_max = hp_max
46
+ self.stam_cur = stam_cur
47
+ self.stam_max = stam_max
48
+
49
+ self.atk_lo = atk_lo
50
+ self.atk_hi = atk_hi
51
+
52
+ self.inventory = inventory
53
+ self.rox = rox
54
+
55
+ self.cur_loc = cur_loc
56
+ end
57
+
58
+ def check_self
59
+ print_char_pic
60
+ return "You check yourself. Currently breathing, wearing clothing, and with a few specific characteristics: face is #{@face}, hands are #{@hands}, and general mood is #{@mood}.\n"
61
+ end
62
+
63
+ def rest
64
+ hours = rand(1..23)
65
+ minutes = rand(1..59)
66
+ seconds = rand(1..59)
67
+
68
+ hours_text = hours == 1 ? "hour" : "hours"
69
+ mins_text = minutes == 1 ? "minute" : "minutes"
70
+ secs_text = seconds == 1 ? "second" : "seconds"
71
+
72
+ return "You lie down somewhere quasi-flat and after a few moments, due to extreme exhaustion, you fall into a deep slumber. Approximately #{hours} #{hours_text}, #{minutes} #{mins_text}, and #{seconds} #{secs_text} later, you wake up with a start, look around you, notice nothing in particular, and get back up, ready to go again."
73
+ end
74
+
75
+ def stamina_dec
76
+ stam_cur = stam_cur - 1
77
+ end
78
+
79
+ def modify_name
80
+ print "Enter new name: "
81
+ new_name = gets.chomp!
82
+ if new_name.length < 3 || new_name.length > 10
83
+ return "'#{new_name}' is an invalid length. Make it between 3 and 10 characters, please."
84
+ else
85
+ name_to_add = ""
86
+ name_to_add << new_name[0].upcase
87
+ name_to_add << new_name[1..new_name.length-1].downcase
88
+ self.name = name_to_add
89
+ return "New name, '#{name}', accepted."
90
+ end
91
+ return nil
92
+ end
93
+
94
+ def list_inventory
95
+ inventory.list_contents
96
+ end
97
+
98
+ def loc_by_id(locations, id)
99
+ locations.each do |loc|
100
+ if loc.id.to_i.equal? id
101
+ return loc
102
+ end
103
+ end
104
+ return nil
105
+ end
106
+
107
+ def can_move?(direction)
108
+ cur_loc.has_loc_to_the?(direction)
109
+ end
110
+
111
+ def go(locations, direction)
112
+ case direction
113
+ when "n"
114
+ direction = "north"
115
+ when "e"
116
+ direction = "east"
117
+ when "s"
118
+ direction = "south"
119
+ when "w"
120
+ direction = "west"
121
+ end
122
+ unless direction.nil?
123
+ if can_move?(direction)
124
+ new_loc_id = cur_loc.locs_connected[direction.to_sym]
125
+ cur_loc = loc_by_id(locations, new_loc_id)
126
+ print_traveling_text
127
+ cur_loc.checked_for_monsters = false
128
+ cur_loc.describe
129
+ else
130
+ ERROR_GO_PARAM_INVALID
131
+ end
132
+ end
133
+ end
134
+
135
+ private
136
+
137
+ def print_traveling_text
138
+ loc = Thread.new do
139
+ print "* "
140
+ print "#{Matrext::process({ :phrase => ">>>", :sl => true })}"
141
+ print " *\n"
142
+ end
143
+ loc.join
144
+ end
145
+
146
+ def print_char_pic
147
+ char_pic = ""
148
+ char_pic << "**********\n"
149
+ char_pic << "* () *\n"
150
+ char_pic << "* \\-||-/ *\n"
151
+ char_pic << "* -- *\n"
152
+ char_pic << "* || *\n"
153
+ char_pic << "* _||_ *\n"
154
+ char_pic << "**********\n"
155
+ puts char_pic
156
+ end
157
+
158
+ def generate_name
159
+ name = []
160
+ letter_max = rand(5..10)
161
+ name[0] = CHAR_UPPER_POOL[rand(0..25)]
162
+ name[1] = CHAR_LOWER_VOWEL_POOL[rand(0..5)]
163
+ 2.upto(letter_max) do |i|
164
+ name[i] = CHAR_LOWER_POOL[rand(0..25)]
165
+ end
166
+ return name.join
167
+ end
168
+
169
+ def generate_desc
170
+ PLYR_DESC_DEFAULT
171
+ end
172
+
173
+ def generate_face
174
+ FACE_DESC[rand(0..FACE_DESC.length-1)]
175
+ end
176
+
177
+ def generate_hands
178
+ HANDS_DESC[rand(0..HANDS_DESC.length-1)]
179
+ end
180
+
181
+ def generate_mood
182
+ MOOD_DESC[rand(0..MOOD_DESC.length-1)]
183
+ end
184
+
185
+ def generate_player_identity
186
+ self.name = generate_name
187
+ self.description = generate_desc
188
+ self.face = generate_face
189
+ self.hands = generate_hands
190
+ self.mood = generate_mood
191
+ end
192
+ end
193
+ end