gemwarrior 0.2.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +1 -0
- data/bin/gemwarrior +29 -0
- data/gemwarrior.gemspec +33 -0
- data/lib/gemwarrior.rb +9 -0
- data/lib/gemwarrior/constants.rb +155 -0
- data/lib/gemwarrior/creature.rb +47 -0
- data/lib/gemwarrior/evaluator.rb +128 -0
- data/lib/gemwarrior/game.rb +42 -0
- data/lib/gemwarrior/inventory.rb +61 -0
- data/lib/gemwarrior/item.rb +28 -0
- data/lib/gemwarrior/location.rb +101 -0
- data/lib/gemwarrior/monster.rb +48 -0
- data/lib/gemwarrior/player.rb +185 -0
- data/lib/gemwarrior/repl.rb +92 -0
- data/lib/gemwarrior/version.rb +6 -0
- data/lib/gemwarrior/world.rb +269 -0
- data/spec/rubywarrior_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a7e88f25ec32e8547f6300380c1b28db29d70ddd
|
4
|
+
data.tar.gz: e52a393b60fdac5aae3d74e5e79d66a8d627ebe1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a655cc40acff93a91e3b17d41f53a35ec9bb46efad7316f9cce1d255150a63233489ceebfb313629cf559745d521e0f7c6ae27ca6e2502d1074d260618ca19a7
|
7
|
+
data.tar.gz: 59c4e5452954b732e45ab09e69a04267f68ffa187ca514d2e38e5aa56e7d793ff6627cd9cc388296ac719480c03a89315122a5f29dcdbf543ed290adbedda645
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Michael Chadwick
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
```
|
2
|
+
/-+-+-+ +-+-+-+-+-+-+-\
|
3
|
+
|G|E|M| |W|A|R|R|I|O|R|
|
4
|
+
\-+-+-+ +-+-+-+-+-+-+-/
|
5
|
+
```
|
6
|
+
<small>logo courtesy of [ascii generator](http://www.network-science.de/ascii/)</small>
|
7
|
+
|
8
|
+
**Gem Warrior** is a text adventure that takes place in the land of **Jool**, where randomized fortune is just as likely as *mayhem*.
|
9
|
+
|
10
|
+
You take up the mantle of **1.upto(rand(5..10)) {print rand(65..90).chr}**, a gifted young acolyte who has been tasked by the queen herself, **Ruby**, to venture off into the unknown to recapture a **Shiny Thing<sup>tm</sup>** that holds great power within its crystallized boundaries. Unfortunately, it was stolen recently by a crazed madperson named **Emerald**, bent on using its frightening power for **Evil**. You are **Good**, obviously, and the rightful caretaker of such power, but he will not give it up willingly, and has cursed all the creatures of the land into doing his bidding, which is largely tearing you limb from limb.
|
11
|
+
|
12
|
+
Start in your poor, super lame cottage, where you live alone, subsisting off the sale of polished rocks you scavenge all day for in the neighboring caves. Once tasked with your quest, travel throughout the land of Jool, eventually reaching the sky tower that Emerald resides in with his stolen goods, laughing to himself, occasionally.
|
13
|
+
|
14
|
+
As you travel you will discover sights and sounds of the land, all of which are new to you because you don't really get out much. Visit towns with merchants willing to trade coin for wares they bought off of other adventurers who didn't last the previous attempts at thwartion. Sleep in makeshift huts to regain your health and magic points (or the ground, if that's all that's available), which are conveniently located in your peripheral vision (i.e. the console window). Eventually, if you're skilled (and I actually code it in), you'll reach **Emerald's Sky Tower**, part him from his **ShinyThing<sup>tm</sup>**, and then do what is "right".
|
15
|
+
|
16
|
+
## How to Get to Jool
|
17
|
+
|
18
|
+
1. `gem install gemwarrior`
|
19
|
+
2. `gemwarrior`
|
20
|
+
|
21
|
+
Run the two commands above and you'll be whisked away to Jool, ready to start or continue your quest to defeat Emerald and take back the coveted Shiny Thing(tm) that you will bring back to Queen Ruby (or will you...?).
|
22
|
+
|
23
|
+
## In Progress, Yanno
|
24
|
+
|
25
|
+
This is in super-hyper-turbo-edition pre-pre-pre-alpha right now, but a working console prompt, some commands (type `h` for a list), and a few locations exist already. Each time you start the game a new hero will be created with a randomized name, but you can change that with `> change name`.
|
26
|
+
|
27
|
+
`> c` - character check for visual identity
|
28
|
+
`> i [object]` - check your inventory (or an individual item within)
|
29
|
+
`> r` - take a load off
|
30
|
+
`> l [object]` - look at current location and items
|
31
|
+
`> t [object]` - take an item from a location
|
32
|
+
`> g [direction]` - go in a direction, if possible
|
33
|
+
`> w` - list all the locations available in the world
|
34
|
+
`> m` - list all the monsters available in the world
|
35
|
+
`> ch [attribute]` - change some things about yourself
|
36
|
+
`> q` - quit this nonsense
|
37
|
+
|
38
|
+
To come:
|
39
|
+
|
40
|
+
* ~~Ability to move between locations!~~
|
41
|
+
* More locations to move between!
|
42
|
+
* Monsters!
|
43
|
+
* Ability to fight those monsters!
|
44
|
+
* ~~Items you can pick up!~~
|
45
|
+
* Quests!
|
46
|
+
* Towns!
|
47
|
+
* Merchants!
|
48
|
+
* Sound FX!
|
49
|
+
* Music!
|
50
|
+
* Epic Length (whereby "Epic" I mean "maybe 30 minutes"?)!
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/gemwarrior
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require_relative '../lib/gemwarrior'
|
5
|
+
require_relative '../lib/gemwarrior/version'
|
6
|
+
|
7
|
+
def parse_options
|
8
|
+
opts.on('-v', '--version', 'Display version number and exit') do
|
9
|
+
puts "#{$PROGRAM_NAME} #{Gemwarrior::VERSION}"
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def print_error(error)
|
15
|
+
case error
|
16
|
+
when OptionParser::InvalidOption
|
17
|
+
puts "#{$PROGRAM_NAME}: illegal option #{error.args.join(' ')}"
|
18
|
+
else
|
19
|
+
puts "An unexpected error occurred while running #{$PROGRAM_NAME}:"
|
20
|
+
puts " #{error}\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
Gemwarrior::Base.new
|
26
|
+
rescue => error
|
27
|
+
print_error(error)
|
28
|
+
exit(false)
|
29
|
+
end
|
data/gemwarrior.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gemwarrior/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'gemwarrior'
|
8
|
+
spec.version = Gemwarrior::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.authors = ['Michael Chadwick']
|
11
|
+
spec.email = 'mike@codana.me'
|
12
|
+
spec.homepage = 'http://rubygems.org/gems/gemwarrior'
|
13
|
+
spec.summary = 'RPG as RubyGem'
|
14
|
+
spec.description = 'A fun role-playing game in the form of a RubyGem!'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split("\n")
|
17
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
spec.license = 'MIT'
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'os', '~> 0.9', '>= 0.9.6'
|
23
|
+
|
24
|
+
#spec.add_runtime_dependency 'feep', '~> 0.0.9'
|
25
|
+
#spec.add_runtime_dependency 'matrext', '~> 0.2'
|
26
|
+
#spec.add_runtime_dependency 'wordnik', '~> 4.12'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 0.29'
|
33
|
+
end
|
data/lib/gemwarrior.rb
ADDED
@@ -0,0 +1,155 @@
|
|
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
|
+
SEPARATOR = '====================================================='
|
9
|
+
CHANGE_PARAMS = 'Options: name'
|
10
|
+
|
11
|
+
DANGER_LEVEL = {:none => 0, :low => 15, :moderate => 30, :high => 55, :assured => 100}
|
12
|
+
|
13
|
+
module Errors
|
14
|
+
ERROR_COMMAND_INVALID = 'That\'s not something the game yet understands.'
|
15
|
+
ERROR_INVENTORY_EMPTY = '...and find you currently have diddly-squat, which is nothing.'
|
16
|
+
ERROR_ITEM_LOC_INVALID = 'You don\'t see that there.'
|
17
|
+
ERROR_ITEM_INVENTORY_INVALID = 'You don\'t possess that.'
|
18
|
+
ERROR_TAKE_PARAM_MISSING = 'You can\'t just take. You gotta choose something.'
|
19
|
+
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.'
|
20
|
+
ERROR_TAKE_ITEM_INVALID = 'That item doesn\'t exist here.'
|
21
|
+
ERROR_GO_DIR_MISSING = 'Just wander aimlessly? A direction would be nice.'
|
22
|
+
ERROR_GO_DIR_INVALID = 'The place in that direction is far, far, FAR too dangerous. You should try a different way.'
|
23
|
+
ERROR_CHANGE_PARAM_MISSING = 'Ch-ch-changes...aren\'t happening because you didn\'t specify what to change.'
|
24
|
+
ERROR_CHANGE_PARAM_INVALID = 'You can\'t change that...yet.'
|
25
|
+
end
|
26
|
+
|
27
|
+
module AttributePools
|
28
|
+
# character pools
|
29
|
+
CHAR_UPPER_POOL = (65..90).map{ |i| i.chr }
|
30
|
+
CHAR_LOWER_POOL = (97..122).map{ |i| i.chr }
|
31
|
+
CHAR_LOWER_VOWEL_POOL = ['a','e','i','o','u','y']
|
32
|
+
|
33
|
+
# attribute pools
|
34
|
+
FACE_DESC = ['smooth', 'tired', 'ruddy', 'moist', 'shocked']
|
35
|
+
HANDS_DESC = ['worn', 'balled into fists', 'relaxed', 'cracked', 'tingly', 'mom\'s spaghetti']
|
36
|
+
MOOD_DESC = ['calm', 'excited', 'depressed', 'tense', 'lackadaisical', 'angry', 'positive']
|
37
|
+
|
38
|
+
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.'
|
39
|
+
|
40
|
+
PLYR_LEVEL_DEFAULT = 1
|
41
|
+
PLYR_XP_DEFAULT = 0
|
42
|
+
PLYR_HP_CUR_DEFAULT = 10
|
43
|
+
PLYR_HP_MAX_DEFAULT = 10
|
44
|
+
PLYR_STAM_CUR_DEFAULT = 20
|
45
|
+
PLYR_STAM_MAX_DEFAULT = 20
|
46
|
+
PLYR_ATK_LO_DEFAULT = 1
|
47
|
+
PLYR_ATK_HI_DEFAULT = 2
|
48
|
+
PLYR_ROX_DEFAULT = 0
|
49
|
+
end
|
50
|
+
|
51
|
+
module Entities
|
52
|
+
module Locations
|
53
|
+
LOC_ID_HOME = 0
|
54
|
+
LOC_NAME_HOME = 'Home'
|
55
|
+
LOC_DESC_HOME = 'The little, unimportant, decrepit hut that you live in.'
|
56
|
+
LOC_CONNECTIONS_HOME = {:north => 4, :east => 1, :south => nil, :west => 3}
|
57
|
+
|
58
|
+
LOC_ID_CAVE_ENTRANCE = 1
|
59
|
+
LOC_NAME_CAVE_ENTRANCE = 'Cave (Entrance)'
|
60
|
+
LOC_DESC_CAVE_ENTRANCE = 'A nearby, dank cavern\'s entrance, surely filled with stacktites, stonemites, and rocksites.'
|
61
|
+
LOC_CONNECTIONS_CAVE_ENTRANCE = {:north => nil, :east => 2, :south => nil, :west => 0}
|
62
|
+
|
63
|
+
LOC_ID_CAVE_ROOM1 = 2
|
64
|
+
LOC_NAME_CAVE_ROOM1 = 'Cave (Room1)'
|
65
|
+
LOC_DESC_CAVE_ROOM1 = 'Now inside the first cavernous room, you confirm that there are stacktites, stonemites, rocksites, and even one or two pebblejites.'
|
66
|
+
LOC_CONNECTIONS_CAVE_ROOM1 = {:north => nil, :east => nil, :south => nil, :west => 1}
|
67
|
+
|
68
|
+
LOC_ID_FOREST = 3
|
69
|
+
LOC_NAME_FOREST = 'Forest'
|
70
|
+
LOC_DESC_FOREST = 'Trees exist here, in droves.'
|
71
|
+
LOC_CONNECTIONS_FOREST = {:north => nil, :east => 0, :south => nil, :west => nil}
|
72
|
+
|
73
|
+
LOC_ID_SKYTOWER = 4
|
74
|
+
LOC_NAME_SKYTOWER = 'Emerald\'s Sky Tower'
|
75
|
+
LOC_DESC_SKYTOWER = 'The craziest guy that ever existed is around here somewhere amongst the cloud floors, snow walls, and ethereal vibe.'
|
76
|
+
LOC_CONNECTIONS_SKYTOWER = {:north => nil, :east => nil, :south => 0, :west => nil}
|
77
|
+
end
|
78
|
+
|
79
|
+
module Monsters
|
80
|
+
MOB_ID_ALEXANDRAT = 0
|
81
|
+
MOB_NAME_ALEXANDRAT = 'Alexandrat'
|
82
|
+
MOB_DESC_ALEXANDRAT = 'Tiny, but fierce, color-changing rodent.'
|
83
|
+
MOB_LEVEL_ALEXANDRAT = 1..2
|
84
|
+
|
85
|
+
MOB_ID_AMBEROO = 1
|
86
|
+
MOB_NAME_AMBEROO = 'Amberoo'
|
87
|
+
MOB_DESC_AMBEROO = 'Fossilized and jumping around like an adorably dangerous threat from the past.'
|
88
|
+
MOB_LEVEL_AMBEROO = 1..2
|
89
|
+
|
90
|
+
MOB_ID_AMETHYSTLE = 2
|
91
|
+
MOB_NAME_AMETHYSTLE = 'Amethystle'
|
92
|
+
MOB_DESC_AMETHYSTLE = 'Sober and contemplative, it moves with purplish tentacles swaying in the breeze.'
|
93
|
+
MOB_LEVEL_AMETHYSTLE = 1..3
|
94
|
+
|
95
|
+
MOB_ID_AQUAMARINE = 3
|
96
|
+
MOB_NAME_AQUAMARINE = 'Aquamarine'
|
97
|
+
MOB_DESC_AQUAMARINE = 'It is but one of the few, the proud, the underwater.'
|
98
|
+
MOB_LEVEL_AQUAMARINE = 2..4
|
99
|
+
|
100
|
+
MOB_ID_APATIGER = 4
|
101
|
+
MOB_NAME_APATIGER = 'Apatiger'
|
102
|
+
MOB_DESC_APATIGER = 'Apathetic about most everything as it lazes around, save for eating you.'
|
103
|
+
MOB_LEVEL_APATIGER = 3..5
|
104
|
+
|
105
|
+
MOB_ID_BLOODSTORM = 5
|
106
|
+
MOB_NAME_BLOODSTORM = 'Bloodstorm'
|
107
|
+
MOB_DESC_BLOODSTORM = 'A literal swirling, maniacal vortex of human hemoglobin.'
|
108
|
+
MOB_LEVEL_BLOODSTORM = 5..6
|
109
|
+
|
110
|
+
MOB_ID_CITRINAGA = 6
|
111
|
+
MOB_NAME_CITRINAGA = 'Citrinaga'
|
112
|
+
MOB_DESC_CITRINAGA = 'Refreshing in its shiny, gleaming effectiveness at ending your life.'
|
113
|
+
MOB_LEVEL_CITRINAGA = 3..4
|
114
|
+
|
115
|
+
MOB_ID_CORALIZ = 7
|
116
|
+
MOB_NAME_CORALIZ = 'Coraliz'
|
117
|
+
MOB_DESC_CORALIZ = 'Small blue lizard that slithers around, nipping at your ankles.'
|
118
|
+
MOB_LEVEL_CORALIZ = 2..3
|
119
|
+
|
120
|
+
MOB_ID_CUBICAT = 8
|
121
|
+
MOB_NAME_CUBICAT = 'Cubicat'
|
122
|
+
MOB_DESC_CUBICAT = 'Perfectly geometrically cubed feline, fresh from its woven enclosure, claws at the ready.'
|
123
|
+
MOB_LEVEL_CUBICAT = 4..5
|
124
|
+
|
125
|
+
MOB_ID_DIAMAN = 9
|
126
|
+
MOB_NAME_DIAMAN = 'Diaman'
|
127
|
+
MOB_DESC_DIAMAN = 'Crystalline structure in the form of a man, lumbering toward you, with outstretched, edged pincers.'
|
128
|
+
MOB_LEVEL_DIAMAN = 6..7
|
129
|
+
|
130
|
+
MOB_NAME_DEFAULT = 'Rocky'
|
131
|
+
MOB_DESC_DEFAULT = 'It\'s a monster, and it\'s not happy.'
|
132
|
+
end
|
133
|
+
|
134
|
+
module Items
|
135
|
+
ITEM_ID_STONE = 0
|
136
|
+
ITEM_NAME_STONE = 'stone'
|
137
|
+
ITEM_DESC_STONE = 'A small, sharp mega pebble, suitable for tossing in amusement, and perhaps combat.'
|
138
|
+
ITEM_ID_BED = 1
|
139
|
+
ITEM_NAME_BED = 'bed'
|
140
|
+
ITEM_DESC_BED = 'The place where you sleep when you\'re not adventuring.'
|
141
|
+
ITEM_ID_STALACTITE = 2
|
142
|
+
ITEM_NAME_STALACTITE = 'stalactite'
|
143
|
+
ITEM_DESC_STALACTITE = 'Long protrusion of cave adornment, broken off and fallen to the ground, where the stalagmites sneer at it from.'
|
144
|
+
ITEM_ID_FEATHER = 3
|
145
|
+
ITEM_NAME_FEATHER = 'feather'
|
146
|
+
ITEM_DESC_FEATHER = 'Soft and tender, unlike the craven bird that probably shed it.'
|
147
|
+
ITEM_ID_GUN = 4
|
148
|
+
ITEM_NAME_GUN = 'gun'
|
149
|
+
ITEM_DESC_GUN = 'Pew pew goes this firearm you wield, ifn\'t it weren\'t unloaded.'
|
150
|
+
|
151
|
+
ITEM_NAME_DEFAULT = 'thing'
|
152
|
+
ITEM_DESC_DEFAULt = 'Something truly interesting and worth your time to look at and possess.'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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
|
@@ -0,0 +1,128 @@
|
|
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
|
+
include Errors
|
11
|
+
|
12
|
+
def initialize(world)
|
13
|
+
@world = world
|
14
|
+
@commands = %w(character inventory rest look take world monsters go change help quit exit)
|
15
|
+
@aliases = %w(c i r l t w m g ch h q x)
|
16
|
+
@descriptions = [
|
17
|
+
'Display character information',
|
18
|
+
'Look in your inventory',
|
19
|
+
'Take a load off and regain stamina',
|
20
|
+
'Look around your current location',
|
21
|
+
'List all locations in the world',
|
22
|
+
'List all the monsters in the world',
|
23
|
+
'Go in a directions',
|
24
|
+
'Change something',
|
25
|
+
'This help menu',
|
26
|
+
'Quit the game',
|
27
|
+
'Exit the game (very different, of course)'
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
def print_separator
|
32
|
+
SEPARATOR
|
33
|
+
end
|
34
|
+
|
35
|
+
def list_commands
|
36
|
+
i = 0
|
37
|
+
print_separator
|
38
|
+
@commands.each do |cmd|
|
39
|
+
puts "#{cmd}, #{@aliases[i]} - #{@descriptions[i]}"
|
40
|
+
i = i + 1
|
41
|
+
end
|
42
|
+
print_separator
|
43
|
+
end
|
44
|
+
|
45
|
+
def evaluate(input)
|
46
|
+
if input.nil?
|
47
|
+
return
|
48
|
+
end
|
49
|
+
|
50
|
+
tokens = input.split
|
51
|
+
|
52
|
+
unless valid?(input)
|
53
|
+
return ERROR_COMMAND_INVALID
|
54
|
+
end
|
55
|
+
|
56
|
+
command = tokens.first
|
57
|
+
param = tokens[1]
|
58
|
+
|
59
|
+
case command
|
60
|
+
when @commands[0], @aliases[0] # character
|
61
|
+
@world.player.check_self
|
62
|
+
when @commands[1], @aliases[1] # inventory
|
63
|
+
if param
|
64
|
+
@world.player.inventory.describe_item(param)
|
65
|
+
else
|
66
|
+
@world.player.list_inventory
|
67
|
+
end
|
68
|
+
when @commands[2], @aliases[2] # rest
|
69
|
+
@world.player.rest
|
70
|
+
when @commands[3], @aliases[3] # look
|
71
|
+
if param
|
72
|
+
@world.player.cur_loc.describe_item(param)
|
73
|
+
else
|
74
|
+
@world.player.cur_loc.describe
|
75
|
+
end
|
76
|
+
when @commands[4], @aliases[4] # take
|
77
|
+
unless param.nil?
|
78
|
+
@world.player.inventory.add_item(@world.player.cur_loc, param)
|
79
|
+
else
|
80
|
+
ERROR_TAKE_PARAM_MISSING
|
81
|
+
end
|
82
|
+
when @commands[5], @aliases[5] # world
|
83
|
+
@world.list_locations
|
84
|
+
when @commands[6], @aliases[6] # monsters
|
85
|
+
@world.list_monsters
|
86
|
+
when @commands[7], @aliases[7] # go
|
87
|
+
if param.nil?
|
88
|
+
ERROR_GO_DIR_MISSING
|
89
|
+
else
|
90
|
+
@world.player.go(@world.locations, param)
|
91
|
+
end
|
92
|
+
when @commands[8], @aliases[8] # change
|
93
|
+
if param.nil?
|
94
|
+
puts ERROR_CHANGE_PARAM_MISSING
|
95
|
+
puts CHANGE_PARAMS
|
96
|
+
else
|
97
|
+
case param
|
98
|
+
when 'name'
|
99
|
+
@world.player.modify_name
|
100
|
+
else
|
101
|
+
ERROR_CHANGE_PARAM_INVALID
|
102
|
+
end
|
103
|
+
end
|
104
|
+
when @commands[9], @aliases[9] # help
|
105
|
+
list_commands
|
106
|
+
when @commands[10..11], @aliases[10] # quit/exit
|
107
|
+
puts QUIT_MESSAGE
|
108
|
+
exit(0)
|
109
|
+
else
|
110
|
+
return
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def valid?(input)
|
115
|
+
tokens = input.split
|
116
|
+
commands_and_aliases = @commands | @aliases
|
117
|
+
if commands_and_aliases.include?(tokens.first)
|
118
|
+
if tokens.size.between?(1,2)
|
119
|
+
return true
|
120
|
+
end
|
121
|
+
elsif tokens.empty?
|
122
|
+
return true
|
123
|
+
end
|
124
|
+
return false
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|