Browse Source

added youon control, refactored consonants packs choosing.

Henry Jameson 9 years ago
parent
commit
f1f4f7d766
2 changed files with 32 additions and 24 deletions
  1. 1
    1
      src/Syllable.scala
  2. 31
    23
      src/SyllableGenerator.scala

+ 1
- 1
src/Syllable.scala View File

@@ -4,7 +4,7 @@
4 4
  * Date: 4/25/13
5 5
  * Time: 9:49 PM
6 6
  */
7
-class Syllable (val consonant: String, val vowel: String){
7
+class Syllable (val consonant: String, val vowel: String, val isYouon: Boolean){
8 8
 	val value: String = consonant + vowel
9 9
 	val consonantOnly : Boolean = vowel == "n"
10 10
 	val vowelOnly : Boolean = consonant == ""

+ 31
- 23
src/SyllableGenerator.scala View File

@@ -24,34 +24,42 @@ class SyllableGenerator (val useX: Boolean, val sInsteadOfsh: Boolean = false, v
24 24
 	val forCommon = forW:::forWRare:::forAll
25 25
 	val forYouon = forW:::forAll
26 26
 
27
-
28
-	def generateSyllableF(youon:Boolean):Syllable = {
29
-		var rarity:Rarity.Value = null
30
-		val consonants =
31
-		if (youon){
32
-			rarity = Rarity.Youon
33
-			youonConsonants
27
+	/**
28
+	 * Generates full syllable, consonant+vowel
29
+	 * @param youonForce force creating ya\yo\yu syllable
30
+	 * @param youonProhibit don't create ?ya\?yo\?yu syllables, for word creation.
31
+	 * @return resulting syllable
32
+	 */
33
+	def generateSyllableF(youonForce:Boolean, youonProhibit:Boolean):Syllable = {
34
+		val rarity =
35
+		if (youonForce){
36
+			Rarity.Youon
37
+		} else if (Randomizer.pickWithProb(0.50)){
38
+			Rarity.Common
34 39
 		} else if (Randomizer.pickWithProb(0.50)){
35
-			rarity = Rarity.Common
36
-			commonConsonants
40
+			Rarity.Uncommon
37 41
 		} else if (Randomizer.pickWithProb(0.50)){
38
-			rarity = Rarity.Uncommon
39
-			uncommonConsonants
42
+			Rarity.Youon
40 43
 		} else if (Randomizer.pickWithProb(0.50)){
41
-			rarity = Rarity.Youon
42
-			youonConsonants
43
-		} else if (Randomizer.pickWithProb(0.50)) {
44
-			rarity = Rarity.Epic
45
-			epicConsonants
44
+			Rarity.Epic
46 45
 		} else {
47
-			rarity = Rarity.EpicAlt
48
-			epicConsonantsAlt
46
+			Rarity.EpicAlt
47
+		}
48
+
49
+		val consonants = rarity match {
50
+			case Rarity.Common => commonConsonants
51
+			case Rarity.Uncommon => uncommonConsonants
52
+			case Rarity.Epic => epicConsonants
53
+			case Rarity.Youon => youonConsonants
54
+			case Rarity.EpicAlt => epicConsonantsAlt
49 55
 		}
50 56
 		val consonant = Randomizer.pickFrom(consonants)
51 57
 		val probOfYouon = if (consonant == j) 0.05 else 0.15
58
+		var generatedYouon = false
52 59
 		val vowel =
53
-		if (!youon && rarity != Rarity.Youon && Randomizer.pickWithProb(probOfYouon)){
54
-			generateSyllableF(youon = true).toString
60
+		if (!youonForce && !youonProhibit && rarity != Rarity.Youon && Randomizer.pickWithProb(probOfYouon)){
61
+			generatedYouon = true
62
+			generateSyllableF(youonForce = true, youonProhibit = false).toString
55 63
 		} else {
56 64
 			val vowels = rarity match {
57 65
 				case Rarity.Uncommon | Rarity.Common => forCommon
@@ -61,13 +69,13 @@ class SyllableGenerator (val useX: Boolean, val sInsteadOfsh: Boolean = false, v
61 69
 			}
62 70
 			Randomizer.pickFrom(vowels)
63 71
 		}
64
-		new Syllable(consonant,vowel)
72
+		new Syllable(consonant,vowel,generatedYouon)
65 73
 	}
66
-	def generateSyllableF:Syllable = generateSyllableF(youon = false)
74
+	def generateSyllableF:Syllable = generateSyllableF(youonForce = false, youonProhibit = false)
67 75
 
68 76
 	def generateSyllableV(includeN:Boolean):Syllable = {
69 77
 		val letters = if (includeN) forAll:+"n" else forAll
70
-		new Syllable("",Randomizer.pickFrom(letters))
78
+		new Syllable("",Randomizer.pickFrom(letters),false)
71 79
 	}
72 80
 
73 81
 }