Skip to content

Commit 2461641

Browse files
chadicusnubs
authored andcommitted
Add Alliteration Generator.
This generator returns 2-word alliterative adjective/animal name pairs. Code updated by @nubs to match standards of the project, but otherwise code was written by @chadicus. Closes #5.
1 parent be07ce5 commit 2461641

6 files changed

+849
-1
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ The video game name generator is based off of [prior](http://videogamena.me/) [a
3434
* *Neurotic Jackhammer Detective*
3535
* *My Little Mountain Climber Conflict*
3636
* *Small-Time Princess vs. The Space Mutants*
37+
38+
## Alliterative Names
39+
The alliteration name generator is based off of a list of [adjectives](http://grammar.yourdictionary.com/parts-of-speech/adjectives/list-of-adjective-words.html) and a list of [animals](https://animalcorner.co.uk/animals/).
40+
41+
#### Examples
42+
* *Agreeable Anaconda*
43+
* *Disturbed Duck*
44+
* *Misty Meerkat*
45+
* *Prickly Pig*

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nubs/random-name-generator",
33
"description": "A library to create interesting, sometimes entertaining, random names.",
4-
"keywords": ["random", "generator", "video game"],
4+
"keywords": ["random", "generator", "video game", "alliteration"],
55
"authors": [
66
{
77
"name": "Spencer Rinehart",

src/Alliteration.php

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
namespace Nubs\RandomNameGenerator;
3+
4+
use Cinam\Randomizer\Randomizer;
5+
6+
/**
7+
* Defines an alliterative name generator.
8+
*/
9+
class Alliteration implements Generator
10+
{
11+
/** @type array The definition of the potential adjectives. */
12+
protected $_adjectives;
13+
14+
/** @type array The definition of the potential nouns. */
15+
protected $_nouns;
16+
17+
/** @type Cinam\Randomizer\Randomizer The random number generator. */
18+
protected $_randomizer;
19+
20+
/**
21+
* Initializes the Alliteration Generator with the default word lists.
22+
*
23+
* @api
24+
* @param \Cinam\Randomizer\Randomizer $randomizer The random number generator.
25+
*/
26+
public function __construct(Randomizer $randomizer = null)
27+
{
28+
$this->_randomizer = $randomizer;
29+
$this->_adjectives = file(__DIR__ . '/adjectives.txt', FILE_IGNORE_NEW_LINES);
30+
$this->_nouns = file(__DIR__ . '/nouns.txt', FILE_IGNORE_NEW_LINES);
31+
}
32+
33+
/**
34+
* Gets a randomly generated alliterative name.
35+
*
36+
* @api
37+
* @return string A random alliterative name.
38+
*/
39+
public function getName()
40+
{
41+
$adjective = $this->_getRandomWord($this->_adjectives);
42+
$noun = $this->_getRandomWord($this->_nouns, $adjective[0]);
43+
44+
return ucwords("{$adjective} {$noun}");
45+
}
46+
47+
/**
48+
* Get a random word from the list of words, optionally filtering by starting letter.
49+
*
50+
* @param array $words An array of words to choose from.
51+
* @param string $startingLetter The desired starting letter of the word.
52+
* @return string The random word.
53+
*/
54+
protected function _getRandomWord(array $words, $startingLetter = null)
55+
{
56+
$wordsToSearch = $startingLetter === null ? $words : preg_grep("/^{$startingLetter}/", $words);
57+
return $this->_randomizer ? $this->_randomizer->getArrayValue($wordsToSearch) : $wordsToSearch[array_rand($wordsToSearch)];
58+
}
59+
}

src/adjectives.txt

+233
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
adorable
2+
adventurous
3+
aggressive
4+
agreeable
5+
alert
6+
alive
7+
amused
8+
angry
9+
annoyed
10+
annoying
11+
anxious
12+
arrogant
13+
ashamed
14+
attractive
15+
average
16+
awful
17+
bad
18+
beautiful
19+
better
20+
bewildered
21+
black
22+
bloody
23+
blue
24+
blue-eyed
25+
blushing
26+
bored
27+
brainy
28+
brave
29+
breakable
30+
bright
31+
busy
32+
calm
33+
careful
34+
cautious
35+
charming
36+
cheerful
37+
clean
38+
clear
39+
clever
40+
cloudy
41+
clumsy
42+
colorful
43+
combative
44+
comfortable
45+
concerned
46+
condemned
47+
confused
48+
cooperative
49+
courageous
50+
crazy
51+
creepy
52+
crowded
53+
cruel
54+
curious
55+
cute
56+
dangerous
57+
dark
58+
dead
59+
defeated
60+
defiant
61+
delightful
62+
depressed
63+
determined
64+
different
65+
difficult
66+
disgusted
67+
distinct
68+
disturbed
69+
dizzy
70+
doubtful
71+
drab
72+
dull
73+
eager
74+
easy
75+
elated
76+
elegant
77+
embarrassed
78+
enchanting
79+
encouraging
80+
energetic
81+
enthusiastic
82+
envious
83+
evil
84+
excited
85+
expensive
86+
exuberant
87+
fair
88+
faithful
89+
famous
90+
fancy
91+
fantastic
92+
fierce
93+
filthy
94+
fine
95+
foolish
96+
fragile
97+
frail
98+
frantic
99+
friendly
100+
frightened
101+
funny
102+
gentle
103+
gifted
104+
glamorous
105+
gleaming
106+
glorious
107+
good
108+
gorgeous
109+
graceful
110+
grieving
111+
grotesque
112+
grumpy
113+
handsome
114+
happy
115+
healthy
116+
helpful
117+
helpless
118+
hilarious
119+
homeless
120+
homely
121+
horrible
122+
hungry
123+
hurt
124+
ill
125+
important
126+
impossible
127+
inexpensive
128+
innocent
129+
inquisitive
130+
itchy
131+
jealous
132+
jittery
133+
jolly
134+
joyous
135+
kind
136+
lazy
137+
light
138+
lively
139+
lonely
140+
long
141+
lovely
142+
lucky
143+
magnificent
144+
misty
145+
modern
146+
motionless
147+
muddy
148+
mushy
149+
mysterious
150+
nasty
151+
naughty
152+
nervous
153+
nice
154+
nutty
155+
obedient
156+
obnoxious
157+
odd
158+
old-fashioned
159+
open
160+
outrageous
161+
outstanding
162+
panicky
163+
perfect
164+
plain
165+
pleasant
166+
poised
167+
poor
168+
powerful
169+
precious
170+
prickly
171+
proud
172+
puzzled
173+
quaint
174+
real
175+
relieved
176+
repulsive
177+
rich
178+
scary
179+
selfish
180+
shiny
181+
shy
182+
silly
183+
sleepy
184+
smiling
185+
smoggy
186+
sore
187+
sparkling
188+
splendid
189+
spotless
190+
stormy
191+
strange
192+
stupid
193+
successful
194+
super
195+
talented
196+
tame
197+
tender
198+
tense
199+
terrible
200+
testy
201+
thankful
202+
thoughtful
203+
thoughtless
204+
tired
205+
tough
206+
troubled
207+
ugliest
208+
ugly
209+
uninterested
210+
unsightly
211+
unusual
212+
upset
213+
uptight
214+
vast
215+
victorious
216+
vivacious
217+
wandering
218+
weary
219+
wicked
220+
wide-eyed
221+
wild
222+
witty
223+
worrisome
224+
worried
225+
wrong
226+
xenophobic
227+
xanthous
228+
xerothermic
229+
yawning
230+
yellowed
231+
yucky
232+
zany
233+
zealous

0 commit comments

Comments
 (0)