Permalink
Browse files

wordnik now optional command line switch; wordnik api key check; more…

… static word arrays for future use; future feep dep req updated
  • Loading branch information...
michaelchadwick committed Jun 15, 2015
1 parent edaec1d commit 16a58e414f177df716f2724e8e9b76834d06e396
View
@@ -8,7 +8,7 @@ require_relative '../lib/gemwarrior/game'
GAME_NAME = "Gem Warrior"
def parse_options
options = {:debug_mode => false, :god_mode => false, :beast_mode => false}
options = {:debug_mode => false, :god_mode => false, :beast_mode => false, :use_wordnik => false}
optparse = OptionParser.new do |opts|
opts.on('-v', '--version', 'Display version number and exit') do
@@ -27,6 +27,10 @@ def parse_options
opts.on('-b', '--beast', 'Set beastmode to true on load') do
options[:beast_mode] = true
end
opts.on('-w', '--wordnik', 'Use Wordnik to generate more diverse, dynamic descriptors of entities') do
options[:use_wordnik] = true
end
end
optparse.parse!()
View
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'json', '~> 1.8.2'
spec.add_runtime_dependency 'colorize', '~> 0.7.7'
#spec.add_runtime_dependency 'feep', '~> 0.0.9'
#spec.add_runtime_dependency 'feep', '~> 0.1.0'
#spec.add_runtime_dependency 'wordnik', '~> 4.12'
spec.add_development_dependency 'pry-byebug', '~> 3.0'
View
@@ -31,6 +31,8 @@ def initialize(options)
start_stats = PlayerLevels::get_level_stats(1)
world.debug_mode = options.fetch(:debug_mode)
world.use_wordnik = options.fetch(:use_wordnik)
world.player = Player.new({
:description => PLAYER_DESC_DEFAULT,
:level => start_stats[:level],
@@ -2,5 +2,5 @@
# Version of Gem Warrior
module Gemwarrior
VERSION = "0.7.2"
VERSION = "0.7.3"
end
@@ -6,25 +6,33 @@
module Gemwarrior
class WordList
STATIC_NOUN_VALUES = ["abutments", "asterisms", "bains", "blebs", "blowholes", "chapes", "civility", "crocuses", "dancers", "deniers", "diastoles", "dinges", "dualism", "ebullitions", "extremities", "fingering", "gabardines", "gullets", "knops", "nooks", "payments", "phaetons", "scalawags", "snickers", "specters", "splats", "squiggles", "thalamuses", "wallets", "xylophones"]
STATIC_ADJECTIVE_VALUES_VALUES = [
'5 o\'clock-shadowed', 'angry', 'aristocratic', 'calm', 'choice', 'clinical', 'cracked', 'depressed', 'dingy', 'excited', 'ginormous', 'handsome', 'hydrothermal', 'lackadaisical', 'man-sized', 'moist', 'non-venomous', 'picaresque', 'positive', 'relaxed', 'ruddy', 'smooth', 'shocked', 'sticky', 'tense', 'tingly', 'tired', 'toneless', 'unpolished', 'worn'
]
STATIC_NOUN_VALUES = [
'arrestor', 'blockhead', 'busker', 'candlestick', 'cigarette', 'clavinet', 'cursor', 'degeneration', 'devotchka', 'drive', 'earthquake', 'genie', 'granddaddy', 'haunter', 'heater', 'locality', 'nitrogen', 'quitter', 'raccoon', 'radish', 'recession', 'sheepdog', 'smorgasbord', 'softener', 'sphere', 'stage-hand', 'tsunami', 'tuber', 'whatsit', 'zillionaire'
]
STATIC_NOUN_PLURAL_VALUES = [
'abutments', 'asterisms', 'bains', 'blebs', 'blowholes', 'chapes', 'civility', 'crocuses', 'dancers', 'deniers', 'diastoles', 'dinges', 'dualism', 'ebullitions', 'extremities', 'fingering', 'gabardines', 'gullets', 'knops', 'nooks', 'payments', 'phaetons', 'scalawags', 'snickers', 'specters', 'splats', 'squiggles', 'thalamuses', 'wallets', 'xylophones'
]
STATIC_VERB_VALUES = [
'accentuate', 'accompany', 'blatter', 'bully', 'collide', 'crusade', 'disallow', 'entitle', 'infest', 'lateral', 'micturate', 'mourn', 'munge', 'numb', 'outdraw', 'overstep', 'plummet', 'refill', 'refurnish', 'reroute', 'rumple', 'scupper', 'smoosh', 'spifflicate', 'straighten', 'synthesize', 'terrorize', 'unshift', 'vociferate'
]
attr_accessor :type, :limit, :words, :error
attr_accessor :use_wordnik, :type, :limit, :words, :error
def initialize(type, limit = 10)
self.type = type
self.limit = limit
self.words = populate_words(type, limit)
self.error = nil
def initialize(use_wordnik = false, type = 'noun', limit = 10)
self.use_wordnik = use_wordnik
self.type = type
self.limit = limit
self.words = populate_words(type, limit)
self.error = nil
end
def get_random_value
random_value = words[rand(0..limit)]
if random_value.nil?
get_random_value
else
return random_value
end
return random_value.nil? ? get_random_value : random_value
end
def list_words
@@ -37,51 +45,68 @@ def populate_words(type, limit = 10)
url = 'http://api.wordnik.com:80/v4/words.json/randomWords'
api_key = ENV['WORDNIK_API_KEY']
case type
when 'noun', 'noun-plural', 'adjective', 'verb'
else
return get_static_values
end
json_return = HTTP.get(
url,
:params => {
:hasDictionaryDef => true,
:includePartOfSpeech => type,
:minCorpusCount => 1,
:maxCorpusCount => -1,
:minDictionaryCount => 1,
:maxDictionaryCount => -1,
:minLength => 5,
:maxLength => 12,
:sortBy => 'alpha',
:sortOrder => 'asc',
:limit => limit,
:api_key => api_key
}
)
json_data = JSON.parse(json_return.to_s)
if json_data.include?('type') && json_data.include?('message')
error = "wordnik #{json_data['type']}: #{json_data['message']}"
return get_static_values
else
word_list = []
json_data.map {|j| word_list.push(j['word'])}
if word_list.length > 0
return word_list
unless api_key.nil? || use_wordnik == false
case type
when 'noun', 'noun-plural', 'adjective', 'verb'
else
error = 'Empty array from Wordnik'
error = 'invalid wordlist type'
return
end
json_return = HTTP.get(
url,
:params => {
:hasDictionaryDef => true,
:includePartOfSpeech => type,
:minCorpusCount => 1,
:maxCorpusCount => -1,
:minDictionaryCount => 1,
:maxDictionaryCount => -1,
:minLength => 5,
:maxLength => 12,
:sortBy => 'alpha',
:sortOrder => 'asc',
:limit => limit,
:api_key => api_key
}
)
json_data = JSON.parse(json_return.to_s)
if json_data.include?('type') && json_data.include?('message')
error = "wordnik #{json_data['type']}: #{json_data['message']}"
return get_static_values
else
word_list = []
json_data.map {|j| word_list.push(j['word'])}
if word_list.length > 0
return word_list
else
error = 'Empty array from Wordnik'
return get_static_values(type)
end
end
end
return get_static_values(type)
end
def get_static_values
def get_static_values(type = nil)
static_values = []
0.upto(10) do
static_values.push(STATIC_NOUN_VALUES[rand(0..STATIC_NOUN_VALUES.length-1)])
case type
when 'noun'
static_values.push(STATIC_NOUN_VALUES[rand(0..STATIC_NOUN_VALUES.length-1)])
when 'noun-plural'
static_values.push(STATIC_NOUN_PLURAL_VALUES[rand(0..STATIC_NOUN_PLURAL_VALUES.length-1)])
when 'adjective'
static_values.push(STATIC_ADJECTIVE_VALUES[rand(0..STATIC_ADJECTIVE_VALUES.length-1)])
when 'verb'
static_values.push(STATIC_VERB_VALUES[rand(0..STATIC_VERB_VALUES.length-1)])
else
error = 'invalid wordlist type'
return
end
end
return static_values
end
View
@@ -65,9 +65,9 @@ def print_splash_message
end
def print_fortune
noun1_values = WordList.new('noun-plural')
noun2_values = WordList.new('noun-plural')
noun3_values = WordList.new('noun-plural')
noun1_values = WordList.new(world.use_wordnik, 'noun-plural')
noun2_values = WordList.new(world.use_wordnik, 'noun-plural')
noun3_values = WordList.new(world.use_wordnik, 'noun-plural')
puts "* Remember: #{noun1_values.get_random_value} and #{noun2_values.get_random_value} are the key to #{noun3_values.get_random_value} *\n\n"
end
View
@@ -15,7 +15,7 @@ class World
ERROR_LIST_PARAM_INVALID = 'That is not something that can be listed.'
ERROR_LOCATION_DESCRIBE_ENTITY_INVALID = 'You do not see that here.'
attr_accessor :monsters, :locations, :player, :debug_mode
attr_accessor :monsters, :locations, :player, :debug_mode, :use_wordnik
def initialize
self.monsters = init_monsters

0 comments on commit 16a58e4

Please sign in to comment.