Browse Source

Replaces the roomname generator.

j8
Boris Grozev 10 years ago
parent
commit
2f4dbe5458
2 changed files with 157 additions and 129 deletions
  1. 1
    1
      css/welcome_page.css
  2. 156
    128
      roomname_generator.js

+ 1
- 1
css/welcome_page.css View File

@@ -63,7 +63,7 @@
63 63
 }
64 64
 
65 65
 #enter_room_field {
66
-    font-size: 18px;
66
+    font-size: 15px;
67 67
     padding: 15px 0px 10px 10px;
68 68
     border: none;
69 69
     -webkit-appearance: none;

+ 156
- 128
roomname_generator.js View File

@@ -1,161 +1,189 @@
1 1
 var RoomNameGenerator = function(my) {
2
-
3
-
4 2
     /**
5 3
      * Constructs new RoomNameGenerator object.
6 4
      * @constructor constructs new RoomNameGenerator object.
7 5
      */
8 6
     function RoomNameGeneratorProto()
9 7
     {
10
-
11 8
     }
12 9
 
13
-    /**
14
-     * Default separator the words in the room name
15
-     * @type {string}
16
-     */
17
-    var DEFAULT_SEPARATOR = "-";
10
+    //var nouns = [
11
+    //];
12
+    var pluralNouns = [
13
+        "Aliens", "Animals", "Antelopes", "Ants", "Apes", "Apples", "Baboons", "Bacteria", "Badgers", "Bananas", "Bats",
14
+        "Bears", "Birds", "Blokes", "Bonobos", "Boys", "Brides", "Brothers", "Bugs", "Bulls", "Butterflies", "Cheetahs",
15
+        "Cherries", "Chicken", "Children", "Chimps", "Clowns", "Cows", "Creatures", "Dinosaurs", "Dogs", "Dolphins",
16
+        "Donkeys", "Dragons", "Ducks", "Dudes", "Dwarfs", "Eagles", "Elephants", "Elves", "FAIL", "Fathers", "Fellows",
17
+        "Fish", "Flowers", "Folk", "Folks", "Frogs", "Fruit", "Fungi", "Galaxies", "Gals", "Geese", "Girls", "Goats",
18
+        "Gorillas", "Grooms", "Guys", "Hedgehogs", "Hippos", "Horses", "Hunters", "Insects", "Kids", "Knights",
19
+        "Lemons", "Lemurs", "Leopards", "LifeForms", "Lions", "Lizards", "Men", "Mice", "Monkeys", "Monsters",
20
+        "Mothers", "Mushrooms", "Octopodes", "Oranges", "Orangutans", "Organisms", "Pants", "Parrots", "Penguins",
21
+        "People", "Pigeons", "Pigs", "Pineapples", "Plants", "Potatoes", "Priests", "Rats", "Reptiles", "Reptilians",
22
+        "Rhinos", "Seagulls", "Sheep", "Siblings", "Sisters", "Snakes", "Spaghetti", "Spiders", "Squid", "Squirrels",
23
+        "Stars", "Students", "Teachers", "Tigers", "Tomatoes", "Trees", "Vegetables", "Virgins", "Viruses", "Vulcans",
24
+        "Weasels", "Wenches", "Whales", "Witches", "Wizards", "Wolves", "Women", "Workers", "Worms", "Zebras"
25
+    ];
26
+    //var places = [
27
+    //"Pub", "University", "Airport", "Library", "Mall", "Theater", "Stadium", "Office", "Show", "Gallows", "Beach",
28
+    // "Cemetery", "Hospital", "Reception", "Restaurant", "Bar", "Church", "House", "School", "Square", "Village",
29
+    // "Cinema", "Movies", "Party", "Restroom", "End", "Jail", "PostOffice", "Station", "Circus", "Gates", "Entrance",
30
+    // "Bridge"
31
+    //];
32
+    var verbs = [
33
+        "Abandon", "Abuse", "Adapt", "Advertise", "Answer", "Answer", "Anticipate", "Appreciate", "Appreciate",
34
+        "Approach", "Ask", "Bite", "Bleed", "Blossom", "Blush", "Breathe", "Breed", "Bribe", "Burn", "Calculate",
35
+        "Clean", "Come", "Communicate", "Compute", "Confess", "Confiscate", "Conjugate", "Conjure", "Consume",
36
+        "Contemplate", "Copulate", "Crawl", "Curse", "Dance", "Defecate", "Delegate", "Devour", "Die", "Differ",
37
+        "Dissolve", "DoIt", "Drink", "Eat", "Elaborate", "Emancipate", "Estimate", "Excrete", "Expire", "Extinguish",
38
+        "Extract", "FAIL", "Facilitate", "Fall", "Feed", "Finish", "Floss", "Fly", "Follow", "Fragment", "Freeze",
39
+        "Gather", "Glow", "Grow", "Hex", "Hide", "Hug", "Hump", "Hurry", "Improve", "Intersect", "Investigate", "Jinx",
40
+        "Joke", "Kill", "Kiss", "Laugh", "Lick", "Manage", "Meet", "Merge", "Move", "Object", "Observe", "Offer",
41
+        "Paint", "Participate", "Party", "Perform", "Pursue", "Pierce", "Play", "Postpone", "Pray", "Proclaim",
42
+        "Question", "Reckon", "Reproduce", "Rhyme", "Rot", "Scream", "Search", "Secrete", "Select", "Share", "Shoot",
43
+        "Shout", "Shout", "Signal", "Skate", "Sleep", "Smile", "Smoke", "Solve", "Spell", "Spell", "Steer", "Stink",
44
+        "Substitute", "Sweat", "Swim", "Taste", "Teach", "Terminate", "Think", "Unite", "Vanish", "Worship"
45
+    ];
46
+    var adverbs = [
47
+        "Absently", "Accurately", "Accusingly", "Adorably", "AllTheTime", "Alone", "Always", "Amazingly", "Angrily",
48
+        "Anxiously", "Anywhere", "Appallingly", "Apparently", "Articulately", "Astonishingly", "Badly", "Barely",
49
+        "Beautifully", "Blindly", "Bravely", "Brightly", "Briskly", "Brutally", "Calmly", "Carefully", "Casually",
50
+        "Cautiously", "Cleverly", "Constantly", "Correctly", "Crazily", "Curiously", "Cynically", "Daily",
51
+        "Dangerously", "Deliberately", "Delicately", "Desperately", "Discreetly", "Eagerly", "Easily", "Euphoric",
52
+        "Evenly", "Everywhere", "Exactly", "Expectantly", "Extensively", "FAIL", "Ferociously", "Fiercely", "Finely",
53
+        "Flatly", "Frequently", "Frighteningly", "Gently", "Gently", "Gloriously", "Grimly", "Guiltily", "Happily",
54
+        "Hard", "Hastily", "Heroically", "High", "Highly", "Hourly", "Humbly", "Hysterically", "Immensely",
55
+        "Impartially", "Impolitely", "Indifferently", "Intensely", "Jealously", "Jovially", "Kindly", "Lazily",
56
+        "Lightly", "Loudly", "Lovingly", "Loyally", "Magnificently", "Malevolently", "Merrily", "Mightily", "Miserably",
57
+        "Mysteriously", "NOT", "Nervously", "Nicely", "Nowhere", "Objectively", "Obnoxiously", "Obsessively",
58
+        "Obviously", "Often", "Painfully", "Patiently", "Playfully", "Politely", "Poorly", "Precisely", "Promptly",
59
+        "Quickly", "Quietly", "Randomly", "Rapidly", "Rarely", "Recklessly", "Regularly", "Remorsefully", "Responsibly",
60
+        "Rudely", "Ruthlessly", "Sadly", "Scornfully", "Seamlessly", "Seldom", "Selfishly", "Seriously", "Shakily",
61
+        "Sharply", "Sideways", "Silently", "Sleepily", "Slightly", "Slowly", "Slyly", "Smoothly", "Softly", "Solemnly",
62
+        "Solemnly", "Steadily", "Sternly", "Strangely", "Strongly", "Stunningly", "Surely", "Tenderly", "Thoughtfully",
63
+        "Tightly", "Uneasily", "Vanishingly", "Violently", "Warmly", "Weakly", "Wearily", "Weekly", "Weirdly", "Well",
64
+        "Well", "Wickedly", "Wildly", "Wisely", "Wonderfully", "Yearly"
65
+    ];
66
+    var adjectives = [
67
+        "Abominable", "Accurate", "Adorable", "All", "Alleged", "Ancient", "Angry", "Angry", "Anxious", "Appalling",
68
+        "Apparent", "Astonishing", "Attractive", "Awesome", "Baby", "Bad", "Beautiful", "Benign", "Big", "Bitter",
69
+        "Blind", "Blue", "Bold", "Brave", "Bright", "Brisk", "Brutal", "Calm", "Camouflaged", "Casual", "Cautious",
70
+        "Choppy", "Chosen", "Clever", "Cold", "Cool", "Crawly", "Crazy", "Creepy", "Cruel", "Curious", "Cynical",
71
+        "Dangerous", "Dark", "Delicate", "Desperate", "Difficult", "Discreet", "Disguised", "Disgusting", "Dizzy",
72
+        "Drunk", "Dumb", "Eager", "Easy", "Edgy", "Electric", "Elegant", "Emancipated", "Enormous", "Euphoric", "Evil",
73
+        "FAIL", "Fast", "Fat", "Fat", "Ferocious", "Fierce", "Fine", "Flawed", "Flying", "Flying", "Foolish", "Foxy",
74
+        "Freezing", "Funny", "Furious", "Gentle", "Glorious", "Gnarly", "Golden", "Good", "Green", "Green", "Guilty",
75
+        "Hairy", "Happy", "Hard", "Hasty", "Hazy", "Heroic", "Horny", "Hostile", "Hot", "Humble", "Humongous",
76
+        "Humorous", "Hysterical", "Idealistic", "Ignorant", "Immense", "Impartial", "Impolite", "Indifferent",
77
+        "Infuriated", "Insightful", "Intense", "Interesting", "Intimidated", "Intriguing", "Jealous", "Jolly", "Jovial",
78
+        "Jumpy", "Kind", "Laughing", "Lazy", "Liquid", "Lonely", "Longing", "Loud", "Loving", "Loyal", "Macabre", "Mad",
79
+        "Magical", "Magnificent", "Malevolent", "Manly", "Medieval", "Memorable", "Mere", "Merry", "Mighty",
80
+        "Mischievous", "Miserable", "Modified", "Moody", "Most", "Mysterious", "Mystical", "Naked", "Nasty", "Needy",
81
+        "Nervous", "Nice", "Objective", "Obnoxious", "Obsessive", "Obvious", "Oily", "Oily", "Opinionated", "Orange",
82
+        "Painful", "Passionate", "Perfect", "Pink", "Playful", "Poisonous", "Polite", "Poor", "Popular", "Powerful", 
83
+        "Precise", "Preserved", "Pretty", "Purple", "Quick", "Quiet", "Racist", "Random", "Rapid", "Rare", "Real",
84
+        "Reassuring", "Reckless", "Red", "Regular", "Remorseful", "Responsible", "Rich", "Rotten", "Rude", "Ruthless",
85
+        "Sad", "Scared", "Scary", "Scornful", "Screaming", "Selfish", "Selfish", "Serious", "Shady", "Shaky", "Sharp",
86
+        "Shiny", "Shy", "Simple", "Skinny", "Sleepy", "Slow", "Sly", "Small", "Smart", "Smelly", "Smiling", "Smooth",
87
+        "Smug", "Sober", "Soft", "Solemn", "Square", "Square", "Steady", "Stinking", "Stoned", "Strange", "Strong",
88
+        "Stunning", "Stunning", "Stupid", "Subjective", "Successful", "Surly", "Sweet", "Tactful", "Tense",
89
+        "Thoughtful", "Tight", "Tiny", "Tolerant", "Ugly", "Uneasy", "Unique", "Unseen", "Violent", "Warm", "Weak",
90
+        "Weird", "WellCooked",  "WellFed", "Wicked", "Wild", "Wise", "Witty", "Wonderful", "Worried", "Yellow", "Young",
91
+        "Zealous"
92
+        ];
93
+    //var pronouns = [
94
+    //];
95
+    //var conjunctions = [
96
+    //"And", "Or", "For", "Above", "Before", "Against", "Between"
97
+    //];
18 98
 
19
-    /**
20
-     * Default number of words in the room name.
21
-     * @type {number}
99
+    /*
100
+     * Maps a string (category name) to the array of words from that category.
22 101
      */
23
-    var NUMBER_OF_WORDS = 3;
102
+    var CATEGORIES =
103
+    {
104
+        //"_NOUN_": nouns,
105
+        "_PLURALNOUN_": pluralNouns,
106
+        //"_PLACE_": places,
107
+        "_VERB_": verbs,
108
+        "_ADVERB_": adverbs,
109
+        "_ADJECTIVE_": adjectives
110
+        //"_PRONOUN_": pronouns,
111
+        //"_CONJUNCTION_": conjunctions,
112
+    };
24 113
 
114
+    var PATTERNS = [
115
+        "_ADJECTIVE__PLURALNOUN__VERB__ADVERB_"
25 116
 
26
-    /**
27
-     * The list with words.
28
-     * @type {string[]}
29
-     */
30
-    var words = [
31
-        "definite", "indefinite", "articles", "name", "preposition", "help", "very", "to", "through", "and", "just",
32
-        "a", "form", "in", "sentence", "is", "great", "it", "think", "you", "say", "that", "help", "he", "low", "was",
33
-        "line", "for", "differ", "on", "turn", "are", "cause", "with", "much", "as", "mean", "before", "his", "move",
34
-        "they", "right", "be", "boy", "at", "old", "one", "too", "have", "same", "this", "tell", "from", "does", "or",
35
-        "set", "had", "three", "by", "want", "hot", "air", "word", "well", "but", "also", "what", "play", "some", "small",
36
-        "we", "end", "can", "put", "out", "home", "other", "read", "were", "hand", "all", "port", "there", "large",
37
-        "when", "spell", "up", "add", "use", "even", "your", "land", "how", "here", "said", "must", "an", "big", "each",
38
-        "high", "she", "such", "which", "follow", "do", "act", "their", "why", "time", "ask", "if", "men", "will", "change",
39
-        "way", "went", "about", "light", "many", "kind", "then", "off", "them", "need", "write", "house", "would",
40
-        "picture", "like", "try", "so", "us", "these", "again", "her", "animal", "long", "point", "make", "mother",
41
-        "thing", "world", "see", "near", "him", "build", "two", "self", "has", "earth", "look", "father", "more", "head",
42
-        "day", "stand", "could", "own", "go", "page", "come", "should", "did", "country", "number", "found", "sound",
43
-        "answer", "no", "school", "most", "grow", "people", "study", "my", "still", "over", "learn", "know", "plant",
44
-        "water", "cover", "than", "food", "call", "sun", "first", "four", "who", "between", "may", "state", "down",
45
-        "keep", "side", "eye", "been", "never", "now", "last", "find", "let", "any", "thought", "new", "city", "work",
46
-        "tree", "part", "cross", "take", "farm", "get", "hard", "place", "start", "made", "might", "live", "story",
47
-        "where", "saw", "after", "far", "back", "sea", "little", "draw", "only", "left", "round", "late", "man", "run",
48
-        "year", "don't", "came", "while", "show", "press", "every", "close", "good", "night", "me", "real", "give",
49
-        "life", "our", "few", "under", "north", "open", "ten", "seem", "simple", "together", "several", "next", "vowel",
50
-        "white", "toward", "children", "war", "begin", "lay", "got", "against", "walk", "pattern", "example", "slow",
51
-        "ease", "center", "paper", "love", "group", "person", "always", "money", "music", "serve", "those", "appear",
52
-        "both", "road", "mark", "map", "often", "rain", "letter", "rule", "until", "govern", "mile", "pull", "river",
53
-        "cold", "car", "notice", "feet", "voice", "care", "unit", "second", "power", "book", "town", "carry", "fine",
54
-        "took", "certain", "science", "fly", "eat", "fall", "room", "lead", "friend", "cry", "began", "dark", "idea",
55
-        "machine", "fish", "note", "mountain", "wait", "stop", "plan", "once", "figure", "base", "star", "hear", "box",
56
-        "horse", "noun", "cut", "field", "sure", "rest", "watch", "correct", "color", "able", "face", "pound", "wood",
57
-        "done", "main", "beauty", "enough", "drive", "plain", "stood", "girl", "contain", "usual", "front", "young",
58
-        "teach", "ready", "week", "above", "final", "ever", "gave", "red", "green", "list", "oh", "though", "quick",
59
-        "feel", "develop", "talk", "ocean", "bird", "warm", "soon", "free", "body", "minute", "dog", "strong", "family",
60
-        "special", "direct", "mind", "pose", "behind", "leave", "clear", "song", "tail", "measure", "produce", "door",
61
-        "fact", "product", "street", "black", "inch", "short", "multiply", "numeral", "nothing", "class", "course", "wind",
62
-        "stay", "question", "wheel", "happen", "full", "complete", "force", "ship", "blue", "area", "object", "half",
63
-        "decide", "rock", "surface", "order", "deep", "fire", "moon", "south", "island", "problem", "foot", "piece",
64
-        "system", "told", "busy", "knew", "test", "pass", "record", "since", "boat", "top", "common", "whole", "gold",
65
-        "king", "possible", "space", "plane", "heard", "stead", "best", "dry", "hour", "wonder", "better", "laugh",
66
-        "true", "thousand", "during", "ago", "hundred", "ran", "five", "check", "remember", "game", "step", "shape",
67
-        "early", "equate", "hold", "hot", "west", "miss", "ground", "brought", "interest", "heat", "reach", "snow",
68
-        "fast", "tire", "verb", "bring", "sing", "yes", "listen", "distant", "six", "fill", "table", "east", "travel",
69
-        "paint", "less", "language", "morning", "among", "grand", "cat", "ball", "century", "yet", "consider", "wave",
70
-        "type", "drop", "law", "heart", "bit", "am", "coast", "present", "copy", "heavy", "phrase", "dance", "silent",
71
-        "engine", "tall", "position", "sand", "arm", "soil", "wide", "roll", "sail", "temperature", "material", "finger",
72
-        "size", "industry", "vary", "value", "settle", "fight", "speak", "lie", "weight", "beat", "general", "excite",
73
-        "ice", "natural", "matter", "view", "circle", "sense", "pair", "ear", "include", "else", "divide", "quite",
74
-        "syllable", "broke", "felt", "case", "perhaps", "middle", "pick", "kill", "sudden", "son", "count", "lake",
75
-        "square", "moment", "reason", "scale", "length", "loud", "represent", "spring", "art", "observe", "subject",
76
-        "child", "region", "straight", "energy", "consonant", "hunt", "nation", "probable", "dictionary", "bed", "milk",
77
-        "brother", "speed", "egg", "method", "ride", "organ", "cell", "pay", "believe", "age", "fraction", "section",
78
-        "forest", "dress", "sit", "cloud", "race", "surprise", "window", "quiet", "store", "stone", "summer", "tiny",
79
-        "train", "climb", "sleep", "cool", "prove", "design", "lone", "poor", "leg", "lot", "exercise", "experiment",
80
-        "wall", "bottom", "catch", "key", "mount", "iron", "wish", "single", "sky", "stick", "board", "flat", "joy",
81
-        "twenty", "winter", "skin", "sat", "smile", "written", "crease", "wild", "hole", "instrument", "trade", "kept",
82
-        "melody", "glass", "trip", "grass", "office", "cow", "receive", "job", "row", "edge", "mouth", "sign", "exact",
83
-        "visit", "symbol", "past", "die", "soft", "least", "fun", "trouble", "bright", "shout", "gas", "except",
84
-        "weather", "wrote", "month", "seed", "million", "tone", "bear", "join", "finish", "suggest", "happy", "clean",
85
-        "hope", "break", "flower", "lady", "clothe", "yard", "strange", "rise", "gone", "bad", "jump", "blow", "baby",
86
-        "oil", "eight", "blood", "village", "touch", "meet", "grew", "root", "cent", "buy", "mix", "raise", "team",
87
-        "solve", "wire", "metal", "cost", "whether", "lost", "push", "brown", "seven", "wear", "paragraph", "garden",
88
-        "third", "equal", "shall", "sent", "held", "choose", "hair", "fell", "describe", "fit", "cook", "flow", "floor",
89
-        "fair", "either", "bank", "result", "collect", "burn", "save", "hill", "control", "safe", "decimal", "rank",
90
-        "word", "reference", "gentle", "truck", "woman", "noise", "captain", "level",
91
-        "practice", "chance", "separate", "gather", "difficult", "shop", "doctor", "stretch", "please", "throw",
92
-        "protect", "shine", "noon", "property", "whose", "column", "locate", "molecule", "ring", "select", "character",
93
-        "wrong", "insect", "gray", "caught", "repeat", "period", "require", "indicate", "broad", "radio", "prepare",
94
-        "spoke", "salt", "atom", "nose", "human", "plural", "history", "anger", "effect", "claim", "electric",
95
-        "continent", "expect", "oxygen", "crop", "sugar", "modern", "death", "element", "pretty", "hit", "skill",
96
-        "student", "women", "corner", "season", "party", "solution", "supply", "magnet", "bone", "silver", "rail",
97
-        "thank", "imagine", "branch", "provide", "match", "agree", "suffix", "thus", "especially", "capital", "fig",
98
-        "won't", "afraid", "chair", "huge", "danger", "sister", "fruit", "steel", "rich", "discuss", "thick", "forward",
99
-        "soldier", "similar", "process", "guide", "operate", "experience", "guess", "score", "necessary", "apple",
100
-        "sharp", "bought", "wing", "led", "create", "pitch", "neighbor", "coat", "wash", "mass", "bat", "card", "rather",
101
-        "band", "crowd", "rope", "corn", "slip", "compare", "win", "poem", "dream", "string", "evening", "bell",
102
-        "condition", "depend", "feed", "meat", "tool", "rub", "total", "tube", "basic", "famous", "smell", "dollar",
103
-        "valley", "stream", "nor", "fear", "double", "sight", "seat", "thin", "arrive", "triangle", "master", "planet",
104
-        "track", "hurry", "parent", "chief", "shore", "colony", "division", "clock", "sheet", "mine", "substance", "tie",
105
-        "favor", "enter", "connect", "major", "post", "fresh", "spend", "search", "chord", "send", "fat", "yellow",
106
-        "glad", "gun", "original", "allow", "share", "print", "station", "dead", "dad", "spot", "bread", "desert",
107
-        "charge", "suit", "proper", "current", "bar", "lift", "offer", "rose", "segment", "continue", "slave", "block",
108
-        "duck", "chart", "instant", "hat", "market", "sell", "degree", "success", "populate", "company", "chick",
109
-        "subtract", "dear", "event", "enemy", "particular", "reply", "deal", "drink", "swim", "occur", "term", "support",
110
-        "opposite", "speech", "wife", "nature", "shoe", "range", "shoulder", "steam", "spread", "motion", "arrange",
111
-        "path", "camp", "liquid", "invent", "log", "cotton", "meant", "born", "quotient", "determine", "teeth", "quart",
112
-        "shell", "nine", "neck", "fancy", "fan", "football"
117
+        // BeautifulFungiOrSpaghetti
118
+        //"_ADJECTIVE__PLURALNOUN__CONJUNCTION__PLURALNOUN_",
119
+
120
+        // AmazinglyScaryToy
121
+        //"_ADVERB__ADJECTIVE__NOUN_",
122
+
123
+        // NeitherTrashNorRifle
124
+        //"Neither_NOUN_Nor_NOUN_",
125
+        //"Either_NOUN_Or_NOUN_",
126
+
127
+        // EitherCopulateOrInvestigate
128
+        //"Either_VERB_Or_VERB_",
129
+        //"Neither_VERB_Nor_VERB_",
130
+
131
+        //"The_ADJECTIVE__ADJECTIVE__NOUN_",
132
+        //"The_ADVERB__ADJECTIVE__NOUN_",
133
+        //"The_ADVERB__ADJECTIVE__NOUN_s",
134
+        //"The_ADVERB__ADJECTIVE__PLURALNOUN__VERB_",
135
+
136
+        // WolvesComputeBadly
137
+        //"_PLURALNOUN__VERB__ADVERB_",
138
+
139
+        // UniteFacilitateAndMerge
140
+        //"_VERB__VERB_And_VERB_",
141
+
142
+        //NastyWitchesAtThePub
143
+        //"_ADJECTIVE__PLURALNOUN_AtThe_PLACE_",
113 144
     ];
114 145
 
115
-    /**
116
-     * Returns random word from the array of words.
117
-     * @returns {string} random word from the array of words.
146
+
147
+    /*
148
+     * Returns a random element from the array 'arr' 
118 149
      */
119
-    function generateWord()
150
+    function randomElement(arr)
120 151
     {
121
-        return words[Math.floor(Math.random() * words.length)];
152
+        return arr[Math.floor(Math.random() * arr.length)];
122 153
     }
123 154
 
124
-    /**
125
-     * Generates new room name.
126
-     * @param separator the separator for the words.
127
-     * @param number_of_words number of words in the room name
128
-     * @returns {string} the room name
155
+    /*
156
+     * Returns true if the string 's' contains one of the
157
+     * template strings.
129 158
      */
130
-    RoomNameGeneratorProto.generateRoom = function(separator, number_of_words)
159
+    function hasTemplate(s)
131 160
     {
132
-        if(!separator)
133
-            separator = DEFAULT_SEPARATOR;
134
-        if(!number_of_words)
135
-            number_of_words = NUMBER_OF_WORDS;
136
-        var name = "";
137
-        for(var i = 0; i<number_of_words; i++)
138
-            name += ((i != 0)? separator : "") + generateWord();
139
-        return name;
161
+        for (var template in CATEGORIES){
162
+            if (s.indexOf(template) >= 0){
163
+                return true;
164
+            }
165
+        }
140 166
     }
141 167
 
142 168
     /**
143 169
      * Generates new room name.
144
-     * @param number_of_words number of words in the room name
145
-     * @returns {string} the room name
170
+     * @param number_of_words ignored
146 171
      */
147 172
     RoomNameGeneratorProto.generateRoomWithoutSeparator = function(number_of_words)
148 173
     {
149
-        if(!number_of_words)
150
-            number_of_words = NUMBER_OF_WORDS;
151
-        var name = "";
152
-        for(var i = 0; i<number_of_words; i++) {
153
-            var word = generateWord();
154
-            word = word.substring(0, 1).toUpperCase() + word.substring(1, word.length);
155
-            name += word ;
174
+        // Note that if more than one pattern is available, the choice of 'name' won't be random (names from patterns
175
+        // with fewer options will have higher probability of being chosen that names from patterns with more options).
176
+        var name = randomElement(PATTERNS);
177
+        var word;
178
+        while (hasTemplate(name)){
179
+            for (var template in CATEGORIES){
180
+                word = randomElement(CATEGORIES[template]);
181
+                name = name.replace(template, word);
182
+            }
156 183
         }
184
+
157 185
         return name;
158
-    }
186
+    };
159 187
 
160 188
     return RoomNameGeneratorProto;
161 189
 }();

Loading…
Cancel
Save